wallet: use GetBlockHeaderVerbose to retrieve block heights in GetTransactions
There's no need to retrieve the full block as we're only interesting in retrieve its corresponding height, which can be done with GetBlockHeaderVerbose.
This commit is contained in:
parent
b07494fc2d
commit
ce888ed941
1 changed files with 20 additions and 18 deletions
|
@ -20,7 +20,6 @@ import (
|
|||
"github.com/btcsuite/btcd/btcjson"
|
||||
"github.com/btcsuite/btcd/chaincfg"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/rpcclient"
|
||||
"github.com/btcsuite/btcd/txscript"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/btcsuite/btcutil"
|
||||
|
@ -2202,7 +2201,6 @@ func (w *Wallet) GetTransactions(startBlock, endBlock *BlockIdentifier, cancel <
|
|||
// TODO: Fetching block heights by their hashes is inherently racy
|
||||
// because not all block headers are saved but when they are for SPV the
|
||||
// db can be queried directly without this.
|
||||
var startResp, endResp rpcclient.FutureGetBlockVerboseResult
|
||||
if startBlock != nil {
|
||||
if startBlock.hash == nil {
|
||||
start = startBlock.height
|
||||
|
@ -2212,7 +2210,13 @@ func (w *Wallet) GetTransactions(startBlock, endBlock *BlockIdentifier, cancel <
|
|||
}
|
||||
switch client := chainClient.(type) {
|
||||
case *chain.RPCClient:
|
||||
startResp = client.GetBlockVerboseTxAsync(startBlock.hash)
|
||||
startHeader, err := client.GetBlockHeaderVerbose(
|
||||
startBlock.hash,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
start = startHeader.Height
|
||||
case *chain.BitcoindClient:
|
||||
var err error
|
||||
start, err = client.GetBlockHeight(startBlock.hash)
|
||||
|
@ -2237,7 +2241,19 @@ func (w *Wallet) GetTransactions(startBlock, endBlock *BlockIdentifier, cancel <
|
|||
}
|
||||
switch client := chainClient.(type) {
|
||||
case *chain.RPCClient:
|
||||
endResp = client.GetBlockVerboseTxAsync(endBlock.hash)
|
||||
endHeader, err := client.GetBlockHeaderVerbose(
|
||||
endBlock.hash,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
end = endHeader.Height
|
||||
case *chain.BitcoindClient:
|
||||
var err error
|
||||
start, err = client.GetBlockHeight(endBlock.hash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case *chain.NeutrinoClient:
|
||||
var err error
|
||||
end, err = client.GetBlockHeight(endBlock.hash)
|
||||
|
@ -2247,20 +2263,6 @@ func (w *Wallet) GetTransactions(startBlock, endBlock *BlockIdentifier, cancel <
|
|||
}
|
||||
}
|
||||
}
|
||||
if startResp != nil {
|
||||
resp, err := startResp.Receive()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
start = int32(resp.Height)
|
||||
}
|
||||
if endResp != nil {
|
||||
resp, err := endResp.Receive()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
end = int32(resp.Height)
|
||||
}
|
||||
|
||||
var res GetTransactionsResult
|
||||
err := walletdb.View(w.db, func(dbtx walletdb.ReadTx) error {
|
||||
|
|
Loading…
Reference in a new issue