Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions database/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,16 @@ func BlocksRecentTxn(txn *Txn, count int) ([]Block, error) {
// after any legitimate key. This should leave our most recent block as the next
// item when doing reverse iteration
tmpPrefix := append([]byte(blockBlobIndexKeyPrefix), 0xff)
var blockKey []byte
var err error
var tmpBlock Block
for it.Seek(tmpPrefix); it.ValidForPrefix([]byte(blockBlobIndexKeyPrefix)); it.Next() {
item := it.Item()
blockKey, err := item.ValueCopy(nil)
blockKey, err = item.ValueCopy(nil)
if err != nil {
return ret, err
}
tmpBlock, err := blockByKey(txn, blockKey)
tmpBlock, err = blockByKey(txn, blockKey)
if err != nil {
return ret, err
}
Expand Down Expand Up @@ -282,18 +285,21 @@ func BlocksAfterSlotTxn(txn *Txn, slotNumber uint64) ([]Block, error) {
[]byte(blockBlobKeyPrefix),
blockBlobKeyUint64ToBytes(slotNumber),
)
var err error
var k []byte
var tmpBlock Block
for it.Seek(keyPrefix); it.ValidForPrefix([]byte(blockBlobKeyPrefix)); it.Next() {
// Skip the start slot
if it.ValidForPrefix(keyPrefix) {
continue
}
item := it.Item()
k := item.Key()
k = item.Key()
// Skip the metadata key
if strings.HasSuffix(string(k), blockBlobMetadataKeySuffix) {
continue
}
tmpBlock, err := blockByKey(txn, k)
tmpBlock, err = blockByKey(txn, k)
if err != nil {
return []Block{}, err
}
Expand Down
16 changes: 11 additions & 5 deletions database/immutable/immutable.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func (i *ImmutableDb) GetTip() (*ocommon.Point, error) {
if err != nil {
return nil, err
}
var tmpPoint ocommon.Point
for {
next, err := secondary.Next()
if err != nil {
Expand All @@ -205,7 +206,7 @@ func (i *ImmutableDb) GetTip() (*ocommon.Point, error) {
if next == nil {
break
}
tmpPoint := ocommon.NewPoint(
tmpPoint = ocommon.NewPoint(
next.BlockOrEbb,
next.HeaderHash[:],
)
Expand All @@ -215,6 +216,7 @@ func (i *ImmutableDb) GetTip() (*ocommon.Point, error) {
}

func (i *ImmutableDb) GetBlock(point ocommon.Point) (*Block, error) {
var err error
chunkNames, err := i.getChunkNamesFromPoint(point)
if err != nil {
return nil, err
Expand All @@ -223,8 +225,9 @@ func (i *ImmutableDb) GetBlock(point ocommon.Point) (*Block, error) {
if err != nil {
return nil, err
}
var tmpBlock *Block
for {
tmpBlock, err := chunk.Next()
tmpBlock, err = chunk.Next()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -290,10 +293,12 @@ type BlockIterator struct {
}

func (b *BlockIterator) Next() (*Block, error) {
var err error
var tmpChunk *chunk
if b.chunk == nil {
if b.chunkIdx == 0 && len(b.chunkNames) > 0 {
// Open initial chunk
tmpChunk, err := b.db.getChunk(b.chunkNames[b.chunkIdx])
tmpChunk, err = b.db.getChunk(b.chunkNames[b.chunkIdx])
if err != nil {
return nil, err
}
Expand All @@ -302,8 +307,9 @@ func (b *BlockIterator) Next() (*Block, error) {
return nil, nil
}
}
var tmpBlock *Block
for {
tmpBlock, err := b.chunk.Next()
tmpBlock, err = b.chunk.Next()
if err != nil {
return nil, err
}
Expand All @@ -317,7 +323,7 @@ func (b *BlockIterator) Next() (*Block, error) {
if b.chunkIdx >= len(b.chunkNames) {
return nil, nil
}
tmpChunk, err := b.db.getChunk(b.chunkNames[b.chunkIdx])
tmpChunk, err = b.db.getChunk(b.chunkNames[b.chunkIdx])
if err != nil {
return nil, err
}
Expand Down
18 changes: 12 additions & 6 deletions database/plugin/metadata/sqlite/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ func (d *MetadataStoreSqlite) GetPoolRegistrations(
return ret, result.Error
}
}
var addrKeyHash lcommon.AddrKeyHash
var tmpCert lcommon.PoolRegistrationCertificate
var tmpMargin cbor.Rat
var tmpRelay lcommon.PoolRelay
for _, cert := range certs {
tmpMargin := cbor.Rat{Rat: cert.Margin.Rat}
tmpCert := lcommon.PoolRegistrationCertificate{
tmpMargin = cbor.Rat{Rat: cert.Margin.Rat}
tmpCert = lcommon.PoolRegistrationCertificate{
CertType: lcommon.CertificateTypePoolRegistration,
Operator: lcommon.PoolKeyHash(
lcommon.NewBlake2b224(cert.PoolKeyHash),
Expand All @@ -61,13 +65,13 @@ func (d *MetadataStoreSqlite) GetPoolRegistrations(
// RewardAccount: lcommon.AddrKeyHash(lcommon.NewBlake2b256(cert.PoolOwners[0]))
}
for _, owner := range cert.Owners {
addrKeyHash := lcommon.AddrKeyHash(
addrKeyHash = lcommon.AddrKeyHash(
lcommon.NewBlake2b224(owner.KeyHash),
)
tmpCert.PoolOwners = append(tmpCert.PoolOwners, addrKeyHash)
}
for _, relay := range cert.Relays {
tmpRelay := lcommon.PoolRelay{}
tmpRelay = lcommon.PoolRelay{}
// Determine type
if relay.Port != 0 {
port := uint32(relay.Port) // #nosec G115
Expand Down Expand Up @@ -124,8 +128,9 @@ func (d *MetadataStoreSqlite) GetStakeRegistrations(
return ret, result.Error
}
}
var tmpCert lcommon.StakeRegistrationCertificate
for _, cert := range certs {
tmpCert := lcommon.StakeRegistrationCertificate{
tmpCert = lcommon.StakeRegistrationCertificate{
CertType: lcommon.CertificateTypeStakeRegistration,
StakeRegistration: lcommon.Credential{
// TODO: determine correct type
Expand Down Expand Up @@ -163,8 +168,9 @@ func (d *MetadataStoreSqlite) SetPoolRegistration(
models.PoolRegistrationOwner{KeyHash: owner[:]},
)
}
var tmpRelay models.PoolRegistrationRelay
for _, relay := range cert.Relays {
tmpRelay := models.PoolRegistrationRelay{
tmpRelay = models.PoolRegistrationRelay{
Ipv4: relay.Ipv4,
Ipv6: relay.Ipv6,
}
Expand Down
7 changes: 5 additions & 2 deletions database/types/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ func TestTypesScanValue(t *testing.T) {
expectedValue: "3/5",
},
}
var ok bool
var tmpScanner sql.Scanner
var tmpValuer driver.Valuer
for _, testDef := range testDefs {
tmpValuer, ok := testDef.origValue.(driver.Valuer)
tmpValuer, ok = testDef.origValue.(driver.Valuer)
if !ok {
t.Fatalf("test original value does not implement driver.Valuer")
}
Expand All @@ -60,7 +63,7 @@ func TestTypesScanValue(t *testing.T) {
testDef.expectedValue,
)
}
tmpScanner, ok := testDef.origValue.(sql.Scanner)
tmpScanner, ok = testDef.origValue.(sql.Scanner)
if !ok {
t.Fatalf(
"test original value does not implement sql.Scanner (it must be a pointer)",
Expand Down
3 changes: 2 additions & 1 deletion database/utxo.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ func (d *Database) UtxosByAddress(
if err != nil {
return ret, err
}
var tmpUtxo Utxo
for _, utxo := range utxos {
tmpUtxo := Utxo(utxo)
tmpUtxo = Utxo(utxo)
if err := tmpUtxo.loadCbor(txn); err != nil {
return ret, err
}
Expand Down
Loading