Skip to content

Commit

Permalink
Correct transaction size
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ayiga committed Nov 26, 2024
1 parent 4c3bab7 commit 2b2f0fb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/explorer/query_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ where
BlockQueryData<Types>: HeightIndexed,
Payload<Types>: QueryablePayload<Types>,
Header<Types>: QueryableHeader<Types> + ExplorerHeader<Types>,
<Types as NodeType>::Transaction: ExplorerTransaction,
{
type Error = TimestampConversionError;

Expand All @@ -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![],
Expand Down
4 changes: 4 additions & 0 deletions src/explorer/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
4 changes: 4 additions & 0 deletions src/testing/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2b2f0fb

Please sign in to comment.