Skip to content

Commit

Permalink
feat: Implement selection filter by Address (#396)
Browse files Browse the repository at this point in the history
sumit2bk authored Aug 27, 2022

Verified

This commit was signed with the committer’s verified signature.
SorsOps SorsOps
1 parent efef67f commit 4de19ee
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/filters/selection.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ use serde::Deserialize;
use serde_json::Value as JsonValue;

use crate::{
model::{Event, EventData, MetadataRecord, MetadatumRendition, MintRecord, OutputAssetRecord},
model::{Event, EventData, MetadataRecord, MetadatumRendition, MintRecord, OutputAssetRecord, TxOutputRecord},
pipelining::{new_inter_stage_channel, FilterProvider, PartialBootstrapResult, StageReceiver},
};

@@ -17,6 +17,7 @@ pub enum Predicate {
VariantNotIn(Vec<String>),
PolicyEquals(String),
AssetEquals(String),
AddressEquals(String),
MetadataLabelEquals(String),
MetadataAnySubLabelEquals(String),
Not(Box<Predicate>),
@@ -47,6 +48,16 @@ fn policy_matches(event: &Event, policy: &str) -> bool {
}
}

#[inline]
fn address_matches(event: &Event, address: &str) -> bool {
match &event.data {
EventData::TxOutput(TxOutputRecord { address: x, .. }) => {
relaxed_str_matches(x, address)
},
_ => false,
}
}

#[inline]
fn asset_matches(event: &Event, asset: &str) -> bool {
match &event.data {
@@ -84,6 +95,7 @@ impl Predicate {
Predicate::VariantIn(x) => variant_in_matches(event, x),
Predicate::VariantNotIn(x) => !variant_in_matches(event, x),
Predicate::PolicyEquals(x) => policy_matches(event, x),
Predicate::AddressEquals(x) => address_matches(event, x),
Predicate::AssetEquals(x) => asset_matches(event, x),
Predicate::MetadataLabelEquals(x) => metadata_label_matches(event, x),
Predicate::MetadataAnySubLabelEquals(x) => metadata_any_sub_label_matches(event, x),

0 comments on commit 4de19ee

Please sign in to comment.