Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RPC] Add transaction size to JSON output #7072

Merged
merged 1 commit into from
Dec 1, 2015
Merged

Conversation

Har01d
Copy link
Contributor

@Har01d Har01d commented Nov 21, 2015

This may be useful for blockchain explorers.

@jonasschnelli
Copy link
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.

@Har01d
Copy link
Contributor Author

Har01d commented Nov 21, 2015

@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
Copy link
Contributor

Agreed. Over RPC/JSON it can be useful.

utACK.

@dcousens
Copy link
Contributor

ACK

@tulip0
Copy link

tulip0 commented Nov 21, 2015

>>> import requests
>>> requests.get("http://127.1:8332/rest/tx/6421d0b4dd71b0a823eb597cc5412b0af9f33bc456fb85c23b9ffe2eb18a7067.json").json()['size']
120

Field seems to be useful.

@pstratem
Copy link
Contributor

concept ACK

@laanwj
Copy link
Member

laanwj commented Nov 26, 2015

Needs to be tested in one of the RPC tests

@sipa
Copy link
Member

sipa commented Nov 26, 2015

utACK, but needs an RPC test indeed.

@paveljanik
Copy link
Contributor

ACK

For a test, you can use this change:

diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp
index 2a486f0..79d7fec 100644
--- a/src/test/rpc_tests.cpp
+++ b/src/test/rpc_tests.cpp
@@ -74,6 +74,7 @@ BOOST_AUTO_TEST_CASE(rpc_rawparams)
     BOOST_CHECK_NO_THROW(r = CallRPC(string("decoderawtransaction ")+rawtx));
     BOOST_CHECK_EQUAL(find_value(r.get_obj(), "version").get_int(), 1);
     BOOST_CHECK_EQUAL(find_value(r.get_obj(), "locktime").get_int(), 0);
+    BOOST_CHECK_EQUAL(find_value(r.get_obj(), "size").get_int(), 193);
     BOOST_CHECK_THROW(r = CallRPC(string("decoderawtransaction ")+rawtx+" extra"), runtime_error);

     BOOST_CHECK_THROW(CallRPC("signrawtransaction"), runtime_error);

@Har01d
Copy link
Contributor Author

Har01d commented Nov 28, 2015

Thanks @paveljanik, I've added the test.

@paveljanik
Copy link
Contributor

And now, squash everything in one commit.

This may be useful for blockchain explorers.
@Har01d
Copy link
Contributor Author

Har01d commented Nov 28, 2015

@paveljanik, done.

@paveljanik
Copy link
Contributor

perfect now, reACK

