mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 23:07:59 +01:00
Add matching descriptors to scantxoutset output + tests
This commit is contained in:
parent
16203d5df7
commit
b65326b562
2 changed files with 16 additions and 1 deletions
|
@ -2074,6 +2074,7 @@ UniValue scantxoutset(const JSONRPCRequest& request)
|
||||||
" \"txid\" : \"transactionid\", (string) The transaction id\n"
|
" \"txid\" : \"transactionid\", (string) The transaction id\n"
|
||||||
" \"vout\": n, (numeric) the vout value\n"
|
" \"vout\": n, (numeric) the vout value\n"
|
||||||
" \"scriptPubKey\" : \"script\", (string) the script key\n"
|
" \"scriptPubKey\" : \"script\", (string) the script key\n"
|
||||||
|
" \"desc\" : \"descriptor\", (string) A specialized descriptor for the matched scriptPubKey\n"
|
||||||
" \"amount\" : x.xxx, (numeric) The total amount in " + CURRENCY_UNIT + " of the unspent output\n"
|
" \"amount\" : x.xxx, (numeric) The total amount in " + CURRENCY_UNIT + " of the unspent output\n"
|
||||||
" \"height\" : n, (numeric) Height of the unspent transaction output\n"
|
" \"height\" : n, (numeric) Height of the unspent transaction output\n"
|
||||||
" }\n"
|
" }\n"
|
||||||
|
@ -2108,6 +2109,7 @@ UniValue scantxoutset(const JSONRPCRequest& request)
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Scan already in progress, use action \"abort\" or \"status\"");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Scan already in progress, use action \"abort\" or \"status\"");
|
||||||
}
|
}
|
||||||
std::set<CScript> needles;
|
std::set<CScript> needles;
|
||||||
|
std::map<CScript, std::string> descriptors;
|
||||||
CAmount total_in = 0;
|
CAmount total_in = 0;
|
||||||
|
|
||||||
// loop through the scan objects
|
// loop through the scan objects
|
||||||
|
@ -2140,7 +2142,11 @@ UniValue scantxoutset(const JSONRPCRequest& request)
|
||||||
if (!desc->Expand(i, provider, scripts, provider)) {
|
if (!desc->Expand(i, provider, scripts, provider)) {
|
||||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Cannot derive script without private keys: '%s'", desc_str));
|
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Cannot derive script without private keys: '%s'", desc_str));
|
||||||
}
|
}
|
||||||
needles.insert(scripts.begin(), scripts.end());
|
for (const auto& script : scripts) {
|
||||||
|
std::string inferred = InferDescriptor(script, provider)->ToString();
|
||||||
|
needles.emplace(script);
|
||||||
|
descriptors.emplace(std::move(script), std::move(inferred));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2173,6 +2179,7 @@ UniValue scantxoutset(const JSONRPCRequest& request)
|
||||||
unspent.pushKV("txid", outpoint.hash.GetHex());
|
unspent.pushKV("txid", outpoint.hash.GetHex());
|
||||||
unspent.pushKV("vout", (int32_t)outpoint.n);
|
unspent.pushKV("vout", (int32_t)outpoint.n);
|
||||||
unspent.pushKV("scriptPubKey", HexStr(txo.scriptPubKey.begin(), txo.scriptPubKey.end()));
|
unspent.pushKV("scriptPubKey", HexStr(txo.scriptPubKey.begin(), txo.scriptPubKey.end()));
|
||||||
|
unspent.pushKV("desc", descriptors[txo.scriptPubKey]);
|
||||||
unspent.pushKV("amount", ValueFromAmount(txo.nValue));
|
unspent.pushKV("amount", ValueFromAmount(txo.nValue));
|
||||||
unspent.pushKV("height", (int32_t)coin.nHeight);
|
unspent.pushKV("height", (int32_t)coin.nHeight);
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,9 @@ from decimal import Decimal
|
||||||
import shutil
|
import shutil
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
def descriptors(out):
|
||||||
|
return sorted(u['desc'] for u in out['unspents'])
|
||||||
|
|
||||||
class ScantxoutsetTest(BitcoinTestFramework):
|
class ScantxoutsetTest(BitcoinTestFramework):
|
||||||
def set_test_params(self):
|
def set_test_params(self):
|
||||||
self.num_nodes = 1
|
self.num_nodes = 1
|
||||||
|
@ -93,5 +96,10 @@ class ScantxoutsetTest(BitcoinTestFramework):
|
||||||
assert_equal(self.nodes[0].scantxoutset("start", [ {"desc": "combo(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/*)", "range": 1499}])['total_amount'], Decimal("12.288"))
|
assert_equal(self.nodes[0].scantxoutset("start", [ {"desc": "combo(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/*)", "range": 1499}])['total_amount'], Decimal("12.288"))
|
||||||
assert_equal(self.nodes[0].scantxoutset("start", [ {"desc": "combo(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/*)", "range": 1500}])['total_amount'], Decimal("28.672"))
|
assert_equal(self.nodes[0].scantxoutset("start", [ {"desc": "combo(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/*)", "range": 1500}])['total_amount'], Decimal("28.672"))
|
||||||
|
|
||||||
|
# Test the reported descriptors for a few matches
|
||||||
|
assert_equal(descriptors(self.nodes[0].scantxoutset("start", [ {"desc": "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/0h/0'/*)", "range": 1499}])), ["pkh([0c5f9a1e/0'/0'/0]026dbd8b2315f296d36e6b6920b1579ca75569464875c7ebe869b536a7d9503c8c)", "pkh([0c5f9a1e/0'/0'/1]033e6f25d76c00bedb3a8993c7d5739ee806397f0529b1b31dda31ef890f19a60c)"])
|
||||||
|
assert_equal(descriptors(self.nodes[0].scantxoutset("start", [ "combo(tprv8ZgxMBicQKsPd7Uf69XL1XwhmjHopUGep8GuEiJDZmbQz6o58LninorQAfcKZWARbtRtfnLcJ5MQ2AtHcQJCCRUcMRvmDUjyEmNUWwx8UbK/1/1/0)"])), ["pkh([0c5f9a1e/1/1/0]03e1c5b6e650966971d7e71ef2674f80222752740fc1dfd63bbbd220d2da9bd0fb)"])
|
||||||
|
assert_equal(descriptors(self.nodes[0].scantxoutset("start", [ {"desc": "combo(tpubD6NzVbkrYhZ4WaWSyoBvQwbpLkojyoTZPRsgXELWz3Popb3qkjcJyJUGLnL4qHHoQvao8ESaAstxYSnhyswJ76uZPStJRJCTKvosUCJZL5B/1/1/*)", "range": 1500}])), ['pkh([0c5f9a1e/1/1/0]03e1c5b6e650966971d7e71ef2674f80222752740fc1dfd63bbbd220d2da9bd0fb)', 'pkh([0c5f9a1e/1/1/1500]03832901c250025da2aebae2bfb38d5c703a57ab66ad477f9c578bfbcd78abca6f)', 'pkh([0c5f9a1e/1/1/1]030d820fc9e8211c4169be8530efbc632775d8286167afd178caaf1089b77daba7)'])
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
ScantxoutsetTest().main()
|
ScantxoutsetTest().main()
|
||||||
|
|
Loading…
Add table
Reference in a new issue