Skip to content

Commit

Permalink
refactor: remove nested option on TransactionEventFilter::block_height
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed May 3, 2024
1 parent 30841b0 commit ba46f7d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
Binary file modified configs/swarm/executor.wasm
Binary file not shown.
34 changes: 20 additions & 14 deletions data_model/src/events/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ mod model {
)]
#[ffi_type]
pub struct TransactionEvent {
#[getset(get = "pub")]
#[getset(get_copy = "pub")]
pub hash: HashOf<SignedTransaction>,
#[getset(get_copy = "pub")]
pub block_height: Option<u64>,
Expand Down Expand Up @@ -182,7 +182,6 @@ mod model {
pub struct BlockEventFilter {
#[getset(get_copy = "pub")]
pub height: Option<u64>,
#[getset(get = "pub")]
pub status: Option<BlockStatus>,
}

Expand All @@ -194,6 +193,7 @@ mod model {
PartialOrd,
Ord,
Default,
CopyGetters,
Getters,
Decode,
Encode,
Expand All @@ -203,10 +203,10 @@ mod model {
)]
#[ffi_type]
pub struct TransactionEventFilter {
#[getset(get = "pub")]
#[getset(get_copy = "pub")]
pub hash: Option<HashOf<SignedTransaction>>,
pub block_height: Option<Option<u64>>,
#[getset(get = "pub")]
#[getset(get_copy = "pub")]
pub block_height: Option<u64>,
pub status: Option<TransactionStatus>,
}
}
Expand Down Expand Up @@ -234,6 +234,11 @@ impl BlockEventFilter {
self.status = Some(status);
self
}

/// Block status
pub fn status(&self) -> Option<&BlockStatus> {
self.status.as_ref()
}
}

impl TransactionEventFilter {
Expand All @@ -249,7 +254,7 @@ impl TransactionEventFilter {

/// Match only transactions with the given block height
#[must_use]
pub fn for_block_height(mut self, block_height: Option<u64>) -> Self {
pub fn for_block_height(mut self, block_height: u64) -> Self {
self.block_height = Some(block_height);
self
}
Expand All @@ -268,10 +273,9 @@ impl TransactionEventFilter {
self
}

/// Block height
// TODO: Derive with getset
pub fn block_height(&self) -> Option<Option<u64>> {
self.block_height
/// Transaction status
pub fn status(&self) -> Option<&TransactionStatus> {
self.status.as_ref()
}
}

Expand Down Expand Up @@ -314,10 +318,12 @@ impl super::EventFilter for PipelineEventFilterBox {
transaction_filter.hash.as_ref(),
&transaction_event.hash,
),
TransactionEventFilter::field_matches(
transaction_filter.block_height.as_ref(),
&transaction_event.block_height,
),
transaction_event.block_height.map_or(true, |block_height| {
TransactionEventFilter::field_matches(
transaction_filter.block_height.as_ref(),
&block_height,
)
}),
TransactionEventFilter::field_matches(
transaction_filter.status.as_ref(),
&transaction_event.status,
Expand Down
5 changes: 1 addition & 4 deletions docs/source/references/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2497,9 +2497,6 @@
"Option<NonZero<u64>>": {
"Option": "NonZero<u64>"
},
"Option<Option<u64>>": {
"Option": "Option<u64>"
},
"Option<ParameterId>": {
"Option": "ParameterId"
},
Expand Down Expand Up @@ -3856,7 +3853,7 @@
},
{
"name": "block_height",
"type": "Option<Option<u64>>"
"type": "Option<u64>"
},
{
"name": "status",
Expand Down

0 comments on commit ba46f7d

Please sign in to comment.