Add block_height field in struct Confirmation

At wallet loading, we rely on chain state querying to retrieve
height of txn, to do so we ensure that lock order is respected
between cs_main and cs_wallet.

If wallet loaded is the wallet-tool one, all wallet txn will
show up with a height of zero. It doesn't matter as confirmation
height is not used by wallet-tool.

Reorder arguments and document Confirmation calls to avoid
ambiguity.

Fixes nits left from #16624
This commit is contained in:
Antoine Riard
2019-04-20 11:22:59 -04:00
parent 9700fcb47f
commit 5971d3848e
4 changed files with 43 additions and 26 deletions

View File

@@ -364,10 +364,12 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
std::vector<uint256> vMatch;
std::vector<unsigned int> vIndex;
unsigned int txnIndex = 0;
Optional<int> height;
if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) == merkleBlock.header.hashMerkleRoot) {
auto locked_chain = pwallet->chain().lock();
if (locked_chain->getBlockHeight(merkleBlock.header.GetHash()) == nullopt) {
height = locked_chain->getBlockHeight(merkleBlock.header.GetHash());
if (height == nullopt) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found in chain");
}
@@ -382,7 +384,7 @@ UniValue importprunedfunds(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Something wrong with merkleblock");
}
CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, merkleBlock.header.GetHash(), txnIndex);
CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, *height, merkleBlock.header.GetHash(), txnIndex);
wtx.m_confirm = confirm;
auto locked_chain = pwallet->chain().lock();