-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync
supported standards
from each token ledger
- Loading branch information
Showing
8 changed files
with
53 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
backend/canisters/registry/impl/src/jobs/check_for_updates_to_supported_standards.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use crate::{mutate_state, read_state}; | ||
use candid::Principal; | ||
use ic_cdk::api::call::RejectionCode; | ||
use std::time::Duration; | ||
use utils::canister_timers::run_now_then_interval; | ||
use utils::time::HOUR_IN_MS; | ||
|
||
pub fn start_job() { | ||
run_now_then_interval(Duration::from_millis(12 * HOUR_IN_MS), run); | ||
} | ||
|
||
fn run() { | ||
ic_cdk::spawn(run_async()); | ||
} | ||
|
||
async fn run_async() { | ||
let ledger_canister_ids: Vec<_> = | ||
read_state(|state| state.data.tokens.get_all().iter().map(|t| t.ledger_canister_id).collect()); | ||
|
||
for id in ledger_canister_ids { | ||
if let Ok(supported_standards) = get_supported_standards(id).await { | ||
mutate_state(|state| state.data.tokens.set_standards(id, supported_standards, state.env.now())); | ||
} | ||
} | ||
} | ||
|
||
async fn get_supported_standards(ledger_canister_id: Principal) -> Result<Vec<String>, (RejectionCode, String)> { | ||
let result = icrc_ledger_canister_c2c_client::icrc1_supported_standards(ledger_canister_id).await?; | ||
Ok(result.into_iter().map(|r| r.name).collect()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
use crate::RuntimeState; | ||
|
||
pub mod check_for_sns_updates; | ||
pub mod check_for_updates_to_supported_standards; | ||
|
||
pub(crate) fn start(_state: &RuntimeState) { | ||
check_for_sns_updates::start_job(); | ||
check_for_updates_to_supported_standards::start_job(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters