Skip to content

Commit

Permalink
feat: Add details to 'transaction' event (#24)
Browse files Browse the repository at this point in the history
* feat: Add full transaction detail as part of the event payload
* feat: Allow opt-in config for transaction details
  • Loading branch information
scarmuega authored Dec 30, 2021
1 parent 350bcad commit 93a6670
Show file tree
Hide file tree
Showing 12 changed files with 366 additions and 221 deletions.
70 changes: 9 additions & 61 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ log = "0.4.14"
env_logger = "0.9.0"
crossterm = "0.20"
merge = "0.1.0"
config = "0.11.0"
config = { version = "0.11.0", default-features = false, features = ["toml"] }
serde = "1.0.130"
serde_json = "1.0.72"
serde_derive = "1.0.130"
Expand Down
3 changes: 3 additions & 0 deletions src/bin/oura/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::str::FromStr;
use clap::{value_t, ArgMatches};
use oura::{
framework::*,
mapping::MapperConfig,
sources::common::{AddressArg, BearerKind, MagicArg, PointArg},
};

Expand Down Expand Up @@ -72,12 +73,14 @@ pub fn run(args: &ArgMatches) -> Result<(), Error> {
address: AddressArg(bearer, socket),
magic,
well_known: None,
mapper: MapperConfig::default(),
since,
}),
PeerMode::AsClient => WatchSource::N2C(N2CConfig {
address: AddressArg(bearer, socket),
magic,
well_known: None,
mapper: MapperConfig::default(),
since,
}),
};
Expand Down
11 changes: 7 additions & 4 deletions src/filters/fingerpint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use std::{
use log::{debug, warn};
use serde_derive::Deserialize;

use crate::framework::{Error, Event, EventData, FilterConfig, PartialBootstrapResult};
use crate::framework::{
Error, Event, EventData, FilterConfig, MetadataRecord, MintRecord, OutputAssetRecord,
PartialBootstrapResult,
};

struct FingerprintBuilder {
seed: u32,
Expand Down Expand Up @@ -107,20 +110,20 @@ fn build_fingerprint(event: &Event, seed: u32) -> Result<String, Error> {
.with_prefix("utxo")
.append_optional(&event.context.tx_hash)?
.append_optional_to_string(&event.context.output_idx)?,
EventData::OutputAsset { policy, asset, .. } => b
EventData::OutputAsset(OutputAssetRecord { policy, asset, .. }) => b
.with_slot(&event.context.slot)
.with_prefix("asst")
.append_optional(&event.context.tx_hash)?
.append_optional_to_string(&event.context.output_idx)?
.append_slice(policy)?
.append_slice(asset)?,
EventData::Metadata { key, subkey, .. } => b
EventData::Metadata(MetadataRecord { key, subkey, .. }) => b
.with_slot(&event.context.slot)
.with_prefix("meta")
.append_optional(&event.context.tx_hash)?
.append_slice(key)?
.append_slice(subkey.as_deref().unwrap_or_default())?,
EventData::Mint { policy, asset, .. } => b
EventData::Mint(MintRecord { policy, asset, .. }) => b
.with_slot(&event.context.slot)
.with_prefix("mint")
.append_optional(&event.context.tx_hash)?
Expand Down
23 changes: 16 additions & 7 deletions src/filters/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use std::{sync::mpsc::Receiver, thread};

use serde_derive::Deserialize;

use crate::framework::{Event, EventData, FilterConfig, PartialBootstrapResult};
use crate::framework::{
Event, EventData, FilterConfig, MetadataRecord, MintRecord, OutputAssetRecord,
PartialBootstrapResult,
};

#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(tag = "predicate", content = "argument", rename_all = "snake_case")]
Expand Down Expand Up @@ -35,33 +38,39 @@ fn variant_in_matches(event: &Event, variants: &Vec<String>) -> bool {
#[inline]
fn policy_matches(event: &Event, policy: &str) -> bool {
match &event.data {
EventData::OutputAsset { policy: x, .. } => relaxed_str_matches(x, &policy),
EventData::Mint { policy: x, .. } => relaxed_str_matches(x, &policy),
EventData::OutputAsset(OutputAssetRecord { policy: x, .. }) => {
relaxed_str_matches(x, &policy)
}
EventData::Mint(MintRecord { policy: x, .. }) => relaxed_str_matches(x, &policy),
_ => false,
}
}

#[inline]
fn asset_matches(event: &Event, asset: &str) -> bool {
match &event.data {
EventData::OutputAsset { asset: x, .. } => relaxed_str_matches(x, &asset),
EventData::Mint { asset: x, .. } => relaxed_str_matches(x, &asset),
EventData::OutputAsset(OutputAssetRecord { asset: x, .. }) => {
relaxed_str_matches(x, &asset)
}
EventData::Mint(MintRecord { asset: x, .. }) => relaxed_str_matches(x, &asset),
_ => false,
}
}

#[inline]
fn metadata_key_matches(event: &Event, key: &str) -> bool {
match &event.data {
EventData::Metadata { key: x, .. } => relaxed_str_matches(x, &key),
EventData::Metadata(MetadataRecord { key: x, .. }) => relaxed_str_matches(x, &key),
_ => false,
}
}

#[inline]
fn metadata_subkey_matches(event: &Event, subkey: &str) -> bool {
match &event.data {
EventData::Metadata { subkey: Some(x), .. } => relaxed_str_matches(x, &subkey),
EventData::Metadata(MetadataRecord {
subkey: Some(x), ..
}) => relaxed_str_matches(x, &subkey),
_ => false,
}
}
Expand Down
Loading

0 comments on commit 93a6670

Please sign in to comment.