diff --git a/chronik/chronik-indexer/src/query/util.rs b/chronik/chronik-indexer/src/query/util.rs --- a/chronik/chronik-indexer/src/query/util.rs +++ b/chronik/chronik-indexer/src/query/util.rs @@ -5,7 +5,10 @@ use std::collections::{hash_map::Entry, BTreeMap, HashMap}; use abc_rust_error::Result; -use bitcoinsuite_core::tx::{OutPoint, SpentBy, Tx, TxId}; +use bitcoinsuite_core::{ + ser::BitcoinSer, + tx::{OutPoint, SpentBy, Tx, TxId}, +}; use chronik_db::io::{DbBlock, SpentByEntry, SpentByReader, TxNum, TxReader}; use chronik_proto::proto; use thiserror::Error; @@ -81,6 +84,7 @@ is_final: avalanche.is_final_height(block.height), }), time_first_seen, + size: tx.ser_len() as u32, is_coinbase, } } diff --git a/chronik/chronik-proto/proto/chronik.proto b/chronik/chronik-proto/proto/chronik.proto --- a/chronik/chronik-proto/proto/chronik.proto +++ b/chronik/chronik-proto/proto/chronik.proto @@ -74,6 +74,8 @@ BlockMetadata block = 8; // Time this tx has first been added to the mempool, or 0 if unknown int64 time_first_seen = 9; + // Serialized size of the tx + uint32 size = 11; // Whether this tx is a coinbase tx bool is_coinbase = 12; } diff --git a/test/functional/chronik_script_unconfirmed_txs.py b/test/functional/chronik_script_unconfirmed_txs.py --- a/test/functional/chronik_script_unconfirmed_txs.py +++ b/test/functional/chronik_script_unconfirmed_txs.py @@ -142,6 +142,7 @@ ), ], lock_time=1, + size=len(tx.serialize()), time_first_seen=time_first_seen, )) diff --git a/test/functional/chronik_tx.py b/test/functional/chronik_tx.py --- a/test/functional/chronik_tx.py +++ b/test/functional/chronik_tx.py @@ -94,6 +94,7 @@ lock_time=1234567890, block=None, time_first_seen=1333333337, + size=len(tx.serialize()), is_coinbase=False, ) @@ -143,6 +144,7 @@ lock_time=12, block=None, time_first_seen=1333333338, + size=len(tx2.serialize()), is_coinbase=False, ) diff --git a/test/functional/test_framework/chronik/test_data.py b/test/functional/test_framework/chronik/test_data.py --- a/test/functional/test_framework/chronik/test_data.py +++ b/test/functional/test_framework/chronik/test_data.py @@ -33,5 +33,6 @@ timestamp=TIME_GENESIS_BLOCK, ), time_first_seen=0, + size=204, is_coinbase=True, )