Skip to content

Commit

Permalink
udb: Remove unnecessary DBVersion param.
Browse files Browse the repository at this point in the history
fetchSStxRecordSStxTicketHash160 implemented two different behaviours
based on the provided database version parameter, however all instances
of the param are hard-coded and only one of the behaviours is ever
invoked.
  • Loading branch information
jholdstock authored and jrick committed Sep 3, 2024
1 parent 08c05e9 commit aa0d0c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
6 changes: 3 additions & 3 deletions wallet/udb/stake.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015-2017 The Decred developers
// Copyright (c) 2015-2024 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -170,7 +170,7 @@ func (s *StakeStore) dumpSStxHashesForAddress(ns walletdb.ReadBucket, addr stdad

// Access the database and store the result locally.
for _, h := range allTickets {
thisHash160, p2sh, err := fetchSStxRecordSStxTicketHash160(ns, &h, DBVersion)
thisHash160, p2sh, err := fetchSStxRecordSStxTicketHash160(ns, &h)
if err != nil {
return nil, errors.E(errors.IO, err)
}
Expand Down Expand Up @@ -198,7 +198,7 @@ func (s *StakeStore) DumpSStxHashesForAddress(ns walletdb.ReadBucket, addr stdad
// sstxAddress returns the address for a given ticket.
func (s *StakeStore) sstxAddress(ns walletdb.ReadBucket, hash *chainhash.Hash) (stdaddr.Address, error) {
// Access the database and store the result locally.
thisHash160, p2sh, err := fetchSStxRecordSStxTicketHash160(ns, hash, DBVersion)
thisHash160, p2sh, err := fetchSStxRecordSStxTicketHash160(ns, hash)
if err != nil {
return nil, err
}
Expand Down
20 changes: 6 additions & 14 deletions wallet/udb/stakedb.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2015-2017 The Decred developers
// Copyright (c) 2015-2024 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand Down Expand Up @@ -166,17 +166,9 @@ func deserializeSStxRecord(serializedSStxRecord []byte, dbVersion uint32) (*sstx

// deserializeSStxTicketHash160 deserializes and returns a 20 byte script
// hash for a ticket's 0th output.
func deserializeSStxTicketHash160(serializedSStxRecord []byte, dbVersion uint32) (hash160 []byte, p2sh bool, err error) {
var pkscriptLocOffset int
var txOffset int
switch {
case dbVersion < 3:
pkscriptLocOffset = 8 // After transaction size
txOffset = 8 + 4 + 1 + stake.MaxSingleBytePushLength
case dbVersion >= 3:
pkscriptLocOffset = 0
txOffset = 4
}
func deserializeSStxTicketHash160(serializedSStxRecord []byte) (hash160 []byte, p2sh bool, err error) {
const pkscriptLocOffset = 0
const txOffset = 4

pkscriptLoc := int(binary.LittleEndian.Uint32(serializedSStxRecord[pkscriptLocOffset:])) + txOffset

Expand Down Expand Up @@ -315,7 +307,7 @@ func fetchSStxRecord(ns walletdb.ReadBucket, hash *chainhash.Hash, dbVersion uin

// fetchSStxRecordSStxTicketHash160 retrieves a ticket 0th output script or
// pubkeyhash from the sstx records bucket with the given hash.
func fetchSStxRecordSStxTicketHash160(ns walletdb.ReadBucket, hash *chainhash.Hash, dbVersion uint32) (hash160 []byte, p2sh bool, err error) {
func fetchSStxRecordSStxTicketHash160(ns walletdb.ReadBucket, hash *chainhash.Hash) (hash160 []byte, p2sh bool, err error) {
bucket := ns.NestedReadBucket(sstxRecordsBucketName)

key := hash[:]
Expand All @@ -324,7 +316,7 @@ func fetchSStxRecordSStxTicketHash160(ns walletdb.ReadBucket, hash *chainhash.Ha
return nil, false, errors.E(errors.NotExist, errors.Errorf("no ticket purchase %v", hash))
}

return deserializeSStxTicketHash160(val, dbVersion)
return deserializeSStxTicketHash160(val)
}

// putSStxRecord inserts a given SStx record to the SStxrecords bucket.
Expand Down

0 comments on commit aa0d0c8

Please sign in to comment.