-
Notifications
You must be signed in to change notification settings - Fork 100
feat: embedding well known canisters at build time #3872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 11 commits
58c293d
158ccc4
20dca9f
199dc6d
646318d
6171920
2467889
f5844ac
dd5303a
88f7cc9
870194c
c9bf270
8ee4815
f414f82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use std::{env, fs::File, io::Write, path::Path}; | ||
|
||
use itertools::Itertools; | ||
use serde_json::Value; | ||
|
||
fn define_well_known_canisters() { | ||
let well_known_canisters = serde_json::from_str::<Value>( | ||
&std::fs::read_to_string(format!( | ||
"{}/assets/canister_ids.json", | ||
env!("CARGO_MANIFEST_DIR") | ||
)) | ||
.unwrap(), | ||
) | ||
.unwrap(); | ||
let well_known_canisters = well_known_canisters.as_object().unwrap(); | ||
let well_known_canisters = well_known_canisters.iter().map(|(key, val)| { | ||
( | ||
key.as_str(), | ||
val.as_object() | ||
.unwrap() | ||
.values() | ||
.last() | ||
.unwrap() | ||
.as_str() | ||
.unwrap(), | ||
) | ||
}); | ||
|
||
let out_dir = env::var("OUT_DIR").unwrap(); | ||
let loader_path = Path::new(&out_dir).join("well_known_canisters.rs"); | ||
let mut f = File::create(loader_path).unwrap(); | ||
f.write_all( | ||
format!( | ||
" | ||
const WELL_KNOWN_CANISTERS: &[(&str, &str)] = &[ | ||
{} | ||
]; | ||
pub fn map_wellknown_canisters() -> HashMap<CanisterName, Principal> {{ | ||
WELL_KNOWN_CANISTERS.iter().map(|(key, value)| (key.to_string(), (*value).try_into().unwrap())).collect() | ||
}} | ||
", | ||
well_known_canisters | ||
.map(|(key, val)| format!("(\"{}\", \"{}\")", key, val)) | ||
.join(",\n") | ||
) | ||
.as_bytes(), | ||
) | ||
.unwrap() | ||
Comment on lines
+34
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is a global mapping of well-known canister ids, could we initialize this into a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The version of rust used by |
||
} | ||
|
||
fn main() { | ||
define_well_known_canisters(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"registry": { | ||
"local": "rwlgt-iiaaa-aaaaa-aaaaa-cai", | ||
"mainnet": "rwlgt-iiaaa-aaaaa-aaaaa-cai", | ||
"small01": "rwlgt-iiaaa-aaaaa-aaaaa-cai" | ||
}, | ||
"governance": { | ||
"local": "rrkah-fqaaa-aaaaa-aaaaq-cai", | ||
"mainnet": "rrkah-fqaaa-aaaaa-aaaaq-cai", | ||
"small01": "rrkah-fqaaa-aaaaa-aaaaq-cai" | ||
}, | ||
"ledger": { | ||
"local": "ryjl3-tyaaa-aaaaa-aaaba-cai", | ||
"mainnet": "ryjl3-tyaaa-aaaaa-aaaba-cai", | ||
"small01": "ryjl3-tyaaa-aaaaa-aaaba-cai" | ||
}, | ||
"icp-ledger-archive": { | ||
"local": "qjdve-lqaaa-aaaaa-aaaeq-cai", | ||
"mainnet": "qjdve-lqaaa-aaaaa-aaaeq-cai", | ||
"small01": "qjdve-lqaaa-aaaaa-aaaeq-cai" | ||
}, | ||
"icp-ledger-archive-1": { | ||
"local": "qsgjb-riaaa-aaaaa-aaaga-cai", | ||
"mainnet": "qsgjb-riaaa-aaaaa-aaaga-cai", | ||
"small01": "qsgjb-riaaa-aaaaa-aaaga-cai" | ||
}, | ||
"root": { | ||
"local": "r7inp-6aaaa-aaaaa-aaabq-cai", | ||
"mainnet": "r7inp-6aaaa-aaaaa-aaabq-cai", | ||
"small01": "r7inp-6aaaa-aaaaa-aaabq-cai" | ||
}, | ||
"cycles-minting": { | ||
"local": "rkp4c-7iaaa-aaaaa-aaaca-cai", | ||
"mainnet": "rkp4c-7iaaa-aaaaa-aaaca-cai", | ||
"small01": "rkp4c-7iaaa-aaaaa-aaaca-cai" | ||
}, | ||
"lifeline": { | ||
"local": "rno2w-sqaaa-aaaaa-aaacq-cai", | ||
"mainnet": "rno2w-sqaaa-aaaaa-aaacq-cai", | ||
"small01": "rno2w-sqaaa-aaaaa-aaacq-cai" | ||
}, | ||
"genesis-token": { | ||
"local": "renrk-eyaaa-aaaaa-aaada-cai", | ||
"mainnet": "renrk-eyaaa-aaaaa-aaada-cai", | ||
"small01": "renrk-eyaaa-aaaaa-aaada-cai" | ||
}, | ||
"sns-wasm": { | ||
"local": "qaa6y-5yaaa-aaaaa-aaafa-cai", | ||
"mainnet": "qaa6y-5yaaa-aaaaa-aaafa-cai", | ||
"small01": "qaa6y-5yaaa-aaaaa-aaafa-cai" | ||
}, | ||
"identity": { | ||
"local": "rdmx6-jaaaa-aaaaa-aaadq-cai", | ||
"mainnet": "rdmx6-jaaaa-aaaaa-aaadq-cai", | ||
"small01": "rdmx6-jaaaa-aaaaa-aaadq-cai" | ||
}, | ||
"nns-ui": { | ||
"local": "qoctq-giaaa-aaaaa-aaaea-cai", | ||
"mainnet": "qoctq-giaaa-aaaaa-aaaea-cai", | ||
"small01": "qoctq-giaaa-aaaaa-aaaea-cai" | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.