Skip to content

Commit 892de1d

Browse files
committed
scantxoutset: add support for scripts
1 parent 7830494 commit 892de1d

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/rpc/blockchain.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2032,6 +2032,7 @@ UniValue scantxoutset(const JSONRPCRequest& request)
20322032
"2. \"scanobjects\" (array, optional) Array of scan objects (only one object type per scan object allowed)\n"
20332033
" [\n"
20342034
" { \"address\" : \"<address>\" }, (string, optional) Bitcoin address\n"
2035+
" { \"script\" : \"<scriptPubKey>\" }, (string, optional) HEX encoded script (scriptPubKey)\n"
20352036
" { \"pubkey\" : (object, optional) Public key\n"
20362037
" {\n"
20372038
" \"pubkey\" : \"<pubkey\">, (string, required) HEX encoded public key\n"
@@ -2089,14 +2090,17 @@ UniValue scantxoutset(const JSONRPCRequest& request)
20892090
}
20902091
UniValue address_uni = find_value(scanobject, "address");
20912092
UniValue pubkey_uni = find_value(scanobject, "pubkey");
2093+
UniValue script_uni = find_value(scanobject, "script");
20922094

20932095
// make sure only one object type is present
2094-
if (1 != !address_uni.isNull() + !pubkey_uni.isNull()) {
2096+
if (1 != !address_uni.isNull() + !pubkey_uni.isNull() + !script_uni.isNull()) {
20952097
throw JSONRPCError(RPC_INVALID_PARAMETER, "Only one object type is allowed per scan object");
20962098
} else if (!address_uni.isNull() && !address_uni.isStr()) {
20972099
throw JSONRPCError(RPC_INVALID_PARAMETER, "Scanobject \"address\" must contain a single string as value");
20982100
} else if (!pubkey_uni.isNull() && !pubkey_uni.isObject()) {
20992101
throw JSONRPCError(RPC_INVALID_PARAMETER, "Scanobject \"pubkey\" must contain an object as value");
2102+
} else if (!script_uni.isNull() && !script_uni.isStr()) {
2103+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Scanobject \"script\" must contain a single string as value");
21002104
} else if (address_uni.isStr()) {
21012105
// type: address
21022106
// decode destination and derive the scriptPubKey
@@ -2117,8 +2121,7 @@ UniValue scantxoutset(const JSONRPCRequest& request)
21172121
// check the script types and use the default if not provided
21182122
if (!script_types_uni.isNull() && !script_types_uni.isArray()) {
21192123
throw JSONRPCError(RPC_INVALID_PARAMETER, "script_types must be an array");
2120-
}
2121-
else if (script_types_uni.isNull()) {
2124+
} else if (script_types_uni.isNull()) {
21222125
// use the default script types
21232126
script_types_uni = UniValue(UniValue::VARR);
21242127
for (const char *t : g_default_scantxoutset_script_types) {
@@ -2144,6 +2147,12 @@ UniValue scantxoutset(const JSONRPCRequest& request)
21442147
assert(!script.empty());
21452148
needles.insert(script);
21462149
}
2150+
} else if (script_uni.isStr()) {
2151+
// type: script
2152+
// check and add the script to the scan containers (needles array)
2153+
CScript script(ParseHexV(script_uni, "script"));
2154+
// TODO: check script: max length, has OP, is unspenable etc.
2155+
needles.insert(script);
21472156
}
21482157
}
21492158

0 commit comments

Comments
 (0)