add cached version of HasWitness
This commit is contained in:
parent
9c01665307
commit
501929d3d0
1 changed files with 15 additions and 0 deletions
15
tx.go
15
tx.go
|
@ -25,6 +25,7 @@ type Tx struct {
|
||||||
msgTx *wire.MsgTx // Underlying MsgTx
|
msgTx *wire.MsgTx // Underlying MsgTx
|
||||||
txHash *chainhash.Hash // Cached transaction hash
|
txHash *chainhash.Hash // Cached transaction hash
|
||||||
txHashWitness *chainhash.Hash // Cached transaction witness hash
|
txHashWitness *chainhash.Hash // Cached transaction witness hash
|
||||||
|
txHasWitness *bool // If the transaction has witness data
|
||||||
txIndex int // Position within a block or TxIndexUnknown
|
txIndex int // Position within a block or TxIndexUnknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,6 +65,20 @@ func (t *Tx) WitnessHash() *chainhash.Hash {
|
||||||
return &hash
|
return &hash
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HasWitness returns false if none of the inputs within the transaction
|
||||||
|
// contain witness data, true false otherwise. This equivalent to calling
|
||||||
|
// HasWitness on the underlying wire.MsgTx, however it caches the result so
|
||||||
|
// subsequent calls are more efficient.
|
||||||
|
func (t *Tx) HasWitness() bool {
|
||||||
|
if t.txHashWitness != nil {
|
||||||
|
return *t.txHasWitness
|
||||||
|
}
|
||||||
|
|
||||||
|
hasWitness := t.msgTx.HasWitness()
|
||||||
|
t.txHasWitness = &hasWitness
|
||||||
|
return hasWitness
|
||||||
|
}
|
||||||
|
|
||||||
// Index returns the saved index of the transaction within a block. This value
|
// Index returns the saved index of the transaction within a block. This value
|
||||||
// will be TxIndexUnknown if it hasn't already explicitly been set.
|
// will be TxIndexUnknown if it hasn't already explicitly been set.
|
||||||
func (t *Tx) Index() int {
|
func (t *Tx) Index() int {
|
||||||
|
|
Loading…
Reference in a new issue