Return matched tx indices from NewMerkleBlock.
This commit modifies the NewMerkleBlock function to return the matched transaction indices instead of their hashes. This is being done because it is much easier for the caller to lookup the matched transactions from the original passed block based on their transaction index within the block versus their hashes.
This commit is contained in:
parent
f3db5cf7e5
commit
d39a255dbc
1 changed files with 6 additions and 6 deletions
|
@ -77,8 +77,8 @@ func (m *merkleBlock) traverseAndBuild(height, pos uint32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMerkleBlock returns a new *wire.MsgMerkleBlock and an array of the matched
|
// NewMerkleBlock returns a new *wire.MsgMerkleBlock and an array of the matched
|
||||||
// transaction hashes based on the passed block and filter.
|
// transaction index numbers based on the passed block and filter.
|
||||||
func NewMerkleBlock(block *btcutil.Block, filter *Filter) (*wire.MsgMerkleBlock, []*wire.ShaHash) {
|
func NewMerkleBlock(block *btcutil.Block, filter *Filter) (*wire.MsgMerkleBlock, []uint32) {
|
||||||
numTx := uint32(len(block.Transactions()))
|
numTx := uint32(len(block.Transactions()))
|
||||||
mBlock := merkleBlock{
|
mBlock := merkleBlock{
|
||||||
numTx: numTx,
|
numTx: numTx,
|
||||||
|
@ -87,11 +87,11 @@ func NewMerkleBlock(block *btcutil.Block, filter *Filter) (*wire.MsgMerkleBlock,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find and keep track of any transactions that match the filter.
|
// Find and keep track of any transactions that match the filter.
|
||||||
var matchedHashes []*wire.ShaHash
|
var matchedIndices []uint32
|
||||||
for _, tx := range block.Transactions() {
|
for txIndex, tx := range block.Transactions() {
|
||||||
if filter.MatchTxAndUpdate(tx) {
|
if filter.MatchTxAndUpdate(tx) {
|
||||||
mBlock.matchedBits = append(mBlock.matchedBits, 0x01)
|
mBlock.matchedBits = append(mBlock.matchedBits, 0x01)
|
||||||
matchedHashes = append(matchedHashes, tx.Sha())
|
matchedIndices = append(matchedIndices, uint32(txIndex))
|
||||||
} else {
|
} else {
|
||||||
mBlock.matchedBits = append(mBlock.matchedBits, 0x00)
|
mBlock.matchedBits = append(mBlock.matchedBits, 0x00)
|
||||||
}
|
}
|
||||||
|
@ -120,5 +120,5 @@ func NewMerkleBlock(block *btcutil.Block, filter *Filter) (*wire.MsgMerkleBlock,
|
||||||
for i := uint32(0); i < uint32(len(mBlock.bits)); i++ {
|
for i := uint32(0); i < uint32(len(mBlock.bits)); i++ {
|
||||||
msgMerkleBlock.Flags[i/8] |= mBlock.bits[i] << (i % 8)
|
msgMerkleBlock.Flags[i/8] |= mBlock.bits[i] << (i % 8)
|
||||||
}
|
}
|
||||||
return &msgMerkleBlock, matchedHashes
|
return &msgMerkleBlock, matchedIndices
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue