Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/rpcdump.cpp
Show First 20 Lines • Show All 411 Lines • ▼ Show 20 Lines | CDataStream ssMB(ParseHexV(request.params[1], "proof"), SER_NETWORK, | ||||
PROTOCOL_VERSION); | PROTOCOL_VERSION); | ||||
CMerkleBlock merkleBlock; | CMerkleBlock merkleBlock; | ||||
ssMB >> merkleBlock; | ssMB >> merkleBlock; | ||||
// Search partial merkle tree in proof for our transaction and index in | // Search partial merkle tree in proof for our transaction and index in | ||||
// valid block | // valid block | ||||
std::vector<uint256> vMatch; | std::vector<uint256> vMatch; | ||||
std::vector<size_t> vIndex; | std::vector<size_t> vIndex; | ||||
size_t txnIndex = 0; | if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) != | ||||
Optional<int> height; | |||||
if (merkleBlock.txn.ExtractMatches(vMatch, vIndex) == | |||||
merkleBlock.header.hashMerkleRoot) { | merkleBlock.header.hashMerkleRoot) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | |||||
"Something wrong with merkleblock"); | |||||
} | |||||
auto locked_chain = pwallet->chain().lock(); | auto locked_chain = pwallet->chain().lock(); | ||||
height = locked_chain->getBlockHeight(merkleBlock.header.GetHash()); | Optional<int> height = | ||||
locked_chain->getBlockHeight(merkleBlock.header.GetHash()); | |||||
if (height == nullopt) { | if (height == nullopt) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Block not found in chain"); | "Block not found in chain"); | ||||
} | } | ||||
std::vector<uint256>::const_iterator it; | std::vector<uint256>::const_iterator it; | ||||
if ((it = std::find(vMatch.begin(), vMatch.end(), txid)) == | if ((it = std::find(vMatch.begin(), vMatch.end(), txid)) == vMatch.end()) { | ||||
vMatch.end()) { | |||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | ||||
"Transaction given doesn't exist in proof"); | "Transaction given doesn't exist in proof"); | ||||
} | } | ||||
txnIndex = vIndex[it - vMatch.begin()]; | size_t txnIndex = vIndex[it - vMatch.begin()]; | ||||
} else { | |||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, | |||||
"Something wrong with merkleblock"); | |||||
} | |||||
CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, *height, | CWalletTx::Confirmation confirm(CWalletTx::Status::CONFIRMED, *height, | ||||
merkleBlock.header.GetHash(), txnIndex); | merkleBlock.header.GetHash(), txnIndex); | ||||
wtx.m_confirm = confirm; | wtx.m_confirm = confirm; | ||||
auto locked_chain = pwallet->chain().lock(); | |||||
LOCK(pwallet->cs_wallet); | LOCK(pwallet->cs_wallet); | ||||
if (pwallet->IsMine(*wtx.tx)) { | if (pwallet->IsMine(*wtx.tx)) { | ||||
pwallet->AddToWallet(wtx, false); | pwallet->AddToWallet(wtx, false); | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
throw JSONRPCError( | throw JSONRPCError( | ||||
▲ Show 20 Lines • Show All 1,380 Lines • Show Last 20 Lines |