mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 02:25:40 +01:00
rpc: add utxo's blockhash and number of confirmations to scantxoutset output
This commit is contained in:
parent
8754d055c6
commit
17845e7f21
@ -2190,7 +2190,7 @@ static RPCHelpMan scantxoutset()
|
|||||||
RPCResult{"when action=='start'; only returns after scan completes", RPCResult::Type::OBJ, "", "", {
|
RPCResult{"when action=='start'; only returns after scan completes", RPCResult::Type::OBJ, "", "", {
|
||||||
{RPCResult::Type::BOOL, "success", "Whether the scan was completed"},
|
{RPCResult::Type::BOOL, "success", "Whether the scan was completed"},
|
||||||
{RPCResult::Type::NUM, "txouts", "The number of unspent transaction outputs scanned"},
|
{RPCResult::Type::NUM, "txouts", "The number of unspent transaction outputs scanned"},
|
||||||
{RPCResult::Type::NUM, "height", "The current block height (index)"},
|
{RPCResult::Type::NUM, "height", "The block height at which the scan was done"},
|
||||||
{RPCResult::Type::STR_HEX, "bestblock", "The hash of the block at the tip of the chain"},
|
{RPCResult::Type::STR_HEX, "bestblock", "The hash of the block at the tip of the chain"},
|
||||||
{RPCResult::Type::ARR, "unspents", "",
|
{RPCResult::Type::ARR, "unspents", "",
|
||||||
{
|
{
|
||||||
@ -2203,6 +2203,8 @@ static RPCHelpMan scantxoutset()
|
|||||||
{RPCResult::Type::STR_AMOUNT, "amount", "The total amount in " + CURRENCY_UNIT + " of the unspent output"},
|
{RPCResult::Type::STR_AMOUNT, "amount", "The total amount in " + CURRENCY_UNIT + " of the unspent output"},
|
||||||
{RPCResult::Type::BOOL, "coinbase", "Whether this is a coinbase output"},
|
{RPCResult::Type::BOOL, "coinbase", "Whether this is a coinbase output"},
|
||||||
{RPCResult::Type::NUM, "height", "Height of the unspent transaction output"},
|
{RPCResult::Type::NUM, "height", "Height of the unspent transaction output"},
|
||||||
|
{RPCResult::Type::STR_HEX, "blockhash", "Blockhash of the unspent transaction output"},
|
||||||
|
{RPCResult::Type::NUM, "confirmations", "Number of confirmations of the unspent transaction output when the scan was done"},
|
||||||
}},
|
}},
|
||||||
}},
|
}},
|
||||||
{RPCResult::Type::STR_AMOUNT, "total_amount", "The total amount of all found unspent outputs in " + CURRENCY_UNIT},
|
{RPCResult::Type::STR_AMOUNT, "total_amount", "The total amount of all found unspent outputs in " + CURRENCY_UNIT},
|
||||||
@ -2292,17 +2294,20 @@ static RPCHelpMan scantxoutset()
|
|||||||
const COutPoint& outpoint = it.first;
|
const COutPoint& outpoint = it.first;
|
||||||
const Coin& coin = it.second;
|
const Coin& coin = it.second;
|
||||||
const CTxOut& txo = coin.out;
|
const CTxOut& txo = coin.out;
|
||||||
|
const CBlockIndex& coinb_block{*CHECK_NONFATAL(tip->GetAncestor(coin.nHeight))};
|
||||||
input_txos.push_back(txo);
|
input_txos.push_back(txo);
|
||||||
total_in += txo.nValue;
|
total_in += txo.nValue;
|
||||||
|
|
||||||
UniValue unspent(UniValue::VOBJ);
|
UniValue unspent(UniValue::VOBJ);
|
||||||
unspent.pushKV("txid", outpoint.hash.GetHex());
|
unspent.pushKV("txid", outpoint.hash.GetHex());
|
||||||
unspent.pushKV("vout", (int32_t)outpoint.n);
|
unspent.pushKV("vout", outpoint.n);
|
||||||
unspent.pushKV("scriptPubKey", HexStr(txo.scriptPubKey));
|
unspent.pushKV("scriptPubKey", HexStr(txo.scriptPubKey));
|
||||||
unspent.pushKV("desc", descriptors[txo.scriptPubKey]);
|
unspent.pushKV("desc", descriptors[txo.scriptPubKey]);
|
||||||
unspent.pushKV("amount", ValueFromAmount(txo.nValue));
|
unspent.pushKV("amount", ValueFromAmount(txo.nValue));
|
||||||
unspent.pushKV("coinbase", coin.IsCoinBase());
|
unspent.pushKV("coinbase", coin.IsCoinBase());
|
||||||
unspent.pushKV("height", (int32_t)coin.nHeight);
|
unspent.pushKV("height", coin.nHeight);
|
||||||
|
unspent.pushKV("blockhash", coinb_block.GetBlockHash().GetHex());
|
||||||
|
unspent.pushKV("confirmations", tip->nHeight - coin.nHeight + 1);
|
||||||
|
|
||||||
unspents.push_back(std::move(unspent));
|
unspents.push_back(std::move(unspent));
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,15 @@ class ScantxoutsetTest(BitcoinTestFramework):
|
|||||||
assert_equal(self.nodes[0].scantxoutset("status"), None)
|
assert_equal(self.nodes[0].scantxoutset("status"), None)
|
||||||
assert_equal(self.nodes[0].scantxoutset("abort"), False)
|
assert_equal(self.nodes[0].scantxoutset("abort"), False)
|
||||||
|
|
||||||
# check that first arg is needed
|
# Check that the blockhash and confirmations fields are correct
|
||||||
|
self.generate(self.nodes[0], 2)
|
||||||
|
unspent = self.nodes[0].scantxoutset("start", ["addr(mpQ8rokAhp1TAtJQR6F6TaUmjAWkAWYYBq)"])["unspents"][0]
|
||||||
|
blockhash = self.nodes[0].getblockhash(info["height"])
|
||||||
|
assert_equal(unspent["height"], info["height"])
|
||||||
|
assert_equal(unspent["blockhash"], blockhash)
|
||||||
|
assert_equal(unspent["confirmations"], 3)
|
||||||
|
|
||||||
|
# Check that first arg is needed
|
||||||
assert_raises_rpc_error(-1, "scantxoutset \"action\" ( [scanobjects,...] )", self.nodes[0].scantxoutset)
|
assert_raises_rpc_error(-1, "scantxoutset \"action\" ( [scanobjects,...] )", self.nodes[0].scantxoutset)
|
||||||
|
|
||||||
# Check that second arg is needed for start
|
# Check that second arg is needed for start
|
||||||
|
Loading…
Reference in New Issue
Block a user