1
1
mirror of https://github.com/bitcoin/bitcoin.git synced 2024-05-17 23:56:39 +00:00

rpc: Style fixups in gettxoutproof

This commit is contained in:
MarcoFalke 2020-07-26 09:30:01 +02:00
parent 40a04814d1
commit fa1f7f28cb
No known key found for this signature in database
GPG Key ID: CE2B75697E69A548

View File

@ -245,10 +245,11 @@ static UniValue gettxoutproof(const JSONRPCRequest& request)
for (unsigned int idx = 0; idx < txids.size(); idx++) { for (unsigned int idx = 0; idx < txids.size(); idx++) {
const UniValue& txid = txids[idx]; const UniValue& txid = txids[idx];
uint256 hash(ParseHashV(txid, "txid")); uint256 hash(ParseHashV(txid, "txid"));
if (setTxids.count(hash)) if (setTxids.count(hash)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated txid: ")+txid.get_str()); throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated txid: ") + txid.get_str());
setTxids.insert(hash); }
oneTxid = hash; setTxids.insert(hash);
oneTxid = hash;
} }
CBlockIndex* pblockindex = nullptr; CBlockIndex* pblockindex = nullptr;
@ -281,8 +282,7 @@ static UniValue gettxoutproof(const JSONRPCRequest& request)
LOCK(cs_main); LOCK(cs_main);
if (pblockindex == nullptr) if (pblockindex == nullptr) {
{
CTransactionRef tx; CTransactionRef tx;
if (!GetTransaction(oneTxid, tx, Params().GetConsensus(), hashBlock) || hashBlock.IsNull()) if (!GetTransaction(oneTxid, tx, Params().GetConsensus(), hashBlock) || hashBlock.IsNull())
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not yet in block"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not yet in block");
@ -293,15 +293,19 @@ static UniValue gettxoutproof(const JSONRPCRequest& request)
} }
CBlock block; CBlock block;
if(!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus())) if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus())) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
}
unsigned int ntxFound = 0; unsigned int ntxFound = 0;
for (const auto& tx : block.vtx) for (const auto& tx : block.vtx) {
if (setTxids.count(tx->GetHash())) if (setTxids.count(tx->GetHash())) {
ntxFound++; ntxFound++;
if (ntxFound != setTxids.size()) }
}
if (ntxFound != setTxids.size()) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Not all transactions found in specified or retrieved block"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Not all transactions found in specified or retrieved block");
}
CDataStream ssMB(SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS); CDataStream ssMB(SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS);
CMerkleBlock mb(block, setTxids); CMerkleBlock mb(block, setTxids);