Skip to content

Commit

Permalink
Merge pull request #38 from Apocentre/chore/pr_fixes
Browse files Browse the repository at this point in the history
chore: fix pr comments
  • Loading branch information
mimoo authored Feb 14, 2024
2 parents 7d450a2 + 0a48c0d commit 2680ea3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/bob_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,15 +449,15 @@ impl BobRequest {

/// Check that the zkapp input transactions are compliant
pub async fn check_compliance(&self, compliance: Arc<Compliance>) -> Result<()> {
for zkapp_txin in &self.zkapp_tx.input {
for (index, zkapp_txin) in self.zkapp_tx.input.iter().enumerate() {
let addr = Address::from_script(
&zkapp_txin.script_sig.clone().into_boxed_script(),
get_network(),
)?;

ensure!(
!compliance.is_sanctioned(&addr).await,
"ZkApp input transaction is sanctioned"
format!("ZkApp input #{index} is sanctioned"),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/committee/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ pub async fn run_server(
info!("- starting orchestrator at address http://{address}");

let mut compliance = Compliance::new();
// Orchestrator should sync the Sanction ist before doing anything else
// Orchestrator should sync the sanction list before doing anything else
compliance.sync().await.expect("sync sanction list");

// wrap in an Arc after the first sync so it can be used in multiple request contexts
Expand Down
13 changes: 5 additions & 8 deletions src/compliance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ use std::{
use tokio::{spawn, sync::RwLock, task::JoinHandle, time::interval};
use xml::reader::{EventReader, XmlEvent};

#[derive(Default)]
pub struct Compliance {
sanctioned_addresses: Arc<RwLock<HashMap<String, bool>>>,
last_update: Arc<RwLock<i64>>,
}

impl Default for Compliance {
fn default() -> Self {
Self::new()
}
}

impl Compliance {
const BTC_ID: &'static str = "344";
const TICK_INTERVAL: u64 = 600;
const OFAC_URL: &'static str =
"https://www.treasury.gov/ofac/downloads/sanctions/1.0/sdn_advanced.xml";

Expand Down Expand Up @@ -91,7 +87,6 @@ impl Compliance {
}

let mut last_update = last_update.write().await;
*last_update = publish_date;

info!("Syncing sanction list...");
let start = Instant::now();
Expand Down Expand Up @@ -137,6 +132,8 @@ impl Compliance {
}
}

*last_update = publish_date;

let duration = start.elapsed();
info!("Sanction list synced in {:?}", duration);

Expand All @@ -149,7 +146,7 @@ impl Compliance {
let last_update = Arc::clone(&self.last_update);

spawn(async move {
let mut interval = interval(Duration::from_secs(600));
let mut interval = interval(Duration::from_secs(Compliance::TICK_INTERVAL));

loop {
interval.tick().await;
Expand Down

0 comments on commit 2680ea3

Please sign in to comment.