[RPC] Add transaction size to JSON output #7072
pull Har01d wants to merge 1 commits into bitcoin:master from Har01d:master changing 2 files +4 −0-
Har01d commented at 2:38 am on November 21, 2015: contributorThis may be useful for blockchain explorers.
-
jonasschnelli commented at 7:57 am on November 21, 2015: contributor
Not sure if this is really useful, because in both cases you know the size already by hexlen/2.
decoderawtrandaction
-> you pass a hexstring so you know the size already.gettransaction
size = result[‘hex’]/2.But no strong opinion.
-
jonasschnelli added the label RPC on Nov 21, 2015
-
Har01d commented at 8:21 am on November 21, 2015: contributor@jonasschnelli, it’s helpful when one uses REST API (
/rest/block/{blockhash}.json
or/rest/tx/{txid}.json
), since there’s no hex strings for transactions. Yes, you can use/rest/tx/{txid}.hex
or/rest/tx/{txid}.bin
for calculating the size, but that would be an additional query per transaction. -
jonasschnelli commented at 8:59 am on November 21, 2015: contributor
Agreed. Over RPC/JSON it can be useful.
utACK.
-
dcousens commented at 10:30 am on November 21, 2015: contributorACK
-
tulip0 commented at 1:07 pm on November 21, 2015: none
0>>> import requests 1>>> requests.get("http://127.1:8332/rest/tx/6421d0b4dd71b0a823eb597cc5412b0af9f33bc456fb85c23b9ffe2eb18a7067.json").json()['size'] 2120
Field seems to be useful.
-
pstratem commented at 9:40 pm on November 22, 2015: contributorconcept ACK
-
laanwj commented at 10:42 am on November 26, 2015: memberNeeds to be tested in one of the RPC tests
-
sipa commented at 3:41 pm on November 26, 2015: memberutACK, but needs an RPC test indeed.
-
paveljanik commented at 11:47 am on November 28, 2015: contributor
ACK
For a test, you can use this change:
0diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp 1index 2a486f0..79d7fec 100644 2--- a/src/test/rpc_tests.cpp 3+++ b/src/test/rpc_tests.cpp 4@@ -74,6 +74,7 @@ BOOST_AUTO_TEST_CASE(rpc_rawparams) 5 BOOST_CHECK_NO_THROW(r = CallRPC(string("decoderawtransaction ")+rawtx)); 6 BOOST_CHECK_EQUAL(find_value(r.get_obj(), "version").get_int(), 1); 7 BOOST_CHECK_EQUAL(find_value(r.get_obj(), "locktime").get_int(), 0); 8+ BOOST_CHECK_EQUAL(find_value(r.get_obj(), "size").get_int(), 193); 9 BOOST_CHECK_THROW(r = CallRPC(string("decoderawtransaction ")+rawtx+" extra"), runtime_error); 10 11 BOOST_CHECK_THROW(CallRPC("signrawtransaction"), runtime_error);
-
Har01d commented at 12:58 pm on November 28, 2015: contributorThanks @paveljanik, I’ve added the test.
-
paveljanik commented at 1:04 pm on November 28, 2015: contributorAnd now, squash everything in one commit.
-
[RPC] Add transaction size to JSON output
This may be useful for blockchain explorers.
-
Har01d force-pushed on Nov 28, 2015
-
Har01d commented at 5:22 pm on November 28, 2015: contributor@paveljanik, done.
-
paveljanik commented at 5:38 pm on November 28, 2015: contributor
perfect now, reACK
0$ curl localhost:18332/rest/tx/00b308619c0cfae71a1375ac75353aab8fda9564be2fb29d146ce5ba7e75c687.json 2>/dev/null | json_pp 1{ 2 "vout" : [ 3 { 4 "n" : 0, 5 "scriptPubKey" : { 6 "addresses" : [ 7 "mhTohtQAoCemEZrMj6gYxwyRMQ5AH7DrmB" 8 ], 9 "type" : "pubkeyhash", 10 "hex" : "76a9141557d578c41e5e5954b6ccf792eef781fce1a41188ac", 11 "reqSigs" : 1, 12 "asm" : "OP_DUP OP_HASH160 1557d578c41e5e5954b6ccf792eef781fce1a411 OP_EQUALVERIFY OP_CHECKSIG" 13 }, 14 "value" : 0.88936742 15 }, 16 { 17 "n" : 1, 18 "scriptPubKey" : { 19 "addresses" : [ 20 "mn1cNcrQuHoRjGgDzQJWynca75VaVZjVXB" 21 ], 22 "type" : "pubkeyhash", 23 "hex" : "76a914473c3029a6cd2fea28653fe0e2cfe0df44ad995a88ac", 24 "reqSigs" : 1, 25 "asm" : "OP_DUP OP_HASH160 473c3029a6cd2fea28653fe0e2cfe0df44ad995a OP_EQUALVERIFY OP_CHECKSIG" 26 }, 27 "value" : 0.12 28 } 29 ], 30 "txid" : "00b308619c0cfae71a1375ac75353aab8fda9564be2fb29d146ce5ba7e75c687", 31 "version" : 1, 32 "vin" : [ 33 { 34 "vout" : 1, 35 "sequence" : 4294967294, 36 "txid" : "8cb542fb7930f93bcd83df0825f66e8334009fd411abed7ce4ab420d049ea6c0", 37 "scriptSig" : { 38 "hex" : "483045022100caa46f920976fbed34bc0b5dbeddeb3dca66360ed10dfd9898a09dbce0cd7627022019f999fa2388f5bbc48858446eb6fb281ea92f3815c5e940f3ead9396a8f442c012103c9ac0648e7f79ef5ccae4a09da0d8ea4ba17a60e5359e46de3c226e1abafa168", 39 "asm" : "3045022100caa46f920976fbed34bc0b5dbeddeb3dca66360ed10dfd9898a09dbce0cd7627022019f999fa2388f5bbc48858446eb6fb281ea92f3815c5e940f3ead9396a8f442c[ALL] 03c9ac0648e7f79ef5ccae4a09da0d8ea4ba17a60e5359e46de3c226e1abafa168" 40 } 41 } 42 ], 43 "locktime" : 607711, 44 "size" : 226 45} 46$ btctest decoderawtransaction 0100000001c0a69e040d42abe47cedab11d49f0034836ef62508df83cd3bf93079fb42b58c010000006b483045022100caa46f920976fbed34bc0b5dbeddeb3dca66360ed10dfd9898a09dbce0cd7627022019f999fa2388f5bbc48858446eb6fb281ea92f3815c5e940f3ead9396a8f442c012103c9ac0648e7f79ef5ccae4a09da0d8ea4ba17a60e5359e46de3c226e1abafa168feffffff0226114d05000000001976a9141557d578c41e5e5954b6ccf792eef781fce1a41188ac001bb700000000001976a914473c3029a6cd2fea28653fe0e2cfe0df44ad995a88acdf450900 47{ 48 "txid": "00b308619c0cfae71a1375ac75353aab8fda9564be2fb29d146ce5ba7e75c687", 49 "size": 226, 50 "version": 1, 51 "locktime": 607711, 52 "vin": [ 53 { 54 "txid": "8cb542fb7930f93bcd83df0825f66e8334009fd411abed7ce4ab420d049ea6c0", 55 "vout": 1, 56 "scriptSig": { 57 "asm": "3045022100caa46f920976fbed34bc0b5dbeddeb3dca66360ed10dfd9898a09dbce0cd7627022019f999fa2388f5bbc48858446eb6fb281ea92f3815c5e940f3ead9396a8f442c[ALL] 03c9ac0648e7f79ef5ccae4a09da0d8ea4ba17a60e5359e46de3c226e1abafa168", 58 "hex": "483045022100caa46f920976fbed34bc0b5dbeddeb3dca66360ed10dfd9898a09dbce0cd7627022019f999fa2388f5bbc48858446eb6fb281ea92f3815c5e940f3ead9396a8f442c012103c9ac0648e7f79ef5ccae4a09da0d8ea4ba17a60e5359e46de3c226e1abafa168" 59 }, 60 "sequence": 4294967294 61 } 62 ], 63 "vout": [ 64 { 65 "value": 0.88936742, 66 "n": 0, 67 "scriptPubKey": { 68 "asm": "OP_DUP OP_HASH160 1557d578c41e5e5954b6ccf792eef781fce1a411 OP_EQUALVERIFY OP_CHECKSIG", 69 "hex": "76a9141557d578c41e5e5954b6ccf792eef781fce1a41188ac", 70 "reqSigs": 1, 71 "type": "pubkeyhash", 72 "addresses": [ 73 "mhTohtQAoCemEZrMj6gYxwyRMQ5AH7DrmB" 74 ] 75 } 76 }, 77 { 78 "value": 0.12000000, 79 "n": 1, 80 "scriptPubKey": { 81 "asm": "OP_DUP OP_HASH160 473c3029a6cd2fea28653fe0e2cfe0df44ad995a OP_EQUALVERIFY OP_CHECKSIG", 82 "hex": "76a914473c3029a6cd2fea28653fe0e2cfe0df44ad995a88ac", 83 "reqSigs": 1, 84 "type": "pubkeyhash", 85 "addresses": [ 86 "mn1cNcrQuHoRjGgDzQJWynca75VaVZjVXB" 87 ] 88 } 89 } 90 ] 91} 92$
-
sipa commented at 5:39 pm on November 28, 2015: memberACK
-
MarcoFalke commented at 6:16 pm on November 28, 2015: memberutACK 996d311
-
gmaxwell commented at 6:59 am on December 1, 2015: contributorACK.
-
gmaxwell merged this on Dec 1, 2015
-
gmaxwell closed this on Dec 1, 2015
-
gmaxwell referenced this in commit c143c499c8 on Dec 1, 2015
-
zkbot referenced this in commit 94cf4a4946 on Sep 28, 2020
-
MarcoFalke locked this on Sep 8, 2021
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 18:12 UTC
This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-17 18:12 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me
More mirrored repositories can be found on mirror.b10c.me