$ curl localhost:18332/rest/tx/00b308619c0cfae71a1375ac75353aab8fda9564be2fb29d146ce5ba7e75c687.json 2>/dev/null | json_pp
{
   "vout" : [
      {
         "n" : 0,
         "scriptPubKey" : {
            "addresses" : [
               "mhTohtQAoCemEZrMj6gYxwyRMQ5AH7DrmB"
            ],
            "type" : "pubkeyhash",
            "hex" : "76a9141557d578c41e5e5954b6ccf792eef781fce1a41188ac",
            "reqSigs" : 1,
            "asm" : "OP_DUP OP_HASH160 1557d578c41e5e5954b6ccf792eef781fce1a411 OP_EQUALVERIFY OP_CHECKSIG"
         },
         "value" : 0.88936742
      },
      {
         "n" : 1,
         "scriptPubKey" : {
            "addresses" : [
               "mn1cNcrQuHoRjGgDzQJWynca75VaVZjVXB"
            ],
            "type" : "pubkeyhash",
            "hex" : "76a914473c3029a6cd2fea28653fe0e2cfe0df44ad995a88ac",
            "reqSigs" : 1,
            "asm" : "OP_DUP OP_HASH160 473c3029a6cd2fea28653fe0e2cfe0df44ad995a OP_EQUALVERIFY OP_CHECKSIG"
         },
         "value" : 0.12
      }
   ],
   "txid" : "00b308619c0cfae71a1375ac75353aab8fda9564be2fb29d146ce5ba7e75c687",
   "version" : 1,
   "vin" : [
      {
         "vout" : 1,
         "sequence" : 4294967294,
         "txid" : "8cb542fb7930f93bcd83df0825f66e8334009fd411abed7ce4ab420d049ea6c0",
         "scriptSig" : {
            "hex" : "483045022100caa46f920976fbed34bc0b5dbeddeb3dca66360ed10dfd9898a09dbce0cd7627022019f999fa2388f5bbc48858446eb6fb281ea92f3815c5e940f3ead9396a8f442c012103c9ac0648e7f79ef5ccae4a09da0d8ea4ba17a60e5359e46de3c226e1abafa168",
            "asm" : "3045022100caa46f920976fbed34bc0b5dbeddeb3dca66360ed10dfd9898a09dbce0cd7627022019f999fa2388f5bbc48858446eb6fb281ea92f3815c5e940f3ead9396a8f442c[ALL] 03c9ac0648e7f79ef5ccae4a09da0d8ea4ba17a60e5359e46de3c226e1abafa168"
         }
      }
   ],
   "locktime" : 607711,
   "size" : 226
}
$ btctest decoderawtransaction 0100000001c0a69e040d42abe47cedab11d49f0034836ef62508df83cd3bf93079fb42b58c010000006b483045022100caa46f920976fbed34bc0b5dbeddeb3dca66360ed10dfd9898a09dbce0cd7627022019f999fa2388f5bbc48858446eb6fb281ea92f3815c5e940f3ead9396a8f442c012103c9ac0648e7f79ef5ccae4a09da0d8ea4ba17a60e5359e46de3c226e1abafa168feffffff0226114d05000000001976a9141557d578c41e5e5954b6ccf792eef781fce1a41188ac001bb700000000001976a914473c3029a6cd2fea28653fe0e2cfe0df44ad995a88acdf450900
{
  "txid": "00b308619c0cfae71a1375ac75353aab8fda9564be2fb29d146ce5ba7e75c687",
  "size": 226,
  "version": 1,
  "locktime": 607711,
  "vin": [
    {
      "txid": "8cb542fb7930f93bcd83df0825f66e8334009fd411abed7ce4ab420d049ea6c0",
      "vout": 1,
      "scriptSig": {
        "asm": "3045022100caa46f920976fbed34bc0b5dbeddeb3dca66360ed10dfd9898a09dbce0cd7627022019f999fa2388f5bbc48858446eb6fb281ea92f3815c5e940f3ead9396a8f442c[ALL] 03c9ac0648e7f79ef5ccae4a09da0d8ea4ba17a60e5359e46de3c226e1abafa168",
        "hex": "483045022100caa46f920976fbed34bc0b5dbeddeb3dca66360ed10dfd9898a09dbce0cd7627022019f999fa2388f5bbc48858446eb6fb281ea92f3815c5e940f3ead9396a8f442c012103c9ac0648e7f79ef5ccae4a09da0d8ea4ba17a60e5359e46de3c226e1abafa168"
      },
      "sequence": 4294967294
    }
  ],
  "vout": [
    {
      "value": 0.88936742,
      "n": 0,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 1557d578c41e5e5954b6ccf792eef781fce1a411 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a9141557d578c41e5e5954b6ccf792eef781fce1a41188ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "mhTohtQAoCemEZrMj6gYxwyRMQ5AH7DrmB"
        ]
      }
    }, 
    {
      "value": 0.12000000,
      "n": 1,
      "scriptPubKey": {
        "asm": "OP_DUP OP_HASH160 473c3029a6cd2fea28653fe0e2cfe0df44ad995a OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "76a914473c3029a6cd2fea28653fe0e2cfe0df44ad995a88ac",
        "reqSigs": 1,
        "type": "pubkeyhash",
        "addresses": [
          "mn1cNcrQuHoRjGgDzQJWynca75VaVZjVXB"
        ]
      }
    }
  ]
}
$ 

@sipa
Copy link
Member

sipa commented Nov 28, 2015

ACK

@maflcko
Copy link
Member

maflcko commented Nov 28, 2015

utACK 996d311

@gmaxwell
Copy link
Contributor

gmaxwell commented Dec 1, 2015

ACK.

@gmaxwell gmaxwell merged commit 996d311 into bitcoin:master Dec 1, 2015
gmaxwell added a commit that referenced this pull request Dec 1, 2015
996d311 [RPC] Add transaction size to JSON output (Nick)
zkbot added a commit to zcash/zcash that referenced this pull request Sep 28, 2020
[RPC] Add transaction size to JSON output

Cherry-picked from upstream PR bitcoin/bitcoin#7072.
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants