From 2b2f0fbfc7ab0de8baeff5c3f16915c4adacf36f Mon Sep 17 00:00:00 2001 From: Theodore Schnepper Date: Tue, 26 Nov 2024 11:44:27 -0700 Subject: [PATCH] Correct transaction size The transaction size currently returns the size of the overall block instead of the individual transaction. To address this effectively, the `ExplorerTransaction` `trait` has been updated to require the ability to specify the payload size of the individual transaction. --- src/explorer/query_data.rs | 3 ++- src/explorer/traits.rs | 4 ++++ src/testing/mocks.rs | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/explorer/query_data.rs b/src/explorer/query_data.rs index 2ac8551f7..9b1a3eef7 100644 --- a/src/explorer/query_data.rs +++ b/src/explorer/query_data.rs @@ -380,6 +380,7 @@ where BlockQueryData: HeightIndexed, Payload: QueryablePayload, Header: QueryableHeader + ExplorerHeader, + ::Transaction: ExplorerTransaction, { type Error = TimestampConversionError; @@ -399,7 +400,7 @@ where block_confirmed: true, offset: offset as u64, num_transactions: block.num_transactions, - size: block.size, + size: transaction.payload_size(), time: Timestamp(time::OffsetDateTime::from_unix_timestamp(seconds)?), sequencing_fees: vec![], fee_details: vec![], diff --git a/src/explorer/traits.rs b/src/explorer/traits.rs index a6d7c489a..7b44e9a0a 100644 --- a/src/explorer/traits.rs +++ b/src/explorer/traits.rs @@ -66,5 +66,9 @@ pub trait ExplorerTransaction { /// a representation of it that adheres to the trait restrictions specified. type NamespaceId: Clone + Debug + Serialize + DeserializeOwned + Send + Sync + PartialEq + Eq; + /// namespace_id returns the namespace id of the individual transaction. fn namespace_id(&self) -> Self::NamespaceId; + + /// payload_size returns the size of the payload of the transaction. + fn payload_size(&self) -> u64; } diff --git a/src/testing/mocks.rs b/src/testing/mocks.rs index a5e51559e..5c271ca1f 100644 --- a/src/testing/mocks.rs +++ b/src/testing/mocks.rs @@ -89,6 +89,10 @@ impl ExplorerTransaction for MockTransaction { fn namespace_id(&self) -> Self::NamespaceId { 0 } + + fn payload_size(&self) -> u64 { + self.bytes().len() as u64 + } } impl HeightIndexed for MockHeader {