Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
lassemand committed Jun 20, 2024
1 parent 3126520 commit 08fb4b9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 44 deletions.
7 changes: 5 additions & 2 deletions notification-server/src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct Args {
db_connection: String, // Changed to String for axum, will parse later
/// Logging level of the application
#[arg(long = "log-level", default_value_t = log::LevelFilter::Info)]
log_level: log::LevelFilter,
log_level: log::LevelFilter,
}

#[derive(Deserialize)]
Expand All @@ -41,7 +41,10 @@ async fn upsert_account_device(
State(state): State<Arc<AppState>>,
Json(device_mapping): Json<DeviceMapping>,
) -> Result<impl axum::response::IntoResponse, axum::response::Response> {
info!("Upserting account {} with device id {}", account, device_mapping.device_id);
info!(
"Upserting account {} with device id {}",
account, device_mapping.device_id
);

// Example of how you might use the state
let _ = &state.db_connection;
Expand Down
84 changes: 42 additions & 42 deletions notification-server/src/bin/service.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use clap::Parser;
use concordium_rust_sdk::cis2;
use concordium_rust_sdk::cis2::Event;
use concordium_rust_sdk::types::{AccountTransactionEffects, ContractTraceElement};
use concordium_rust_sdk::types::BlockItemSummaryDetails::AccountTransaction;
use concordium_rust_sdk::v2::{Client, Endpoint};
use concordium_rust_sdk::{
cis2,
cis2::Event,
types::{
AccountTransactionEffects, BlockItemSummaryDetails::AccountTransaction,
ContractTraceElement,
},
v2::{Client, Endpoint},
};
use dotenv::dotenv;
use tonic::{
codegen::{http, tokio_stream::StreamExt},
Expand All @@ -30,31 +34,29 @@ struct Args {
}

fn get_cis2_events_addresses(effects: &AccountTransactionEffects) -> Option<Vec<String>> {
match &effects {
AccountTransactionEffects::ContractUpdateIssued { effects } => {
Some(effects.iter().flat_map(|effect| match effect {
ContractTraceElement::Updated { data } => {
data.events.iter().map(|event| {
match cis2::Event::try_from(event) {
Ok(Event::Transfer { to, .. }) => {
Some(to.to_string())
},
Ok(Event::Mint { amount, .. }) => {
Some(amount.to_string())
},
_ => None
}
}).filter(|t| Option::is_some(t)).collect()
},
_ => None,
}).collect())
}
_ => None,
}
match &effects {
AccountTransactionEffects::ContractUpdateIssued { effects } => Some(
effects
.iter()
.flat_map(|effect| match effect {
ContractTraceElement::Updated { data } => data
.events
.iter()
.map(|event| match cis2::Event::try_from(event) {
Ok(Event::Transfer { to, .. }) => Some(to.to_string()),
Ok(Event::Mint { amount, .. }) => Some(amount.to_string()),
_ => None,
})
.filter(|t| Option::is_some(t))
.collect(),
_ => None,
})
.collect(),
),
_ => None,
}
}



fn is_notification_emitting_transaction_effect(effects: &AccountTransactionEffects) -> bool {
match effects {
AccountTransactionEffects::AccountTransfer { .. }
Expand Down Expand Up @@ -96,22 +98,20 @@ async fn main() -> anyhow::Result<()> {
.response;
let addresses: Vec<String> = transactions
.filter_map(Result::ok)
.filter_map(|t| {
match t.details {
AccountTransaction(ref account_transaction) => {
if is_notification_emitting_transaction_effect(&account_transaction.effects) {
Some(
t.affected_addresses()
.into_iter()
.map(|addr| addr.to_string())
.collect::<Vec<_>>(),
)
} else {
get_cis2_events_addresses(&account_transaction.effects)
}
.filter_map(|t| match t.details {
AccountTransaction(ref account_transaction) => {
if is_notification_emitting_transaction_effect(&account_transaction.effects) {
Some(
t.affected_addresses()
.into_iter()
.map(|addr| addr.to_string())
.collect::<Vec<_>>(),
)
} else {
get_cis2_events_addresses(&account_transaction.effects)
}
_ => None,
}
_ => None,
})
.collect::<Vec<Vec<String>>>()
.await
Expand Down

0 comments on commit 08fb4b9

Please sign in to comment.