diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -417,35 +417,32 @@ // valid block std::vector vMatch; std::vector vIndex; - size_t txnIndex = 0; - Optional height; - if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) == + if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) != merkleBlock.header.hashMerkleRoot) { - auto locked_chain = pwallet->chain().lock(); - height = locked_chain->getBlockHeight(merkleBlock.header.GetHash()); - if (height == nullopt) { - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, - "Block not found in chain"); - } + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, + "Something wrong with merkleblock"); + } - std::vector::const_iterator it; - if ((it = std::find(vMatch.begin(), vMatch.end(), txid)) == - vMatch.end()) { - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, - "Transaction given doesn't exist in proof"); - } + auto locked_chain = pwallet->chain().lock(); + Optional height = + locked_chain->getBlockHeight(merkleBlock.header.GetHash()); + if (height == nullopt) { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, + "Block not found in chain"); + } - txnIndex = vIndex[it - vMatch.begin()]; - } else { + std::vector::const_iterator it; + if ((it = std::find(vMatch.begin(), vMatch.end(), txid)) == vMatch.end()) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, - "Something wrong with merkleblock"); + "Transaction given doesn't exist in proof"); } + size_t txnIndex = vIndex[it - vMatch.begin()]; + CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, *height, merkleBlock.header.GetHash(), txnIndex); wtx.m_confirm = confirm; - auto locked_chain = pwallet->chain().lock(); LOCK(pwallet->cs_wallet); if (pwallet->IsMine(*wtx.tx)) {