mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-24 18:23:26 -03:00
rpc: Improve gettxoutproof error when only header is available.
This commit is contained in:
parent
69fc867ea1
commit
6cbf2e5f81
2 changed files with 9 additions and 0 deletions
|
@ -10,6 +10,7 @@
|
|||
#include <merkleblock.h>
|
||||
#include <node/blockstorage.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <rpc/blockchain.h>
|
||||
#include <rpc/server.h>
|
||||
#include <rpc/server_util.h>
|
||||
#include <rpc/util.h>
|
||||
|
@ -96,6 +97,10 @@ static RPCHelpMan gettxoutproof()
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
LOCK(cs_main);
|
||||
CheckBlockDataAvailability(chainman.m_blockman, *pblockindex, /*check_for_undo=*/false);
|
||||
}
|
||||
CBlock block;
|
||||
if (!chainman.m_blockman.ReadBlockFromDisk(block, *pblockindex)) {
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
|
||||
|
|
|
@ -67,6 +67,10 @@ class MerkleBlockTest(BitcoinTestFramework):
|
|||
assert_equal(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid_spent], blockhash)), [txid_spent])
|
||||
# We can't get the proof if we specify a non-existent block
|
||||
assert_raises_rpc_error(-5, "Block not found", self.nodes[0].gettxoutproof, [txid_spent], "0000000000000000000000000000000000000000000000000000000000000000")
|
||||
# We can't get the proof if we only have the header of the specified block
|
||||
block = self.generateblock(self.nodes[0], output="raw(55)", transactions=[], submit=False)
|
||||
self.nodes[0].submitheader(block["hex"])
|
||||
assert_raises_rpc_error(-1, "Block not available (not fully downloaded)", self.nodes[0].gettxoutproof, [txid_spent], block['hash'])
|
||||
# We can get the proof if the transaction is unspent
|
||||
assert_equal(self.nodes[0].verifytxoutproof(self.nodes[0].gettxoutproof([txid_unspent])), [txid_unspent])
|
||||
# We can get the proof if we provide a list of transactions and one of them is unspent. The ordering of the list should not matter.
|
||||
|
|
Loading…
Add table
Reference in a new issue