Function wasm_deploy::commands::instantiate
source · pub async fn instantiate(
contracts: &[impl Contract]
) -> Result<Status, DeployError>Examples found in repository?
src/commands.rs (line 53)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
pub async fn execute_args<C, S>(cli: &Cli<C, S>) -> Result<Status, DeployError>
where
C: Contract,
S: Subcommand,
{
match &cli.command {
Commands::Update {} => update::<C, S>(),
Commands::Init {} => init().await,
Commands::Build { contracts } => build(contracts, &cli.cargo_args),
Commands::Chain { add, delete } => chain(add, delete),
Commands::Key { add, delete } => key(add, delete).await,
Commands::Contract { add, delete } => contract(add, delete),
Commands::Deploy { contracts, no_build } => deploy(contracts, no_build, &cli.cargo_args).await,
Commands::Env { add, delete, select } => execute_env(add, delete, select),
Commands::Schema { contracts } => schemas(contracts),
Commands::StoreCode { contracts } => store_code(contracts).await,
Commands::Instantiate { contracts } => instantiate(contracts).await,
Commands::Migrate { contracts } => migrate(contracts, &cli.cargo_args).await,
Commands::Execute { contract } => execute::<C>(contract).await,
Commands::Cw20Send { contract } => cw20_send::<C>(contract).await,
Commands::Cw20Transfer {} => cw20_transfer().await,
Commands::ExecutePayload { contract, payload } => custom_execute(contract, payload).await,
Commands::SetConfig { contracts } => set_config(contracts).await,
Commands::Query { contract } => query::<C>(contract).await,
Commands::SetUp { contracts } => set_up(contracts).await,
Commands::CustomCommand { .. } => Ok(Status::Continue),
}
}
pub async fn init() -> DeployResult<Status> {
info!("Initializing deploy");
let mut config = Config::init()?;
config.add_key().await?;
config.add_chain()?;
config.add_env()?;
config.save()?;
Ok(Status::Quit)
}
pub fn chain(add: &bool, delete: &bool) -> Result<Status, DeployError> {
let mut config = Config::load()?;
if *add {
config.add_chain()?;
} else if *delete {
let all_chains = &mut config.chains;
let chains_to_remove = MultiSelect::new(
"Select which chains to delete",
all_chains.iter().map(|x| x.chain_id.clone()).collect::<Vec<_>>(),
)
.prompt()?;
for chain in chains_to_remove {
all_chains.retain(|x| x.chain_id != chain);
}
}
config.save()?;
Ok(Status::Quit)
}
pub async fn key(add: &bool, delete: &bool) -> Result<Status, DeployError> {
let mut config = Config::load()?;
if *add {
config.add_key().await?;
} else if *delete {
let all_keys = &mut config.keys;
let keys_to_remove = MultiSelect::new(
"Select which keys to delete",
all_keys.iter().map(|x| x.name.clone()).collect::<Vec<_>>(),
)
.prompt()?;
for key in keys_to_remove {
all_keys.retain(|x| x.name != key);
}
}
config.save()?;
Ok(Status::Quit)
}
pub fn contract(add: &bool, delete: &bool) -> Result<Status, DeployError> {
let mut config = Config::load()?;
if *add {
config.add_contract()?;
} else if *delete {
let env = config.get_active_env_mut()?;
let all_contracts = &mut env.contracts;
let contracts = MultiSelect::new("Select which contracts to delete", all_contracts.clone()).prompt()?;
for contract in contracts {
all_contracts.retain(|x| x != &contract);
}
}
config.save()?;
Ok(Status::Quit)
}
pub fn execute_env(add: &bool, delete: &bool, select: &bool) -> Result<Status, DeployError> {
let mut config = Config::load()?;
if *add {
config.add_env()?;
} else if *delete {
let envs = MultiSelect::new("Select which envs to delete", config.envs.clone()).prompt()?;
for env in envs {
config.envs.retain(|x| x != &env);
}
let env = Select::new("Select which env to activate", config.envs.clone()).prompt()?;
config.envs.iter_mut().for_each(|x| x.is_active = x == &env);
} else if *select {
let env = Select::new("Select which env to activate", config.envs.clone()).prompt()?;
config.envs.iter_mut().for_each(|x| x.is_active = x == &env);
}
config.save()?;
Ok(Status::Quit)
}
pub async fn deploy(
contracts: &Vec<impl Contract>, no_build: &bool, cargo_args: &Vec<String>,
) -> Result<Status, DeployError> {
if !no_build {
build(contracts, cargo_args)?;
}
store_code(contracts).await?;
instantiate(contracts).await?;
set_config(contracts).await?;
set_up(contracts).await?;
Ok(Status::Continue)
}