Skip to content

Commit 1fcaf34

Browse files
achow101knst
authored andcommitted
Merge bitcoin#16795: rpc: have raw transaction decoding infer output descriptors
6498ba1 transaction decoding infer output descriptors (Gregory Sanders) Pull request description: Following discussion in bitcoin#16725 this is complementary data to expose. All outputs are inferred. ACKs for top commit: achow101: ACK 6498ba1 meshcollider: utACK 6498ba1 Tree-SHA512: 36664117ddbe46d5fdde7ed6541ef2c9d8dfb7a3636b97f363bf1c325096fe00d9d2acea2d1917ea19fdb82f1ea296c12e440c5c703d6a9bfc1a02fba028bcd8
1 parent a257f9e commit 1fcaf34

20 files changed

+30
-1
lines changed

doc/REST-interface.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ $ curl localhost:19998/rest/getutxos/checkmempool/b2cdfd7b89def827ff8af7cd9bff76
111111
"value" : 8.8687,
112112
"scriptPubKey" : {
113113
"asm" : "OP_DUP OP_HASH160 1c7cebb529b86a04c683dfa87be49de35bcf589e OP_EQUALVERIFY OP_CHECKSIG",
114+
"desc" : "addr(mi7as51dvLJsizWnTMurtRmrP8hG2m1XvD)#gj9tznmy"
114115
"hex" : "76a9141c7cebb529b86a04c683dfa87be49de35bcf589e88ac",
115116
"type" : "pubkeyhash",
116117
"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/validation.h>
99
#include <key_io.h>
1010
#include <primitives/transaction.h>
11+
#include <script/descriptor.h>
1112
#include <script/script.h>
1213
#include <script/standard.h>
1314
#include <serialize.h>
@@ -162,6 +163,7 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool include
162163
CTxDestination address;
163164

164165
out.pushKV("asm", ScriptToAsmStr(scriptPubKey));
166+
out.pushKV("desc", InferDescriptor(scriptPubKey, DUMMY_SIGNING_PROVIDER)->ToString());
165167
if (include_hex) out.pushKV("hex", HexStr(scriptPubKey));
166168

167169
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
@@ -1250,6 +1250,7 @@ static RPCHelpMan gettxout()
12501250
{RPCResult::Type::OBJ, "scriptPubKey", "",
12511251
{
12521252
{RPCResult::Type::STR, "asm", ""},
1253+
{RPCResult::Type::STR, "desc", "Inferred descriptor for the output"},
12531254
{RPCResult::Type::STR_HEX, "hex", ""},
12541255
{RPCResult::Type::STR_HEX, "type", "The type, eg pubkeyhash"},
12551256
{RPCResult::Type::STR, "address", /* optional */ true, "Dash address (only if a well-defined address exists)"},

src/rpc/rawtransaction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ static RPCHelpMan getrawtransaction()
212212
{RPCResult::Type::OBJ, "scriptPubKey", "",
213213
{
214214
{RPCResult::Type::STR, "asm", "the asm"},
215+
{RPCResult::Type::STR, "desc", "Inferred descriptor for the output"},
215216
{RPCResult::Type::STR, "hex", "the hex"},
216217
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
217218
{RPCResult::Type::STR, "address", /* optional */ true, "The Dash address (only if a well-defined address exists)"},
@@ -764,6 +765,7 @@ static RPCHelpMan decoderawtransaction()
764765
{RPCResult::Type::OBJ, "scriptPubKey", "",
765766
{
766767
{RPCResult::Type::STR, "asm", "the asm"},
768+
{RPCResult::Type::STR, "desc", "Inferred descriptor for the output"},
767769
{RPCResult::Type::STR_HEX, "hex", "the hex"},
768770
{RPCResult::Type::STR, "type", "The type, eg 'pubkeyhash'"},
769771
{RPCResult::Type::STR, "address", /* optional */ true, "The Dash address (only if a well-defined address exists)"},
@@ -807,6 +809,7 @@ static RPCHelpMan decodescript()
807809
RPCResult::Type::OBJ, "", "",
808810
{
809811
{RPCResult::Type::STR, "asm", "Script public key"},
812+
{RPCResult::Type::STR, "desc", "Inferred descriptor for the script"},
810813
{RPCResult::Type::STR, "type", "The output type (e.g. " + GetAllOutputTypes() + ")"},
811814
{RPCResult::Type::STR, "address", /* optional */ true, "The Dash address (only if a well-defined address exists)"},
812815
},

test/functional/data/rpc_decodescript.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{
55
"asm": "OP_HASH160 eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee OP_EQUAL",
66
"address": "92Cpm6g9Hba4maFG66aDjVxcgPY4wnQM4E",
7+
"desc": "addr(92Cpm6g9Hba4maFG66aDjVxcgPY4wnQM4E)#w082pp4j",
78
"type": "scripthash"
89
}
910
],
@@ -12,7 +13,8 @@
1213
{
1314
"asm": "OP_RETURN 0",
1415
"type": "nulldata",
15-
"p2sh": "93JSZ4DRLAifokPwn3C6WtnZoAVHwDa6UP"
16+
"p2sh": "93JSZ4DRLAifokPwn3C6WtnZoAVHwDa6UP",
17+
"desc": "raw(6a00)#ncfmkl43"
1618
}
1719
]
1820
]

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
"n": 0,
194194
"scriptPubKey": {
195195
"asm": "OP_DUP OP_HASH160 8fd139bb39ced713f231c58a4d07bf6954d1c201 OP_EQUALVERIFY OP_CHECKSIG",
196+
"desc": "addr(XooH6vpTCuVowS9vmJowNaNGcJQ3cQT7rs)#faud38f0",
196197
"hex": "76a9148fd139bb39ced713f231c58a4d07bf6954d1c20188ac",
197198
"address": "XooH6vpTCuVowS9vmJowNaNGcJQ3cQT7rs",
198199
"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(XkaMatRZjFxq1QbgUvdmqGzGRaPqSLvvS6)#kvxym3t8",
207209
"hex": "76a9146c772e9cf96371bba3da8cb733da70a2fcf2007888ac",
208210
"address": "XkaMatRZjFxq1QbgUvdmqGzGRaPqSLvvS6",
209211
"type": "pubkeyhash"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
"n": 0,
203203
"scriptPubKey": {
204204
"asm": "OP_DUP OP_HASH160 8fd139bb39ced713f231c58a4d07bf6954d1c201 OP_EQUALVERIFY OP_CHECKSIG",
205+
"desc": "addr(XooH6vpTCuVowS9vmJowNaNGcJQ3cQT7rs)#faud38f0",
205206
"hex": "76a9148fd139bb39ced713f231c58a4d07bf6954d1c20188ac",
206207
"address": "XooH6vpTCuVowS9vmJowNaNGcJQ3cQT7rs",
207208
"type": "pubkeyhash"

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
"n": 0,
203203
"scriptPubKey": {
204204
"asm": "OP_DUP OP_HASH160 8fd139bb39ced713f231c58a4d07bf6954d1c201 OP_EQUALVERIFY OP_CHECKSIG",
205+
"desc": "addr(XooH6vpTCuVowS9vmJowNaNGcJQ3cQT7rs)#faud38f0",
205206
"hex": "76a9148fd139bb39ced713f231c58a4d07bf6954d1c20188ac",
206207
"address": "XooH6vpTCuVowS9vmJowNaNGcJQ3cQT7rs",
207208
"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(XkaMatRZjFxq1QbgUvdmqGzGRaPqSLvvS6)#kvxym3t8",
216218
"hex": "76a9146c772e9cf96371bba3da8cb733da70a2fcf2007888ac",
217219
"address": "XkaMatRZjFxq1QbgUvdmqGzGRaPqSLvvS6",
218220
"type": "pubkeyhash"

test/util/data/txcreate1.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"n": 0,
4141
"scriptPubKey": {
4242
"asm": "OP_DUP OP_HASH160 1fc11f39be1729bf973a7ab6a615ca4729d64574 OP_EQUALVERIFY OP_CHECKSIG",
43+
"desc": "addr(Xdak8YsJz8tm1iHFmycfTyKeUvHgfbdpyw)#nr4se9ls",
4344
"hex": "76a9141fc11f39be1729bf973a7ab6a615ca4729d6457488ac",
4445
"address": "Xdak8YsJz8tm1iHFmycfTyKeUvHgfbdpyw",
4546
"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(XxppMBDQ6SiJrKcBrAy4WkkNdrxDBfzFdZ)#ack2ftlg",
5456
"hex": "76a914f2d4db28cad6502226ee484ae24505c2885cb12d88ac",
5557
"address": "XxppMBDQ6SiJrKcBrAy4WkkNdrxDBfzFdZ",
5658
"type": "pubkeyhash"

test/util/data/txcreate2.json

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

test/util/data/txcreatedata1.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"n": 0,
2323
"scriptPubKey": {
2424
"asm": "OP_DUP OP_HASH160 1fc11f39be1729bf973a7ab6a615ca4729d64574 OP_EQUALVERIFY OP_CHECKSIG",
25+
"desc": "addr(Xdak8YsJz8tm1iHFmycfTyKeUvHgfbdpyw)#nr4se9ls",
2526
"hex": "76a9141fc11f39be1729bf973a7ab6a615ca4729d6457488ac",
2627
"address": "Xdak8YsJz8tm1iHFmycfTyKeUvHgfbdpyw",
2728
"type": "pubkeyhash"
@@ -33,6 +34,7 @@
3334
"n": 1,
3435
"scriptPubKey": {
3536
"asm": "OP_RETURN 54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e",
37+
"desc": "raw(6a4c4f54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e)#zf2avljj",
3638
"hex": "6a4c4f54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e",
3739
"type": "nulldata"
3840
}

test/util/data/txcreatedata2.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"n": 0,
2323
"scriptPubKey": {
2424
"asm": "OP_DUP OP_HASH160 1fc11f39be1729bf973a7ab6a615ca4729d64574 OP_EQUALVERIFY OP_CHECKSIG",
25+
"desc": "addr(Xdak8YsJz8tm1iHFmycfTyKeUvHgfbdpyw)#nr4se9ls",
2526
"hex": "76a9141fc11f39be1729bf973a7ab6a615ca4729d6457488ac",
2627
"address": "Xdak8YsJz8tm1iHFmycfTyKeUvHgfbdpyw",
2728
"type": "pubkeyhash"
@@ -33,6 +34,7 @@
3334
"n": 1,
3435
"scriptPubKey": {
3536
"asm": "OP_RETURN 54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e",
37+
"desc": "raw(6a4c4f54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e)#zf2avljj",
3638
"hex": "6a4c4f54686973204f505f52455455524e207472616e73616374696f6e206f7574707574207761732063726561746564206279206d6f646966696564206372656174657261777472616e73616374696f6e2e",
3739
"type": "nulldata"
3840
}

test/util/data/txcreatedata_seq0.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"n": 0,
2323
"scriptPubKey": {
2424
"asm": "OP_DUP OP_HASH160 1fc11f39be1729bf973a7ab6a615ca4729d64574 OP_EQUALVERIFY OP_CHECKSIG",
25+
"desc": "addr(Xdak8YsJz8tm1iHFmycfTyKeUvHgfbdpyw)#nr4se9ls",
2526
"hex": "76a9141fc11f39be1729bf973a7ab6a615ca4729d6457488ac",
2627
"address": "Xdak8YsJz8tm1iHFmycfTyKeUvHgfbdpyw",
2728
"type": "pubkeyhash"

test/util/data/txcreatedata_seq1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"n": 0,
3232
"scriptPubKey": {
3333
"asm": "OP_DUP OP_HASH160 1fc11f39be1729bf973a7ab6a615ca4729d64574 OP_EQUALVERIFY OP_CHECKSIG",
34+
"desc": "addr(Xdak8YsJz8tm1iHFmycfTyKeUvHgfbdpyw)#nr4se9ls",
3435
"hex": "76a9141fc11f39be1729bf973a7ab6a615ca4729d6457488ac",
3536
"address": "Xdak8YsJz8tm1iHFmycfTyKeUvHgfbdpyw",
3637
"type": "pubkeyhash"

test/util/data/txcreatemultisig1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"n": 0,
1414
"scriptPubKey": {
1515
"asm": "2 02a5613bd857b7048924264d1e70e08fb2a7e6527d32b7ab1bb993ac59964ff397 021ac43c7ff740014c3b33737ede99c967e4764553d1b2b83db77c83b8715fa72d 02df2089105c77f266fa11a9d33f05c735234075f2e8780824c6b709415f9fb485 3 OP_CHECKMULTISIG",
16+
"desc": "multi(2,02a5613bd857b7048924264d1e70e08fb2a7e6527d32b7ab1bb993ac59964ff397,021ac43c7ff740014c3b33737ede99c967e4764553d1b2b83db77c83b8715fa72d,02df2089105c77f266fa11a9d33f05c735234075f2e8780824c6b709415f9fb485)#8s88p9pl",
1617
"hex": "522102a5613bd857b7048924264d1e70e08fb2a7e6527d32b7ab1bb993ac59964ff39721021ac43c7ff740014c3b33737ede99c967e4764553d1b2b83db77c83b8715fa72d2102df2089105c77f266fa11a9d33f05c735234075f2e8780824c6b709415f9fb48553ae",
1718
"type": "multisig"
1819
}

test/util/data/txcreatemultisig2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"n": 0,
1414
"scriptPubKey": {
1515
"asm": "OP_HASH160 1c6fbaf46d64221e80cbae182c33ddf81b9294ac OP_EQUAL",
16+
"desc": "addr(7V11XGPxzBWxkiuw15a1Vgk7XT74tyYtCY)#2m9p8juh",
1617
"hex": "a9141c6fbaf46d64221e80cbae182c33ddf81b9294ac87",
1718
"address": "7V11XGPxzBWxkiuw15a1Vgk7XT74tyYtCY",
1819
"type": "scripthash"

test/util/data/txcreateoutpubkey1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"n": 0,
1414
"scriptPubKey": {
1515
"asm": "02a5613bd857b7048924264d1e70e08fb2a7e6527d32b7ab1bb993ac59964ff397 OP_CHECKSIG",
16+
"desc": "pk(02a5613bd857b7048924264d1e70e08fb2a7e6527d32b7ab1bb993ac59964ff397)#rk5v7uqw",
1617
"hex": "2102a5613bd857b7048924264d1e70e08fb2a7e6527d32b7ab1bb993ac59964ff397ac",
1718
"type": "pubkey"
1819
}

test/util/data/txcreatescript1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"n": 0,
1414
"scriptPubKey": {
1515
"asm": "OP_DROP",
16+
"desc": "raw(75)#ppey0zqj",
1617
"hex": "75",
1718
"type": "nonstandard"
1819
}

test/util/data/txcreatescript2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"n": 0,
1414
"scriptPubKey": {
1515
"asm": "OP_HASH160 71ed53322d470bb96657deb786b94f97dd46fb15 OP_EQUAL",
16+
"desc": "addr(7co3R3WSW8mHKMkFK2FrzQY2fLCBWsg56D)#tjdnllwj",
1617
"hex": "a91471ed53322d470bb96657deb786b94f97dd46fb1587",
1718
"address": "7co3R3WSW8mHKMkFK2FrzQY2fLCBWsg56D",
1819
"type": "scripthash"

test/util/data/txcreatesignv1.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"n": 0,
2323
"scriptPubKey": {
2424
"asm": "OP_DUP OP_HASH160 5834479edbbe0539b31ffd3a8f8ebadc2165ed01 OP_EQUALVERIFY OP_CHECKSIG",
25+
"desc": "addr(XijDvbYpPmznwgpWD3DkdYNfGmRP2KoVSk)#m8zt5egk",
2526
"hex": "76a9145834479edbbe0539b31ffd3a8f8ebadc2165ed0188ac",
2627
"address": "XijDvbYpPmznwgpWD3DkdYNfGmRP2KoVSk",
2728
"type": "pubkeyhash"

0 commit comments

Comments
 (0)