Skip to content

Commit c143c49

Browse files
committed
Merge pull request #7072
996d311 [RPC] Add transaction size to JSON output (Nick)
2 parents 438ee59 + 996d311 commit c143c49

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

src/rpcrawtransaction.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fInclud
6262
void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry)
6363
{
6464
entry.push_back(Pair("txid", tx.GetHash().GetHex()));
65+
entry.push_back(Pair("size", (int)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION)));
6566
entry.push_back(Pair("version", tx.nVersion));
6667
entry.push_back(Pair("locktime", (int64_t)tx.nLockTime));
6768
UniValue vin(UniValue::VARR);
@@ -133,6 +134,7 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp)
133134
"{\n"
134135
" \"hex\" : \"data\", (string) The serialized, hex-encoded data for 'txid'\n"
135136
" \"txid\" : \"id\", (string) The transaction id (same as provided)\n"
137+
" \"size\" : n, (numeric) The transaction size\n"
136138
" \"version\" : n, (numeric) The version\n"
137139
" \"locktime\" : ttt, (numeric) The lock time\n"
138140
" \"vin\" : [ (array of json objects)\n"
@@ -429,6 +431,7 @@ UniValue decoderawtransaction(const UniValue& params, bool fHelp)
429431
"\nResult:\n"
430432
"{\n"
431433
" \"txid\" : \"id\", (string) The transaction id\n"
434+
" \"size\" : n, (numeric) The transaction size\n"
432435
" \"version\" : n, (numeric) The version\n"
433436
" \"locktime\" : ttt, (numeric) The lock time\n"
434437
" \"vin\" : [ (array of json objects)\n"

src/test/rpc_tests.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ BOOST_AUTO_TEST_CASE(rpc_rawparams)
7272
BOOST_CHECK_THROW(CallRPC("decoderawtransaction DEADBEEF"), runtime_error);
7373
string rawtx = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000";
7474
BOOST_CHECK_NO_THROW(r = CallRPC(string("decoderawtransaction ")+rawtx));
75+
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "size").get_int(), 193);
7576
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "version").get_int(), 1);
7677
BOOST_CHECK_EQUAL(find_value(r.get_obj(), "locktime").get_int(), 0);
7778
BOOST_CHECK_THROW(r = CallRPC(string("decoderawtransaction ")+rawtx+" extra"), runtime_error);

0 commit comments

Comments
 (0)