Skip to content

Commit 3d22371

Browse files
committed
Merge bitcoin/bitcoin#16795: rpc: have raw transaction decoding infer output descriptors
6498ba1 transaction decoding infer output descriptors (Gregory Sanders) Pull request description: Following discussion in #16725 this is complementary data to expose. All outputs are inferred. ACKs for top commit: achow101: ACK 6498ba1 meshcollider: utACK 6498ba1 Tree-SHA512: 36664117ddbe46d5fdde7ed6541ef2c9d8dfb7a3636b97f363bf1c325096fe00d9d2acea2d1917ea19fdb82f1ea296c12e440c5c703d6a9bfc1a02fba028bcd8
2 parents e3699b7 + 6498ba1 commit 3d22371

27 files changed

+46
-0
lines changed

doc/REST-interface.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ $ curl localhost:18332/rest/getutxos/checkmempool/b2cdfd7b89def827ff8af7cd9bff76
108108
"value" : 8.8687,
109109
"scriptPubKey" : {
110110
"asm" : "OP_DUP OP_HASH160 1c7cebb529b86a04c683dfa87be49de35bcf589e OP_EQUALVERIFY OP_CHECKSIG",
111+
"desc" : "addr(mi7as51dvLJsizWnTMurtRmrP8hG2m1XvD)#gj9tznmy"
111112
"hex" : "76a9141c7cebb529b86a04c683dfa87be49de35bcf589e88ac",
112113
"type" : "pubkeyhash",
113114
"address" : "mi7as51dvLJsizWnTMurtRmrP8hG2m1XvD"

src/core_write.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <consensus/consensus.h>
99
#include <consensus/validation.h>
1010
#include <key_io.h>
11+
#include <script/descriptor.h>
1112
#include <script/script.h>
1213
#include <script/standard.h>
1314
#include <serialize.h>
@@ -152,6 +153,7 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool include
152153
CTxDestination address;
153154

154155
out.pushKV("asm", ScriptToAsmStr(scriptPubKey));
156+
out.pushKV("desc", InferDescriptor(scriptPubKey, DUMMY_SIGNING_PROVIDER)->ToString());
155157
if (include_hex) out.pushKV("hex", HexStr(scriptPubKey));
156158

157159
std::vector<std::vector<unsigned char>> solns;

src/rpc/blockchain.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,7 @@ static RPCHelpMan gettxout()
13311331
{RPCResult::Type::STR_AMOUNT, "value", "The transaction value in " + CURRENCY_UNIT},
13321332
{RPCResult::Type::OBJ, "scriptPubKey", "", {
13331333
{RPCResult::Type::STR, "asm", ""},
1334+
{RPCResult::Type::STR, "desc", "Inferred descriptor for the output"},
13341335
{RPCResult::Type::STR_HEX, "hex", ""},
13351336
{RPCResult::Type::STR, "type", "The type, eg pubkeyhash"},
13361337
{RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"},

src/rpc/rawtransaction.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ static RPCHelpMan getrawtransaction()
179179
{RPCResult::Type::OBJ, "scriptPubKey", "",
180180
{
181181
{RPCResult::Type::STR, "asm", "the asm"},
182+
{RPCResult::Type::STR, "desc", "Inferred descriptor for the output"},
182183
{RPCResult::Type::STR, "hex", "the hex"},
183184
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
184185
{RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"},
@@ -506,6 +507,7 @@ static RPCHelpMan decoderawtransaction()
506507
{RPCResult::Type::OBJ, "scriptPubKey", "",
507508
{
508509
{RPCResult::Type::STR, "asm", "the asm"},
510+
{RPCResult::Type::STR, "desc", "Inferred descriptor for the output"},
509511
{RPCResult::Type::STR_HEX, "hex", "the hex"},
510512
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
511513
{RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"},
@@ -561,6 +563,7 @@ static RPCHelpMan decodescript()
561563
RPCResult::Type::OBJ, "", "",
562564
{
563565
{RPCResult::Type::STR, "asm", "Script public key"},
566+
{RPCResult::Type::STR, "desc", "Inferred descriptor for the script"},
564567
{RPCResult::Type::STR, "type", "The output type (e.g. " + GetAllOutputTypes() + ")"},
565568
{RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"},
566569
{RPCResult::Type::STR, "p2sh", /*optional=*/true,
@@ -572,6 +575,7 @@ static RPCHelpMan decodescript()
572575
{RPCResult::Type::STR_HEX, "hex", "Hex string of the script public key"},
573576
{RPCResult::Type::STR, "type", "The type of the script public key (e.g. witness_v0_keyhash or witness_v0_scripthash)"},
574577
{RPCResult::Type::STR, "address", /*optional=*/true, "The Bitcoin address (only if a well-defined address exists)"},
578+
{RPCResult::Type::STR, "desc", "Inferred descriptor for the script"},
575579
{RPCResult::Type::STR, "p2sh-segwit", "address of the P2SH script wrapping this witness redeem script"},
576580
}},
577581
},

test/functional/data/rpc_decodescript.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{
55
"asm": "1 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
66
"address": "bcrt1pamhwamhwamhwamhwamhwamhwamhwamhwamhwamhwamhwamhwamhqz6nvlh",
7+
"desc": "addr(bcrt1pamhwamhwamhwamhwamhwamhwamhwamhwamhwamhwamhwamhwamhqz6nvlh)#v52jnujz",
78
"type": "witness_v1_taproot"
89
}
910
],
@@ -12,6 +13,7 @@
1213
{
1314
"asm": "1 -28398",
1415
"address": "bcrt1pamhqk96edn",
16+
"desc": "addr(bcrt1pamhqk96edn)#vkh8uj5a",
1517
"type": "witness_unknown"
1618
}
1719
],
@@ -20,6 +22,7 @@
2022
{
2123
"asm": "0 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
2224
"address": "bcrt1qamhwamhwamhwamhwamhwamhwamhwamhwamhwamhwamhwamhwamhqgdn98t",
25+
"desc": "addr(bcrt1qamhwamhwamhwamhwamhwamhwamhwamhwamhwamhwamhwamhwamhqgdn98t)#afaecevx",
2326
"type": "witness_v0_scripthash",
2427
"p2sh": "2MwGk8mw1GBP6U9D5X8gTvgvXpuknmAK3fo"
2528
}
@@ -29,38 +32,44 @@
2932
{
3033
"asm": "OP_HASH160 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee OP_EQUAL",
3134
"address": "2NF2b3KS8xXb9XHvbRMXdZh8s5g92rUZHtp",
35+
"desc": "addr(2NF2b3KS8xXb9XHvbRMXdZh8s5g92rUZHtp)#ywfcpmh9",
3236
"type": "scripthash"
3337
}
3438
],
3539
[
3640
"6a00",
3741
{
3842
"asm": "OP_RETURN 0",
43+
"desc": "raw(6a00)#ncfmkl43",
3944
"type": "nulldata"
4045
}
4146
],
4247
[
4348
"6aee",
4449
{
4550
"asm": "OP_RETURN OP_UNKNOWN",
51+
"desc": "raw(6aee)#vsyzgqdt",
4652
"type": "nonstandard"
4753
}
4854
],
4955
[
5056
"6a02ee",
5157
{
5258
"asm": "OP_RETURN [error]",
59+
"desc": "raw(6a02ee)#gvdwnlzl",
5360
"type": "nonstandard"
5461
}
5562
],
5663
[
5764
"02eeee",
5865
{
5966
"asm": "-28398",
67+
"desc": "raw(02eeee)#5xzck7pr",
6068
"type": "nonstandard",
6169
"p2sh": "2N34iiGoUUkVSPiaaTFpJjB1FR9TXQu3PGM",
6270
"segwit": {
6371
"asm": "0 96c2368fc30514a438a8bd909f93c49a1549d77198ccbdb792043b666cb24f42",
72+
"desc": "addr(bcrt1qjmprdr7rq522gw9ghkgfly7yng25n4m3nrxtmdujqsakvm9jfapqk795l5)#5akkdska",
6473
"hex": "002096c2368fc30514a438a8bd909f93c49a1549d77198ccbdb792043b666cb24f42",
6574
"address": "bcrt1qjmprdr7rq522gw9ghkgfly7yng25n4m3nrxtmdujqsakvm9jfapqk795l5",
6675
"type": "witness_v0_scripthash",
@@ -72,13 +81,15 @@
7281
"ba",
7382
{
7483
"asm": "OP_CHECKSIGADD",
84+
"desc": "raw(ba)#yy0eg44l",
7585
"type": "nonstandard"
7686
}
7787
],
7888
[
7989
"50",
8090
{
8191
"asm": "OP_RESERVED",
92+
"desc": "raw(50)#a7tu03xf",
8293
"type": "nonstandard"
8394
}
8495
]

test/util/data/tt-delin1-out.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@
194194
"n": 0,
195195
"scriptPubKey": {
196196
"asm": "OP_DUP OP_HASH160 8fd139bb39ced713f231c58a4d07bf6954d1c201 OP_EQUALVERIFY OP_CHECKSIG",
197+
"desc": "addr(1E7SGgAZFCHDnVZLuRViX3gUmxpMfdvd2o)#xvg87vgr",
197198
"hex": "76a9148fd139bb39ced713f231c58a4d07bf6954d1c20188ac",
198199
"address": "1E7SGgAZFCHDnVZLuRViX3gUmxpMfdvd2o",
199200
"type": "pubkeyhash"
@@ -204,6 +205,7 @@
204205
"n": 1,
205206
"scriptPubKey": {
206207
"asm": "OP_DUP OP_HASH160 6c772e9cf96371bba3da8cb733da70a2fcf20078 OP_EQUALVERIFY OP_CHECKSIG",
208+
"desc": "addr(1AtWkdmfmYkErU16d3KYykJUbEp9MAj9Sb)#tsyprkms",
207209
"hex": "76a9146c772e9cf96371bba3da8cb733da70a2fcf2007888ac",
208210
"address": "1AtWkdmfmYkErU16d3KYykJUbEp9MAj9Sb",
209211
"type": "pubkeyhash"

test/util/data/tt-delout1-out.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
"n": 0,
204204
"scriptPubKey": {
205205
"asm": "OP_DUP OP_HASH160 8fd139bb39ced713f231c58a4d07bf6954d1c201 OP_EQUALVERIFY OP_CHECKSIG",
206+
"desc": "addr(1E7SGgAZFCHDnVZLuRViX3gUmxpMfdvd2o)#xvg87vgr",
206207
"hex": "76a9148fd139bb39ced713f231c58a4d07bf6954d1c20188ac",
207208
"address": "1E7SGgAZFCHDnVZLuRViX3gUmxpMfdvd2o",
208209
"type": "pubkeyhash"

test/util/data/tt-locktime317000-out.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
"n": 0,
204204
"scriptPubKey": {
205205
"asm": "OP_DUP OP_HASH160 8fd139bb39ced713f231c58a4d07bf6954d1c201 OP_EQUALVERIFY OP_CHECKSIG",
206+
"desc": "addr(1E7SGgAZFCHDnVZLuRViX3gUmxpMfdvd2o)#xvg87vgr",
206207
"hex": "76a9148fd139bb39ced713f231c58a4d07bf6954d1c20188ac",
207208
"address": "1E7SGgAZFCHDnVZLuRViX3gUmxpMfdvd2o",
208209
"type": "pubkeyhash"
@@ -213,6 +214,7 @@
213214
"n": 1,
214215
"scriptPubKey": {
215216
"asm": "OP_DUP OP_HASH160 6c772e9cf96371bba3da8cb733da70a2fcf20078 OP_EQUALVERIFY OP_CHECKSIG",
217+
"desc": "addr(1AtWkdmfmYkErU16d3KYykJUbEp9MAj9Sb)#tsyprkms",
216218
"hex": "76a9146c772e9cf96371bba3da8cb733da70a2fcf2007888ac",
217219
"address": "1AtWkdmfmYkErU16d3KYykJUbEp9MAj9Sb",
218220
"type": "pubkeyhash"

test/util/data/txcreate1.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"n": 0,
4242
"scriptPubKey": {
4343
"asm": "OP_DUP OP_HASH160 1fc11f39be1729bf973a7ab6a615ca4729d64574 OP_EQUALVERIFY OP_CHECKSIG",
44+
"desc": "addr(13tuJJDR2RgArmgfv6JScSdreahzgc4T6o)#ztmwxg4c",
4445
"hex": "76a9141fc11f39be1729bf973a7ab6a615ca4729d6457488ac",
4546
"address": "13tuJJDR2RgArmgfv6JScSdreahzgc4T6o",
4647
"type": "pubkeyhash"
@@ -51,6 +52,7 @@
5152
"n": 1,
5253
"scriptPubKey": {
5354
"asm": "OP_DUP OP_HASH160 f2d4db28cad6502226ee484ae24505c2885cb12d OP_EQUALVERIFY OP_CHECKSIG",
55+
"desc": "addr(1P8yWvZW8jVihP1bzHeqfE4aoXNX8AVa46)#vdmdu766",
5456
"hex": "76a914f2d4db28cad6502226ee484ae24505c2885cb12d88ac",
5557
"address": "1P8yWvZW8jVihP1bzHeqfE4aoXNX8AVa46",
5658
"type": "pubkeyhash"

test/util/data/txcreate2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"n": 0,
1515
"scriptPubKey": {
1616
"asm": "",
17+
"desc": "raw()#58lrscpx",
1718
"hex": "",
1819
"type": "nonstandard"
1920
}

0 commit comments

Comments
 (0)