-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Migrating sns downloader to canister calls (#451)
* migrating to canister call instead of api calls * adding back sns name
- Loading branch information
1 parent
00f2e85
commit 9f8fa09
Showing
16 changed files
with
213 additions
and
225 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::str::FromStr; | ||
|
||
use crate::IcAgentCanisterClient; | ||
use ic_agent::Agent; | ||
use ic_base_types::CanisterId; | ||
use ic_sns_wasm::pb::v1::{ListDeployedSnsesRequest, ListDeployedSnsesResponse}; | ||
|
||
const SNS_WASM_CANISTER: &str = "qaa6y-5yaaa-aaaaa-aaafa-cai"; | ||
|
||
#[derive(Clone)] | ||
pub struct SnsWasmCanister { | ||
agent: Agent, | ||
sns_wasm_canister: CanisterId, | ||
} | ||
|
||
impl From<IcAgentCanisterClient> for SnsWasmCanister { | ||
fn from(value: IcAgentCanisterClient) -> Self { | ||
Self { | ||
agent: value.agent, | ||
sns_wasm_canister: CanisterId::from_str(SNS_WASM_CANISTER).unwrap(), | ||
} | ||
} | ||
} | ||
|
||
impl SnsWasmCanister { | ||
pub fn new(agent: Agent, sns_canister_id: Option<&str>) -> Self { | ||
Self { | ||
agent, | ||
sns_wasm_canister: CanisterId::from_str(sns_canister_id.unwrap_or(SNS_WASM_CANISTER)).unwrap(), | ||
} | ||
} | ||
|
||
pub async fn list_deployed_snses(&self) -> anyhow::Result<ListDeployedSnsesResponse> { | ||
let arg = candid::encode_one(ListDeployedSnsesRequest {})?; | ||
let response = self | ||
.agent | ||
.query(&self.sns_wasm_canister.into(), "list_deployed_snses") | ||
.with_arg(arg) | ||
.call() | ||
.await?; | ||
Ok(candid::decode_one(&response)?) | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
rs/ic-observability/multiservice-discovery-shared/src/contracts/deployed_sns.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,51 @@ | ||
use std::hash::Hash; | ||
|
||
use ic_sns_wasm::pb::v1::DeployedSns; | ||
|
||
pub struct Sns { | ||
pub root_canister_id: String, | ||
pub governance_canister_id: String, | ||
pub ledger_canister_id: String, | ||
pub swap_canister_id: String, | ||
pub index_canister_id: String, | ||
pub name: String, | ||
} | ||
|
||
impl From<DeployedSns> for Sns { | ||
fn from(value: DeployedSns) -> Self { | ||
Self { | ||
governance_canister_id: match value.governance_canister_id { | ||
None => "".to_string(), | ||
Some(val) => val.to_string(), | ||
}, | ||
index_canister_id: match value.index_canister_id { | ||
None => "".to_string(), | ||
Some(val) => val.to_string(), | ||
}, | ||
ledger_canister_id: match value.ledger_canister_id { | ||
None => "".to_string(), | ||
Some(val) => val.to_string(), | ||
}, | ||
root_canister_id: match value.root_canister_id { | ||
None => "".to_string(), | ||
Some(val) => val.to_string(), | ||
}, | ||
swap_canister_id: match value.swap_canister_id { | ||
None => "".to_string(), | ||
Some(val) => val.to_string(), | ||
}, | ||
name: "".to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl Hash for Sns { | ||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) { | ||
self.root_canister_id.hash(state); | ||
self.governance_canister_id.hash(state); | ||
self.ledger_canister_id.hash(state); | ||
self.swap_canister_id.hash(state); | ||
self.index_canister_id.hash(state); | ||
self.name.hash(state); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
rs/ic-observability/multiservice-discovery-shared/src/contracts/mod.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
pub mod sns; | ||
pub mod deployed_sns; | ||
pub mod target; | ||
|
||
pub trait DataContract { | ||
|
54 changes: 0 additions & 54 deletions
54
rs/ic-observability/multiservice-discovery-shared/src/contracts/sns.rs
This file was deleted.
Oops, something went wrong.
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
22 changes: 0 additions & 22 deletions
22
rs/ic-observability/multiservice-discovery-shared/src/filters/sns_name_regex_filter.rs
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.