Skip to content

Commit 2874709

Browse files
committed
Expose a transaction's weight via RPC
1 parent 5f2a399 commit 2874709

26 files changed

+27
-0
lines changed

src/core_write.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry,
161161
entry.pushKV("version", tx.nVersion);
162162
entry.pushKV("size", (int)::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION));
163163
entry.pushKV("vsize", (GetTransactionWeight(tx) + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR);
164+
entry.pushKV("weight", GetTransactionWeight(tx));
164165
entry.pushKV("locktime", (int64_t)tx.nLockTime);
165166

166167
UniValue vin(UniValue::VARR);

src/rpc/rawtransaction.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
9494
" \"hash\" : \"id\", (string) The transaction hash (differs from txid for witness transactions)\n"
9595
" \"size\" : n, (numeric) The serialized transaction size\n"
9696
" \"vsize\" : n, (numeric) The virtual transaction size (differs from size for witness transactions)\n"
97+
" \"weight\" : n, (numeric) The transaction's weight (between vsize*4-3 and vsize*4)\n"
9798
" \"version\" : n, (numeric) The version\n"
9899
" \"locktime\" : ttt, (numeric) The lock time\n"
99100
" \"vin\" : [ (array of json objects)\n"
@@ -494,6 +495,7 @@ UniValue decoderawtransaction(const JSONRPCRequest& request)
494495
" \"hash\" : \"id\", (string) The transaction hash (differs from txid for witness transactions)\n"
495496
" \"size\" : n, (numeric) The transaction size\n"
496497
" \"vsize\" : n, (numeric) The virtual transaction size (differs from size for witness transactions)\n"
498+
" \"weight\" : n, (numeric) The transaction's weight (between vsize*4 - 3 and vsize*4)\n"
497499
" \"version\" : n, (numeric) The version\n"
498500
" \"locktime\" : ttt, (numeric) The lock time\n"
499501
" \"vin\" : [ (array of json objects)\n"

test/util/data/blanktxv1.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 10,
66
"vsize": 10,
7+
"weight": 40,
78
"locktime": 0,
89
"vin": [
910
],

test/util/data/blanktxv2.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 2,
55
"size": 10,
66
"vsize": 10,
7+
"weight": 40,
78
"locktime": 0,
89
"vin": [
910
],

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

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 3040,
66
"vsize": 3040,
7+
"weight": 12160,
78
"locktime": 0,
89
"vin": [
910
{

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

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 3155,
66
"vsize": 3155,
7+
"weight": 12620,
78
"locktime": 0,
89
"vin": [
910
{

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

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 3189,
66
"vsize": 3189,
7+
"weight": 12756,
78
"locktime": 317000,
89
"vin": [
910
{

test/util/data/txcreate1.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 2,
55
"size": 201,
66
"vsize": 201,
7+
"weight": 804,
78
"locktime": 0,
89
"vin": [
910
{

test/util/data/txcreate2.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 2,
55
"size": 19,
66
"vsize": 19,
7+
"weight": 76,
78
"locktime": 0,
89
"vin": [
910
],

test/util/data/txcreatedata1.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 176,
66
"vsize": 176,
7+
"weight": 704,
78
"locktime": 0,
89
"vin": [
910
{

test/util/data/txcreatedata2.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 2,
55
"size": 176,
66
"vsize": 176,
7+
"weight": 704,
78
"locktime": 0,
89
"vin": [
910
{

test/util/data/txcreatedata_seq0.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 2,
55
"size": 85,
66
"vsize": 85,
7+
"weight": 340,
78
"locktime": 0,
89
"vin": [
910
{

test/util/data/txcreatedata_seq1.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 126,
66
"vsize": 126,
7+
"weight": 504,
78
"locktime": 0,
89
"vin": [
910
{

test/util/data/txcreatemultisig1.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 124,
66
"vsize": 124,
7+
"weight": 496,
78
"locktime": 0,
89
"vin": [
910
],

test/util/data/txcreatemultisig2.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 42,
66
"vsize": 42,
7+
"weight": 168,
78
"locktime": 0,
89
"vin": [
910
],

test/util/data/txcreatemultisig3.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 53,
66
"vsize": 53,
7+
"weight": 212,
78
"locktime": 0,
89
"vin": [
910
],

test/util/data/txcreatemultisig4.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 42,
66
"vsize": 42,
7+
"weight": 168,
78
"locktime": 0,
89
"vin": [
910
],

test/util/data/txcreatemultisig5.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 2,
55
"size": 42,
66
"vsize": 42,
7+
"weight": 168,
78
"locktime": 0,
89
"vin": [
910
],

test/util/data/txcreateoutpubkey1.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 54,
66
"vsize": 54,
7+
"weight": 216,
78
"locktime": 0,
89
"vin": [
910
],

test/util/data/txcreateoutpubkey2.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 41,
66
"vsize": 41,
7+
"weight": 164,
78
"locktime": 0,
89
"vin": [
910
],

test/util/data/txcreateoutpubkey3.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 42,
66
"vsize": 42,
7+
"weight": 168,
78
"locktime": 0,
89
"vin": [
910
],

test/util/data/txcreatescript1.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 20,
66
"vsize": 20,
7+
"weight": 80,
78
"locktime": 0,
89
"vin": [
910
],

test/util/data/txcreatescript2.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 42,
66
"vsize": 42,
7+
"weight": 168,
78
"locktime": 0,
89
"vin": [
910
],

test/util/data/txcreatescript3.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 53,
66
"vsize": 53,
7+
"weight": 212,
78
"locktime": 0,
89
"vin": [
910
],

test/util/data/txcreatescript4.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 42,
66
"vsize": 42,
7+
"weight": 168,
78
"locktime": 0,
89
"vin": [
910
],

test/util/data/txcreatesignv1.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": 1,
55
"size": 224,
66
"vsize": 224,
7+
"weight": 896,
78
"locktime": 0,
89
"vin": [
910
{

0 commit comments

Comments
 (0)