Skip to content

Commit 2b5501e

Browse files
authored
fix(database): preserve uint64 values in sqlite (#1017)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 544d883 commit 2b5501e

File tree

14 files changed

+100
-58
lines changed

14 files changed

+100
-58
lines changed

database/account.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package database
1616

1717
import (
1818
"github.com/blinklabs-io/dingo/database/models"
19+
"github.com/blinklabs-io/dingo/database/types"
1920
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
2021
)
2122

@@ -54,13 +55,14 @@ func (d *Database) SetDeregistration(
5455
// SetRegistration saves a registration certificate
5556
func (d *Database) SetRegistration(
5657
cert *lcommon.RegistrationCertificate,
57-
slot, deposit uint64,
58+
slot uint64,
59+
deposit uint64,
5860
txn *Txn,
5961
) error {
6062
return d.metadata.SetRegistration(
6163
cert,
6264
slot,
63-
deposit,
65+
types.Uint64(deposit),
6466
txn.Metadata(),
6567
)
6668
}
@@ -94,27 +96,29 @@ func (d *Database) SetStakeDeregistration(
9496
// SetStakeRegistration saves a stake registration certificate
9597
func (d *Database) SetStakeRegistration(
9698
cert *lcommon.StakeRegistrationCertificate,
97-
slot, deposit uint64,
99+
slot uint64,
100+
deposit uint64,
98101
txn *Txn,
99102
) error {
100103
return d.metadata.SetStakeRegistration(
101104
cert,
102105
slot,
103-
deposit,
106+
types.Uint64(deposit),
104107
txn.Metadata(),
105108
)
106109
}
107110

108111
// SetStakeRegistrationDelegation saves a stake registration delegation certificate
109112
func (d *Database) SetStakeRegistrationDelegation(
110113
cert *lcommon.StakeRegistrationDelegationCertificate,
111-
slot, deposit uint64,
114+
slot uint64,
115+
deposit uint64,
112116
txn *Txn,
113117
) error {
114118
return d.metadata.SetStakeRegistrationDelegation(
115119
cert,
116120
slot,
117-
deposit,
121+
types.Uint64(deposit),
118122
txn.Metadata(),
119123
)
120124
}
@@ -135,13 +139,14 @@ func (d *Database) SetStakeVoteDelegation(
135139
// SetStakeVoteRegistrationDelegation saves a stake vote registration delegation certificate
136140
func (d *Database) SetStakeVoteRegistrationDelegation(
137141
cert *lcommon.StakeVoteRegistrationDelegationCertificate,
138-
slot, deposit uint64,
142+
slot uint64,
143+
deposit uint64,
139144
txn *Txn,
140145
) error {
141146
return d.metadata.SetStakeVoteRegistrationDelegation(
142147
cert,
143148
slot,
144-
deposit,
149+
types.Uint64(deposit),
145150
txn.Metadata(),
146151
)
147152
}
@@ -162,13 +167,14 @@ func (d *Database) SetVoteDelegation(
162167
// SetVoteRegistrationDelegation saves a vote registration delegation certificate
163168
func (d *Database) SetVoteRegistrationDelegation(
164169
cert *lcommon.VoteRegistrationDelegationCertificate,
165-
slot, deposit uint64,
170+
slot uint64,
171+
deposit uint64,
166172
txn *Txn,
167173
) error {
168174
return d.metadata.SetVoteRegistrationDelegation(
169175
cert,
170176
slot,
171-
deposit,
177+
types.Uint64(deposit),
172178
txn.Metadata(),
173179
)
174180
}

database/certs.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package database
1616

1717
import (
18+
"github.com/blinklabs-io/dingo/database/types"
1819
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
1920
)
2021

@@ -37,10 +38,11 @@ func (d *Database) GetStakeRegistrations(
3738
// SetPoolRegistration saves a pool registration certificate
3839
func (d *Database) SetPoolRegistration(
3940
cert *lcommon.PoolRegistrationCertificate,
40-
slot, deposit uint64, // slot
41+
slot uint64,
42+
deposit uint64,
4143
txn *Txn,
4244
) error {
43-
return d.metadata.SetPoolRegistration(cert, slot, deposit, txn.Metadata())
45+
return d.metadata.SetPoolRegistration(cert, slot, types.Uint64(deposit), txn.Metadata())
4446
}
4547

4648
// SetPoolRetirement saves a pool retirement certificate

database/drep.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,36 @@
1515
package database
1616

1717
import (
18+
"github.com/blinklabs-io/dingo/database/types"
1819
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
1920
)
2021

2122
// SetRegistrationDrep saves a registration drep certificate
2223
func (d *Database) SetRegistrationDrep(
2324
cert *lcommon.RegistrationDrepCertificate,
24-
slot, deposit uint64,
25+
slot uint64,
26+
deposit uint64,
2527
txn *Txn,
2628
) error {
2729
return d.metadata.SetRegistrationDrep(
2830
cert,
2931
slot,
30-
deposit,
32+
types.Uint64(deposit),
3133
txn.Metadata(),
3234
)
3335
}
3436

3537
// SetDeregistrationDrep saves a deregistration drep certificate
3638
func (d *Database) SetDeregistrationDrep(
3739
cert *lcommon.DeregistrationDrepCertificate,
38-
slot, deposit uint64,
40+
slot uint64,
41+
deposit uint64,
3942
txn *Txn,
4043
) error {
4144
return d.metadata.SetDeregistrationDrep(
4245
cert,
4346
slot,
44-
deposit,
47+
types.Uint64(deposit),
4548
txn.Metadata(),
4649
)
4750
}

database/models/account.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"errors"
1919
"fmt"
2020

21+
"github.com/blinklabs-io/dingo/database/types"
2122
"github.com/btcsuite/btcd/btcutil/bech32"
2223
)
2324

@@ -61,7 +62,7 @@ type Deregistration struct {
6162
ID uint `gorm:"primarykey"`
6263
CertificateID uint `gorm:"index"`
6364
AddedSlot uint64
64-
Amount int64
65+
Amount types.Uint64
6566
}
6667

6768
func (Deregistration) TableName() string {
@@ -73,7 +74,7 @@ type Registration struct {
7374
ID uint `gorm:"primarykey"`
7475
CertificateID uint `gorm:"index"`
7576
AddedSlot uint64
76-
DepositAmount uint64
77+
DepositAmount types.Uint64
7778
}
7879

7980
func (Registration) TableName() string {
@@ -108,7 +109,7 @@ type StakeRegistration struct {
108109
CertificateID uint `gorm:"index"`
109110
ID uint `gorm:"primarykey"`
110111
AddedSlot uint64
111-
DepositAmount uint64
112+
DepositAmount types.Uint64
112113
}
113114

114115
func (StakeRegistration) TableName() string {
@@ -121,7 +122,7 @@ type StakeRegistrationDelegation struct {
121122
CertificateID uint `gorm:"index"`
122123
ID uint `gorm:"primarykey"`
123124
AddedSlot uint64
124-
DepositAmount uint64
125+
DepositAmount types.Uint64
125126
}
126127

127128
func (StakeRegistrationDelegation) TableName() string {
@@ -148,7 +149,7 @@ type StakeVoteRegistrationDelegation struct {
148149
CertificateID uint `gorm:"index"`
149150
ID uint `gorm:"primarykey"`
150151
AddedSlot uint64
151-
DepositAmount uint64
152+
DepositAmount types.Uint64
152153
}
153154

154155
func (StakeVoteRegistrationDelegation) TableName() string {
@@ -173,7 +174,7 @@ type VoteRegistrationDelegation struct {
173174
CertificateID uint `gorm:"index"`
174175
ID uint `gorm:"primarykey"`
175176
AddedSlot uint64
176-
DepositAmount uint64
177+
DepositAmount types.Uint64
177178
}
178179

179180
func (VoteRegistrationDelegation) TableName() string {

database/models/certs.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414

1515
package models
1616

17+
import "github.com/blinklabs-io/dingo/database/types"
18+
1719
type Certificate struct {
1820
Cbor []byte `gorm:"-"`
1921
Pool []byte
2022
Credential []byte
2123
Drep []byte
2224
CertType uint `gorm:"index"`
2325
Epoch uint64
24-
Amount uint64
26+
Amount types.Uint64
2527
ID uint `gorm:"primaryKey"`
2628
}
2729

database/models/drep.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package models
1616

17+
import "github.com/blinklabs-io/dingo/database/types"
18+
1719
type Drep struct {
1820
AnchorUrl string
1921
Credential []byte `gorm:"uniqueIndex"`
@@ -33,7 +35,7 @@ type DeregistrationDrep struct {
3335
CertificateID uint `gorm:"index"`
3436
ID uint `gorm:"primarykey"`
3537
AddedSlot uint64
36-
DepositAmount uint64
38+
DepositAmount types.Uint64
3739
}
3840

3941
func (DeregistrationDrep) TableName() string {
@@ -47,7 +49,7 @@ type RegistrationDrep struct {
4749
CertificateID uint `gorm:"index"`
4850
ID uint `gorm:"primarykey"`
4951
AddedSlot uint64
50-
DepositAmount uint64
52+
DepositAmount types.Uint64
5153
}
5254

5355
func (RegistrationDrep) TableName() string {

database/models/pool.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type PoolRegistration struct {
5656
ID uint `gorm:"primarykey"`
5757
PoolID uint `gorm:"index"`
5858
AddedSlot uint64
59-
DepositAmount uint64
59+
DepositAmount types.Uint64
6060
}
6161

6262
func (PoolRegistration) TableName() string {

database/models/transaction.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package models
1616

17+
import "github.com/blinklabs-io/dingo/database/types"
18+
1719
// Transaction represents a transaction record
1820
type Transaction struct {
1921
Hash []byte `gorm:"uniqueIndex"`
@@ -27,8 +29,8 @@ type Transaction struct {
2729
Type int
2830
BlockIndex uint32
2931
Metadata []byte
30-
Fee uint64
31-
TTL uint64
32+
Fee types.Uint64
33+
TTL types.Uint64
3234
}
3335

3436
func (Transaction) TableName() string {

database/models/utxo.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package models
1616

1717
import (
18+
"github.com/blinklabs-io/dingo/database/types"
1819
"github.com/blinklabs-io/gouroboros/ledger"
1920
lcommon "github.com/blinklabs-io/gouroboros/ledger/common"
2021
)
@@ -26,15 +27,15 @@ type Utxo struct {
2627
PaymentKey []byte `gorm:"index"`
2728
StakingKey []byte `gorm:"index"`
2829
Assets []Asset
29-
Cbor []byte `gorm:"-"` // This is here for convenience but not represented in the metadata DB
30-
SpentAtTxId []byte `gorm:"index"`
31-
ReferencedByTxId []byte `gorm:"index"`
32-
CollateralByTxId []byte `gorm:"index"`
33-
ID uint `gorm:"primarykey"`
34-
AddedSlot uint64 `gorm:"index"`
35-
DeletedSlot uint64 `gorm:"index"`
36-
Amount uint64 `gorm:"index"`
37-
OutputIdx uint32 `gorm:"uniqueIndex:tx_id_output_idx"`
30+
Cbor []byte `gorm:"-"` // This is here for convenience but not represented in the metadata DB
31+
SpentAtTxId []byte `gorm:"index"`
32+
ReferencedByTxId []byte `gorm:"index"`
33+
CollateralByTxId []byte `gorm:"index"`
34+
ID uint `gorm:"primarykey"`
35+
AddedSlot uint64 `gorm:"index"`
36+
DeletedSlot uint64 `gorm:"index"`
37+
Amount types.Uint64 `gorm:"index"`
38+
OutputIdx uint32 `gorm:"uniqueIndex:tx_id_output_idx"`
3839
}
3940

4041
func (u *Utxo) TableName() string {
@@ -54,7 +55,7 @@ func UtxoLedgerToModel(
5455
TxId: utxo.Id.Id().Bytes(),
5556
Cbor: utxo.Output.Cbor(),
5657
AddedSlot: slot,
57-
Amount: utxo.Output.Amount(),
58+
Amount: types.Uint64(utxo.Output.Amount()),
5859
OutputIdx: utxo.Id.Index(),
5960
}
6061
pkh := outAddr.PaymentKeyHash()

0 commit comments

Comments
 (0)