-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add subnet type argument when creating canisters (#2584)
Adds a new optional argument when creating canisters through dfx that allows users to choose a specific "type" of subnet that their canister can be created on. These user-facing types are different than the existing types of subnets in the registry (system,verified, application) and are mostly useful for allowing users to choose a subnet with some certain characteristics. Additionally, the ability to list available subnet types is added through a new subcommand of `dfx ledger`.
- Loading branch information
Showing
11 changed files
with
171 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Array "mo:base/Array"; | ||
import P "mo:base/Principal"; | ||
import Text "mo:base/Text"; | ||
import Prim "mo:⛔"; | ||
|
||
actor Call { | ||
type SubnetTypesToSubnetsResponse = { | ||
data: [(Text, [Principal])]; | ||
}; | ||
|
||
public query func get_subnet_types_to_subnets() : async SubnetTypesToSubnetsResponse { | ||
let type1 = "type1"; | ||
let type2 = "type2"; | ||
{ | ||
data = [ | ||
(type1, [Prim.principalOfBlob("\00")]), | ||
(type2, [Prim.principalOfBlob("\01"), Prim.principalOfBlob("\02")]), | ||
]; | ||
} | ||
}; | ||
|
||
} |
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 @@ | ||
jq '.canisters.cmc.main="main.mo"' dfx.json | sponge dfx.json |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use crate::lib::environment::Environment; | ||
use crate::lib::error::DfxResult; | ||
use crate::lib::ledger_types::{GetSubnetTypesToSubnetsResult, MAINNET_CYCLE_MINTER_CANISTER_ID}; | ||
use crate::lib::waiter::waiter_with_timeout; | ||
use crate::util::expiry_duration; | ||
|
||
use crate::lib::root_key::fetch_root_key_if_needed; | ||
|
||
use anyhow::{anyhow, Context}; | ||
use candid::{Decode, Encode, Principal}; | ||
use clap::Parser; | ||
|
||
const GET_SUBNET_TYPES_TO_SUBNETS_METHOD: &str = "get_subnet_types_to_subnets"; | ||
|
||
/// Show available subnet types in the cycles minting canister. | ||
#[derive(Parser)] | ||
pub struct ShowSubnetTypesOpts { | ||
#[clap(long)] | ||
/// Canister ID of the cycles minting canister. | ||
cycles_minting_canister_id: Option<Principal>, | ||
} | ||
|
||
pub async fn exec(env: &dyn Environment, opts: ShowSubnetTypesOpts) -> DfxResult { | ||
let agent = env | ||
.get_agent() | ||
.ok_or_else(|| anyhow!("Cannot get HTTP client from environment."))?; | ||
|
||
fetch_root_key_if_needed(env).await?; | ||
|
||
let cycles_minting_canister_id = opts | ||
.cycles_minting_canister_id | ||
.unwrap_or(MAINNET_CYCLE_MINTER_CANISTER_ID); | ||
|
||
let result = agent | ||
.update( | ||
&cycles_minting_canister_id, | ||
GET_SUBNET_TYPES_TO_SUBNETS_METHOD, | ||
) | ||
.with_arg(Encode!(&()).context("Failed to encode get_subnet_types_to_subnets arguments.")?) | ||
.call_and_wait(waiter_with_timeout(expiry_duration())) | ||
.await | ||
.context("get_subnet_types_to_subnets call failed.")?; | ||
let result = Decode!(&result, GetSubnetTypesToSubnetsResult) | ||
.context("Failed to decode get_subnet_types_to_subnets response")?; | ||
|
||
let available_subnet_types: Vec<String> = result.data.into_iter().map(|(x, _)| x).collect(); | ||
|
||
println!("{:?}", available_subnet_types); | ||
|
||
Ok(()) | ||
} |
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