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

Conversation

Projects
None yet
10 participants
@Har01d
Contributor

Har01d commented Nov 21, 2015

This may be useful for blockchain explorers.

@jonasschnelli

This comment has been minimized.

Show comment
Hide comment
@jonasschnelli

jonasschnelli Nov 21, 2015

Member

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.

Member

jonasschnelli commented Nov 21, 2015

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

This comment has been minimized.

Show comment
Hide comment
@Har01d

Har01d Nov 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.

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@jonasschnelli

jonasschnelli Nov 21, 2015

Member

Agreed. Over RPC/JSON it can be useful.

utACK.

Member

jonasschnelli commented Nov 21, 2015

Agreed. Over RPC/JSON it can be useful.

utACK.

@dcousens

This comment has been minimized.

Show comment
Hide comment
@dcousens

dcousens Nov 21, 2015

Contributor

ACK

Contributor

dcousens commented Nov 21, 2015

ACK

@tulip0

This comment has been minimized.

Show comment
Hide comment
@tulip0

tulip0 Nov 21, 2015

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

Field seems to be useful.

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

This comment has been minimized.

Show comment
Hide comment
@pstratem

pstratem Nov 22, 2015

Contributor

concept ACK

Contributor

pstratem commented Nov 22, 2015

concept ACK

@laanwj

This comment has been minimized.

Show comment
Hide comment
@laanwj

laanwj Nov 26, 2015

Member

Needs to be tested in one of the RPC tests

Member

laanwj commented Nov 26, 2015

Needs to be tested in one of the RPC tests

@sipa

This comment has been minimized.

Show comment
Hide comment
@sipa

sipa Nov 26, 2015

Member

utACK, but needs an RPC test indeed.

Member

sipa commented Nov 26, 2015

utACK, but needs an RPC test indeed.

@paveljanik

This comment has been minimized.

Show comment
Hide comment
@paveljanik

paveljanik Nov 28, 2015

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);
Contributor

paveljanik commented Nov 28, 2015

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

This comment has been minimized.

Show comment
Hide comment
@Har01d

Har01d Nov 28, 2015

Contributor

Thanks @paveljanik, I've added the test.

Contributor

Har01d commented Nov 28, 2015

Thanks @paveljanik, I've added the test.

@paveljanik

This comment has been minimized.

Show comment
Hide comment
@paveljanik

paveljanik Nov 28, 2015

Contributor

And now, squash everything in one commit.

Contributor

paveljanik commented Nov 28, 2015

And now, squash everything in one commit.

[RPC] Add transaction size to JSON output
This may be useful for blockchain explorers.
@Har01d

This comment has been minimized.

Show comment
Hide comment
@Har01d

Har01d Nov 28, 2015

Contributor

@paveljanik, done.

Contributor

Har01d commented Nov 28, 2015

@paveljanik, done.

@paveljanik

This comment has been minimized.

Show comment
Hide comment
@paveljanik

paveljanik Nov 28, 2015

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"
        ]
      }
    }
  ]
}
$ 
Contributor

paveljanik commented Nov 28, 2015

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

This comment has been minimized.

Show comment
Hide comment
@sipa

sipa Nov 28, 2015

Member

ACK

Member

sipa commented Nov 28, 2015

ACK

@MarcoFalke

This comment has been minimized.

Show comment
Hide comment
@MarcoFalke
Member

MarcoFalke commented Nov 28, 2015

utACK 996d311

@gmaxwell

This comment has been minimized.

Show comment
Hide comment
@gmaxwell

gmaxwell Dec 1, 2015

Member

ACK.

Member

gmaxwell commented Dec 1, 2015

ACK.

@gmaxwell gmaxwell merged commit 996d311 into bitcoin:master Dec 1, 2015

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

gmaxwell added a commit that referenced this pull request Dec 1, 2015

Merge pull request #7072
996d311 [RPC] Add transaction size to JSON output (Nick)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment