Struct wasm_deploy::file::Config

source ·
pub struct Config {
    pub shell_completion_dir: Option<PathBuf>,
    pub chains: Vec<ChainConfig>,
    pub envs: Vec<Env>,
    pub keys: Vec<SigningKey>,
}

Fields§

§shell_completion_dir: Option<PathBuf>§chains: Vec<ChainConfig>§envs: Vec<Env>§keys: Vec<SigningKey>

Implementations§

Examples found in repository?
src/commands.rs (line 68)
66
67
68
69
70
71
72
73
74
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)
}
Examples found in repository?
src/commands.rs (line 77)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
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)
}

pub fn update<C, S>() -> Result<Status, DeployError>
where
    C: Contract,
    S: Subcommand,
{
    Command::new("mv").arg("./target/debug/deploy").arg("./target/debug/deploy.old").spawn()?.wait()?;

    Command::new("cargo").arg("build").current_dir("./deployment").spawn()?.wait()?.exit_ok()?;

    generate_completions::<C, S>()?;

    Ok(Status::Quit)
}

fn generate_completions<C, S>() -> Result<(), DeployError>
where
    C: Contract,
    S: Subcommand,
{
    let shell_completion_dir = match get_shell_completion_dir()? {
        Some(shell_completion_dir) => shell_completion_dir,
        None => return Ok(()),
    };
    let string = env::var_os("SHELL").unwrap().into_string().unwrap();
    let (_, last_word) = string.rsplit_once('/').unwrap();
    let mut cmd = Cli::<C, S>::command();

    match last_word {
        "zsh" => {
            println!("Generating shell completion scripts for zsh");
            println!("Run source ~/.zshrc to update your completion scripts");

            let generated_file = generate_to(
                Zsh,
                &mut cmd,            // We need to specify what generator to use
                "deploy",            // We need to specify the bin name manually
                BUILD_DIR.as_path(), // We need to specify where to write to
            )?;

            let source_path = BUILD_DIR.join(generated_file.file_name().unwrap());
            let target_path = shell_completion_dir.join(generated_file.file_name().unwrap());
            Command::new("rm").arg(target_path.clone()).spawn()?.wait().ok();

            if Command::new("cp").arg(source_path).arg(target_path).spawn()?.wait()?.exit_ok().is_err() {
                println!("could not find {}", shell_completion_dir.to_str().unwrap());
            }
        }
        "bash" => {
            println!("generating shell completion scripts for bash");
            let generated_file = generate_to(
                Bash,
                &mut cmd,            // We need to specify what generator to use
                "deploy",            // We need to specify the bin name manually
                BUILD_DIR.as_path(), // We need to specify where to write to
            )?;

            let source_path = BUILD_DIR.join(generated_file.file_name().unwrap());
            let target_path = shell_completion_dir.join(generated_file.file_name().unwrap());

            if Command::new("cp").arg(source_path).arg(target_path).spawn()?.wait()?.exit_ok().is_err() {
                println!("could not find {}", shell_completion_dir.to_str().unwrap());
            }
        }
        _ => {
            return Err(DeployError::UnsupportedShell {});
        }
    }

    Ok(())
}

pub fn build(contracts: &Vec<impl Contract>, cargo_args: &Vec<String>) -> Result<Status, DeployError> {
    // Build contracts
    for contract in contracts {
        Command::new("cargo")
            .env("RUSTFLAGS", "-C link-arg=-s")
            .arg("build")
            .arg("--release")
            .arg("--lib")
            .arg("--target=wasm32-unknown-unknown")
            .args(cargo_args)
            .current_dir(format!("./contracts/{}", contract.name()))
            .spawn()?
            .wait()?
            .exit_ok()?;
    }

    Command::new("mkdir").arg("-p").arg("artifacts").spawn()?.wait()?;

    optimize(contracts)?;
    set_execute_permissions(contracts)?;

    Ok(Status::Quit)
}

pub fn schemas(contracts: &Vec<impl Contract>) -> Result<Status, DeployError> {
    // Generate schemas
    for contract in contracts {
        Command::new("cargo")
            .arg("schema")
            .current_dir(format!("./contracts/{}", contract.name()))
            .spawn()?
            .wait()?
            .exit_ok()?;
    }

    #[cfg(wasm_cli)]
    // Import schemas
    for contract in contracts {
        wasm_cli_import_schemas(&contract.name())?;
    }

    Ok(Status::Quit)
}

pub fn optimize(contracts: &Vec<impl Contract>) -> Result<Status, DeployError> {
    // Optimize contracts
    let mut handles = vec![];
    for contract in contracts {
        let name = contract.name();
        println!("Optimizing {name} contract");
        handles.push(
            Command::new("wasm-opt")
                .arg("-Os")
                .arg("-o")
                .arg(format!("artifacts/{name}.wasm"))
                .arg(format!("target/wasm32-unknown-unknown/release/{name}.wasm"))
                .spawn()?,
        );
    }
    handles.iter_mut().for_each(|x| {
        x.wait().unwrap();
    });
    Ok(Status::Quit)
}

pub fn set_execute_permissions(contracts: &Vec<impl Contract>) -> Result<Status, DeployError> {
    // change mod
    for contract in contracts {
        let name = contract.name();
        Command::new("chmod").arg("+x").arg(format!("artifacts/{name}.wasm"));
    }
    Ok(Status::Quit)
}

pub async fn store_code(contracts: &[impl Contract]) -> Result<Status, DeployError> {
    let chunks = contracts.chunks(2);
    for chunk in chunks {
        msg_contract(chunk, DeploymentStage::StoreCode).await?;
    }
    Ok(Status::Quit)
}

pub async fn instantiate(contracts: &[impl Contract]) -> Result<Status, DeployError> {
    msg_contract(contracts, DeploymentStage::Instantiate).await?;
    Ok(Status::Quit)
}

pub async fn migrate(contracts: &Vec<impl Contract>, cargo_args: &Vec<String>) -> Result<Status, DeployError> {
    build(contracts, cargo_args)?;
    store_code(contracts).await?;
    msg_contract(contracts, DeploymentStage::Migrate).await?;
    Ok(Status::Quit)
}

pub async fn set_config(contracts: &[impl Contract]) -> Result<Status, DeployError> {
    msg_contract(contracts, DeploymentStage::SetConfig).await?;
    Ok(Status::Quit)
}

pub async fn set_up(contracts: &[impl Contract]) -> Result<Status, DeployError> {
    msg_contract(contracts, DeploymentStage::SetUp).await?;
    Ok(Status::Quit)
}

pub async fn execute<C: Contract>(contract: &impl Contract) -> Result<Status, DeployError> {
    let e = C::ExecuteMsg::parse(contract)?; //parse(contract);
    crate::contract::execute(&e).await?;
    Ok(Status::Quit)
}

pub async fn cw20_send<C: Contract>(contract: &impl Contract) -> Result<Status, DeployError> {
    let h = C::Cw20HookMsg::parse(contract)?; //parse(contract);
    crate::contract::cw20_send(&h).await?;
    Ok(Status::Quit)
}

pub async fn cw20_transfer() -> Result<Status, DeployError> {
    crate::contract::cw20_transfer().await?;
    Ok(Status::Quit)
}

pub async fn custom_execute<C: Contract>(contract: &C, string: &str) -> Result<Status, DeployError> {
    println!("Executing {}", contract.name());
    let mut config = Config::load()?;
    let value: serde_json::Value = serde_json::from_str(string)?;
    let color = to_colored_json_auto(&value)?;
    println!("{color}");
    let msg = serde_json::to_vec(&value)?;
    let key = config.get_active_key().await?;

    let chain_info = config.get_active_chain_info()?;
    let client = CosmosgRPC::new(chain_info.grpc_endpoint.clone().unwrap());
    let cosm_tome = CosmTome::new(chain_info, client);
    let contract_addr = config.get_contract_addr_mut(&contract.to_string())?.clone();
    let funds = Vec::<Coin>::parse_to_obj()?;
    let tx_options = TxOptions { timeout_height: None, fee: None, memo: "wasm_deploy".into() };
    let req = ExecRequest { msg, funds, address: Address::from_str(&contract_addr).unwrap() };

    let response = cosm_tome.wasm_execute(req, &key, &tx_options).await?;

    println!(
        "gas wanted: {}, gas used: {}",
        response.res.gas_wanted.to_string().green(),
        response.res.gas_used.to_string().green()
    );
    println!("tx hash: {}", response.res.tx_hash.purple());

    Ok(Status::Quit)
}
More examples
Hide additional examples
src/file.rs (line 258)
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
pub fn get_shell_completion_dir() -> Result<Option<PathBuf>, DeployError> {
    let mut config = Config::load()?;
    match config.shell_completion_dir {
        Some(shell_completion_path) => Ok(Some(shell_completion_path)),
        None => {
            let ans = Confirm::new("Shell completion directory not found.\nWould you like to add one?")
                .with_default(true)
                .prompt()?;
            match ans {
                true => {
                    let string = CustomType::<String>::new("Enter you shell completion script directory.").prompt()?;
                    let path = PathBuf::from(string);
                    match path.is_dir() {
                        true => {
                            config.shell_completion_dir = Some(path.clone());
                            config.save()?;
                            Ok(Some(path))
                        }
                        false => Err(DeployError::InvalidDir),
                    }
                }
                false => Ok(None),
            }
        }
    }
}
src/contract.rs (line 47)
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
pub async fn execute(contract: &impl Execute) -> Result<(), DeployError> {
    println!("Executing");
    let mut config = Config::load()?;
    let mut msg = contract.execute_msg()?;
    replace_strings(&mut msg, &config.get_active_env()?.contracts)?;
    let key = config.get_active_key().await?;
    let chain_info = config.get_active_chain_info()?;
    let client = CosmosgRPC::new(chain_info.grpc_endpoint.clone().unwrap());
    let cosm_tome = CosmTome::new(chain_info, client);
    let contract_addr = config.get_contract_addr_mut(&contract.to_string())?.clone();
    let funds = Vec::<Coin>::parse_to_obj()?;
    let tx_options = TxOptions { timeout_height: None, fee: None, memo: "wasm_deploy".into() };
    let req = ExecRequest { msg, funds, address: Address::from_str(&contract_addr).unwrap() };
    let response = cosm_tome.wasm_execute(req, &key, &tx_options).await?;

    println!(
        "gas wanted: {}, gas used: {}",
        response.res.gas_wanted.to_string().green(),
        response.res.gas_used.to_string().green()
    );
    println!("tx hash: {}", response.res.tx_hash.purple());

    Ok(())
}

pub trait Query: Serialize + DeserializeOwned + Display + Debug {
    fn query_msg(&self) -> Result<Value, DeployError>;
    fn parse(contract: &impl Contract) -> DeployResult<Self>;
}

pub async fn query(contract: &impl Query) -> Result<(), DeployError> {
    println!("Querying");
    let mut config = Config::load()?;
    let mut msg = contract.query_msg()?;
    replace_strings(&mut msg, &config.get_active_env()?.contracts)?;
    let chain_info = config.get_active_chain_info()?;
    let addr = config.get_contract_addr_mut(&contract.to_string())?;
    let client = CosmosgRPC::new(chain_info.grpc_endpoint.clone().unwrap());
    let cosm_tome = CosmTome::new(chain_info, client);
    let response = cosm_tome.wasm_query(Address::from_str(addr).unwrap(), &msg).await?;

    let string = String::from_utf8(response.res.data.unwrap()).unwrap();
    let value: serde_json::Value = serde_json::from_str(string.as_str()).unwrap();
    let color = to_colored_json_auto(&value)?;
    println!("{color}");

    Ok(())
}

pub trait Cw20Hook: Serialize + DeserializeOwned + Display + Debug {
    fn cw20_hook_msg(&self) -> Result<Value, DeployError>;
    fn parse(contract: &impl Contract) -> DeployResult<Self>;
}

pub async fn cw20_send(contract: &impl Cw20Hook) -> Result<(), DeployError> {
    println!("Executing cw20 send");
    let mut config = Config::load()?;
    let key = config.get_active_key().await?;

    let hook_msg = contract.cw20_hook_msg()?;
    let contract_addr = config.get_contract_addr_mut(&contract.to_string())?.clone();
    let cw20_contract_addr = Text::new("Cw20 Contract Address?").with_help_message("string").prompt()?;
    let amount = CustomType::<u64>::new("Amount of tokens to send?").with_help_message("int").prompt()?;
    let msg = Cw20ExecuteMsg::Send {
        contract: contract_addr,
        amount:   amount.into(),
        msg:      serde_json::to_vec(&hook_msg)?.into(),
    };
    let chain_info = config.get_active_chain_info()?;
    let client = CosmosgRPC::new(chain_info.grpc_endpoint.clone().unwrap());
    let cosm_tome = CosmTome::new(chain_info, client);
    let funds = Vec::<Coin>::parse_to_obj()?;
    let req = ExecRequest { msg, funds, address: Address::from_str(&cw20_contract_addr).unwrap() };
    let tx_options = TxOptions { timeout_height: None, fee: None, memo: "wasm_deploy".into() };
    let response = cosm_tome.wasm_execute(req, &key, &tx_options).await?;
    println!(
        "gas wanted: {}, gas used: {}",
        response.res.gas_wanted.to_string().green(),
        response.res.gas_used.to_string().green()
    );
    println!("tx hash: {}", response.res.tx_hash.purple());

    Ok(())
}

pub async fn cw20_transfer() -> Result<(), DeployError> {
    println!("Executing cw20 transfer");
    let mut config = Config::load()?;
    let key = config.get_active_key().await?;

    let cw20_contract_addr = Text::new("Cw20 Contract Address?").with_help_message("string").prompt()?;
    let msg = Cw20ExecuteMsg::parse_to_obj()?;
    let chain_info = config.get_active_chain_info()?;
    let client = CosmosgRPC::new(chain_info.grpc_endpoint.clone().unwrap());
    let cosm_tome = CosmTome::new(chain_info, client);
    let tx_options = TxOptions { timeout_height: None, fee: None, memo: "wasm_deploy".into() };
    let req = ExecRequest { msg, funds: vec![], address: Address::from_str(&cw20_contract_addr).unwrap() };
    let response = cosm_tome.wasm_execute(req, &key, &tx_options).await?;

    println!(
        "gas wanted: {}, gas used: {}",
        response.res.gas_wanted.to_string().green(),
        response.res.gas_used.to_string().green()
    );
    println!("tx hash: {}", response.res.tx_hash.purple());

    Ok(())
}
src/wasm_msg.rs (line 29)
28
29
30
31
32
33
34
35
36
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
pub async fn msg_contract(contracts: &[impl Contract], msg_type: DeploymentStage) -> DeployResult<()> {
    let mut config = Config::load()?;
    let chain_info = config.get_active_chain_info()?;
    let key = config.get_active_key().await?;
    let client = CosmosgRPC::new(chain_info.grpc_endpoint.clone().unwrap());
    let cosm_tome = CosmTome::new(chain_info, client);
    let tx_options = TxOptions { timeout_height: None, fee: None, memo: "wasm_deploy".into() };

    let response: Option<ChainTxResponse> = match msg_type {
        DeploymentStage::StoreCode => {
            let mut reqs = vec![];
            for contract in contracts {
                println!("Storing code for {}", contract.name());
                let path = format!("./artifacts/{}.wasm", contract.name());
                let wasm_data = std::fs::read(path)?;
                reqs.push(StoreCodeRequest { wasm_data, instantiate_perms: None });
            }
            let response = cosm_tome.wasm_store_batch(reqs, &key, &tx_options).await?;

            for (i, contract) in contracts.iter().enumerate() {
                match config.get_contract(&contract.to_string()) {
                    Ok(contract_info) => contract_info.code_id = Some(response.code_ids[i]),
                    Err(_) => {
                        config.add_contract_from(ContractInfo {
                            name:    contract.name(),
                            addr:    None,
                            code_id: Some(response.code_ids[i]),
                        })?;
                    }
                }
            }
            config.save()?;
            Some(response.res)
        }
        DeploymentStage::Instantiate => {
            let mut reqs = vec![];
            let tx_options =
                TxOptions { timeout_height: None, fee: None, memo: "wasm_deploy".into() };
            for contract in contracts {
                println!("Instantiating {}", contract.name());
                let mut msg = contract.instantiate_msg()?;
                replace_strings(&mut msg, &config.get_active_env()?.contracts)?;
                let contract_info = config.get_contract(&contract.to_string())?;
                let code_id = contract_info.code_id.ok_or(DeployError::CodeIdNotFound)?;
                reqs.push(InstantiateRequest {
                    code_id,
                    msg,
                    label: contract.name(),
                    admin: Some(Address::from_str(&contract.admin()).unwrap()),
                    funds: vec![],
                });
                for mut external in contract.external_instantiate_msgs()? {
                    println!("Instantiating {}", external.name);
                    replace_strings(&mut external.msg, &config.get_active_env()?.contracts)?;
                    reqs.push(InstantiateRequest {
                        code_id: external.code_id,
                        msg:     external.msg,
                        label:   external.name.clone(),
                        admin:   Some(Address::from_str(&contract.admin()).unwrap()),
                        funds:   vec![],
                    });
                }
            }
            let response = cosm_tome.wasm_instantiate_batch(reqs, &key, &tx_options).await?;
            let mut index = 0;
            for contract in contracts {
                let contract_info = config.get_contract(&contract.to_string())?;
                contract_info.addr = Some(response.addresses[index].to_string());
                index += 1;
                for external in contract.external_instantiate_msgs()? {
                    config.add_contract_from(ContractInfo {
                        name:    external.name,
                        addr:    Some(response.addresses[index].to_string()),
                        code_id: Some(external.code_id),
                    })?;
                    index += 1;
                }
            }
            config.save()?;
            Some(response.res)
        }
        DeploymentStage::SetConfig => {
            let mut reqs = vec![];
            for contract in contracts {
                println!("Setting config for {}", contract.name());
                let Some(mut msg) = contract.config_msg()? else { return Ok(()) };
                replace_strings(&mut msg, &config.get_active_env()?.contracts)?;
                let contract_addr = config.get_contract_addr_mut(&contract.to_string())?.clone();
                reqs.push(ExecRequest { msg, funds: vec![], address: Address::from_str(&contract_addr).unwrap() });
            }
            let response = cosm_tome.wasm_execute_batch(reqs, &key, &tx_options).await?;
            Some(response.res)
        }
        DeploymentStage::SetUp => {
            let mut reqs = vec![];
            for contract in contracts {
                println!("Executing Set Up for {}", contract.name());
                for mut msg in contract.set_up_msgs()? {
                    replace_strings(&mut msg, &config.get_active_env()?.contracts)?;
                    let contract_addr = config.get_contract_addr_mut(&contract.to_string())?.clone();
                    reqs.push(ExecRequest { msg, funds: vec![], address: Address::from_str(&contract_addr).unwrap() });
                }
            }
            let response = cosm_tome.wasm_execute_batch(reqs, &key, &tx_options).await?;
            Some(response.res)
        }
        DeploymentStage::Migrate => {
            let mut reqs = vec![];
            for contract in contracts {
                if let Some(mut msg) = contract.migrate_msg()? {
                    println!("Migrating {}", contract.name());
                    replace_strings(&mut msg, &config.get_active_env()?.contracts)?;
                    let contract_info = config.get_contract(&contract.to_string())?;
                    let contract_addr = contract_info.addr.clone().ok_or(DeployError::AddrNotFound)?;
                    let code_id = contract_info.code_id.ok_or(DeployError::CodeIdNotFound)?;
                    reqs.push(MigrateRequest {
                        msg,
                        address: Address::from_str(&contract_addr).unwrap(),
                        new_code_id: code_id,
                    });
                }
            }
            let response = cosm_tome.wasm_migrate_batch(reqs, &key, &tx_options).await?;
            Some(response.res)
        }
    };
    if let Some(res) = response {
        println!("gas wanted: {}, gas used: {}", res.gas_wanted.to_string().green(), res.gas_used.to_string().green());
        println!("tx hash: {}", res.tx_hash.purple());
    }

    Ok(())
}
Examples found in repository?
src/commands.rs (line 72)
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
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)
}
More examples
Hide additional examples
src/file.rs (line 272)
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
pub fn get_shell_completion_dir() -> Result<Option<PathBuf>, DeployError> {
    let mut config = Config::load()?;
    match config.shell_completion_dir {
        Some(shell_completion_path) => Ok(Some(shell_completion_path)),
        None => {
            let ans = Confirm::new("Shell completion directory not found.\nWould you like to add one?")
                .with_default(true)
                .prompt()?;
            match ans {
                true => {
                    let string = CustomType::<String>::new("Enter you shell completion script directory.").prompt()?;
                    let path = PathBuf::from(string);
                    match path.is_dir() {
                        true => {
                            config.shell_completion_dir = Some(path.clone());
                            config.save()?;
                            Ok(Some(path))
                        }
                        false => Err(DeployError::InvalidDir),
                    }
                }
                false => Ok(None),
            }
        }
    }
}
src/wasm_msg.rs (line 59)
28
29
30
31
32
33
34
35
36
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
pub async fn msg_contract(contracts: &[impl Contract], msg_type: DeploymentStage) -> DeployResult<()> {
    let mut config = Config::load()?;
    let chain_info = config.get_active_chain_info()?;
    let key = config.get_active_key().await?;
    let client = CosmosgRPC::new(chain_info.grpc_endpoint.clone().unwrap());
    let cosm_tome = CosmTome::new(chain_info, client);
    let tx_options = TxOptions { timeout_height: None, fee: None, memo: "wasm_deploy".into() };

    let response: Option<ChainTxResponse> = match msg_type {
        DeploymentStage::StoreCode => {
            let mut reqs = vec![];
            for contract in contracts {
                println!("Storing code for {}", contract.name());
                let path = format!("./artifacts/{}.wasm", contract.name());
                let wasm_data = std::fs::read(path)?;
                reqs.push(StoreCodeRequest { wasm_data, instantiate_perms: None });
            }
            let response = cosm_tome.wasm_store_batch(reqs, &key, &tx_options).await?;

            for (i, contract) in contracts.iter().enumerate() {
                match config.get_contract(&contract.to_string()) {
                    Ok(contract_info) => contract_info.code_id = Some(response.code_ids[i]),
                    Err(_) => {
                        config.add_contract_from(ContractInfo {
                            name:    contract.name(),
                            addr:    None,
                            code_id: Some(response.code_ids[i]),
                        })?;
                    }
                }
            }
            config.save()?;
            Some(response.res)
        }
        DeploymentStage::Instantiate => {
            let mut reqs = vec![];
            let tx_options =
                TxOptions { timeout_height: None, fee: None, memo: "wasm_deploy".into() };
            for contract in contracts {
                println!("Instantiating {}", contract.name());
                let mut msg = contract.instantiate_msg()?;
                replace_strings(&mut msg, &config.get_active_env()?.contracts)?;
                let contract_info = config.get_contract(&contract.to_string())?;
                let code_id = contract_info.code_id.ok_or(DeployError::CodeIdNotFound)?;
                reqs.push(InstantiateRequest {
                    code_id,
                    msg,
                    label: contract.name(),
                    admin: Some(Address::from_str(&contract.admin()).unwrap()),
                    funds: vec![],
                });
                for mut external in contract.external_instantiate_msgs()? {
                    println!("Instantiating {}", external.name);
                    replace_strings(&mut external.msg, &config.get_active_env()?.contracts)?;
                    reqs.push(InstantiateRequest {
                        code_id: external.code_id,
                        msg:     external.msg,
                        label:   external.name.clone(),
                        admin:   Some(Address::from_str(&contract.admin()).unwrap()),
                        funds:   vec![],
                    });
                }
            }
            let response = cosm_tome.wasm_instantiate_batch(reqs, &key, &tx_options).await?;
            let mut index = 0;
            for contract in contracts {
                let contract_info = config.get_contract(&contract.to_string())?;
                contract_info.addr = Some(response.addresses[index].to_string());
                index += 1;
                for external in contract.external_instantiate_msgs()? {
                    config.add_contract_from(ContractInfo {
                        name:    external.name,
                        addr:    Some(response.addresses[index].to_string()),
                        code_id: Some(external.code_id),
                    })?;
                    index += 1;
                }
            }
            config.save()?;
            Some(response.res)
        }
        DeploymentStage::SetConfig => {
            let mut reqs = vec![];
            for contract in contracts {
                println!("Setting config for {}", contract.name());
                let Some(mut msg) = contract.config_msg()? else { return Ok(()) };
                replace_strings(&mut msg, &config.get_active_env()?.contracts)?;
                let contract_addr = config.get_contract_addr_mut(&contract.to_string())?.clone();
                reqs.push(ExecRequest { msg, funds: vec![], address: Address::from_str(&contract_addr).unwrap() });
            }
            let response = cosm_tome.wasm_execute_batch(reqs, &key, &tx_options).await?;
            Some(response.res)
        }
        DeploymentStage::SetUp => {
            let mut reqs = vec![];
            for contract in contracts {
                println!("Executing Set Up for {}", contract.name());
                for mut msg in contract.set_up_msgs()? {
                    replace_strings(&mut msg, &config.get_active_env()?.contracts)?;
                    let contract_addr = config.get_contract_addr_mut(&contract.to_string())?.clone();
                    reqs.push(ExecRequest { msg, funds: vec![], address: Address::from_str(&contract_addr).unwrap() });
                }
            }
            let response = cosm_tome.wasm_execute_batch(reqs, &key, &tx_options).await?;
            Some(response.res)
        }
        DeploymentStage::Migrate => {
            let mut reqs = vec![];
            for contract in contracts {
                if let Some(mut msg) = contract.migrate_msg()? {
                    println!("Migrating {}", contract.name());
                    replace_strings(&mut msg, &config.get_active_env()?.contracts)?;
                    let contract_info = config.get_contract(&contract.to_string())?;
                    let contract_addr = contract_info.addr.clone().ok_or(DeployError::AddrNotFound)?;
                    let code_id = contract_info.code_id.ok_or(DeployError::CodeIdNotFound)?;
                    reqs.push(MigrateRequest {
                        msg,
                        address: Address::from_str(&contract_addr).unwrap(),
                        new_code_id: code_id,
                    });
                }
            }
            let response = cosm_tome.wasm_migrate_batch(reqs, &key, &tx_options).await?;
            Some(response.res)
        }
    };
    if let Some(res) = response {
        println!("gas wanted: {}, gas used: {}", res.gas_wanted.to_string().green(), res.gas_used.to_string().green());
        println!("tx hash: {}", res.tx_hash.purple());
    }

    Ok(())
}
Examples found in repository?
src/file.rs (line 106)
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
    pub(crate) fn get_active_chain_info(&mut self) -> Result<ChainConfig, DeployError> {
        let chains = self.chains.clone();
        let env = self.get_active_env_mut()?;
        match chains.iter().find(|x| x.chain_id == env.chain_id) {
            Some(chain_info) => Ok(chain_info.clone()),
            None => self.add_chain(),
        }
    }

    #[allow(unused_mut)]
    pub(crate) async fn get_active_key(&mut self) -> Result<SigningKey, DeployError> {
        let active_key_name = self.get_active_env()?.key_name.clone();
        let key = self
            .keys
            .iter_mut()
            .find(|x| x.name == active_key_name)
            .ok_or(DeployError::KeyNotFound { key_name: active_key_name })?;
        let mut key = key.clone();
        #[cfg(feature = "ledger")]
        if let Key::Ledger { connection, .. } = &mut key.key {
            if connection.is_none() {
                *connection = Some(Rc::new(Connection::new().await));
            }
        }
        Ok(key)
    }

    pub(crate) fn _get_active_chain_id(&mut self) -> Result<String, DeployError> {
        Ok(self.get_active_chain_info()?.chain_id)
    }

    // pub(crate) fn _get_client(&mut self) -> Result<impl Client, DeployError> {
    //     let url = self.get_active_chain_info()?.rpc_endpoint;
    //     Ok(HttpClient::new(url.as_str()).unwrap())
    // }

    pub(crate) fn add_chain_from(&mut self, chain_info: ChainConfig) -> Result<ChainConfig, DeployError> {
        match self.chains.iter().any(|x| x.chain_id == chain_info.chain_id) {
            true => Err(DeployError::ChainAlreadyExists),
            false => {
                self.chains.push(chain_info.clone());
                Ok(chain_info)
            }
        }
    }

    pub(crate) fn add_chain(&mut self) -> Result<ChainConfig, DeployError> {
        let chain_info = ChainConfig::parse_to_obj()?;
        self.add_chain_from(chain_info.clone())?;
        Ok(chain_info)
    }

    /// Adds or replaces a contract
    pub(crate) fn add_contract_from(&mut self, new_contract: ContractInfo) -> Result<ContractInfo, DeployError> {
        let env = self.get_active_env_mut()?;
        match env.contracts.iter_mut().find(|x| x.name == new_contract.name) {
            Some(contract) => *contract = new_contract.clone(),
            None => env.contracts.push(new_contract.clone()),
        }
        Ok(new_contract)
    }

    pub(crate) fn add_contract(&mut self) -> Result<ContractInfo, DeployError> {
        let contract = ContractInfo::parse_to_obj()?;
        self.add_contract_from(contract.clone())?;
        Ok(contract)
    }

    pub(crate) fn get_contract_addr_mut(&mut self, name: &String) -> Result<&String, DeployError> {
        let contract = self.get_contract(name)?;
        match &contract.addr {
            Some(addr) => Ok(addr),
            None => Err(DeployError::NoAddr),
        }
    }

    pub(crate) fn _get_code_id(&mut self, name: &String) -> Result<&mut u64, DeployError> {
        let contract = self.get_contract(name)?;
        match &mut contract.code_id {
            Some(code_id) => Ok(code_id),
            None => Err(DeployError::CodeIdNotFound),
        }
    }

    pub(crate) fn get_contract(&mut self, name: &String) -> Result<&mut ContractInfo, DeployError> {
        let env = self.get_active_env_mut()?;
        env.contracts.iter_mut().find(|x| &x.name == name).ok_or(DeployError::ContractNotFound)
    }
More examples
Hide additional examples
src/commands.rs (line 119)
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
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)
}
Examples found in repository?
src/file.rs (line 115)
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
    pub(crate) async fn get_active_key(&mut self) -> Result<SigningKey, DeployError> {
        let active_key_name = self.get_active_env()?.key_name.clone();
        let key = self
            .keys
            .iter_mut()
            .find(|x| x.name == active_key_name)
            .ok_or(DeployError::KeyNotFound { key_name: active_key_name })?;
        let mut key = key.clone();
        #[cfg(feature = "ledger")]
        if let Key::Ledger { connection, .. } = &mut key.key {
            if connection.is_none() {
                *connection = Some(Rc::new(Connection::new().await));
            }
        }
        Ok(key)
    }
More examples
Hide additional examples
src/contract.rs (line 49)
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
pub async fn execute(contract: &impl Execute) -> Result<(), DeployError> {
    println!("Executing");
    let mut config = Config::load()?;
    let mut msg = contract.execute_msg()?;
    replace_strings(&mut msg, &config.get_active_env()?.contracts)?;
    let key = config.get_active_key().await?;
    let chain_info = config.get_active_chain_info()?;
    let client = CosmosgRPC::new(chain_info.grpc_endpoint.clone().unwrap());
    let cosm_tome = CosmTome::new(chain_info, client);
    let contract_addr = config.get_contract_addr_mut(&contract.to_string())?.clone();
    let funds = Vec::<Coin>::parse_to_obj()?;
    let tx_options = TxOptions { timeout_height: None, fee: None, memo: "wasm_deploy".into() };
    let req = ExecRequest { msg, funds, address: Address::from_str(&contract_addr).unwrap() };
    let response = cosm_tome.wasm_execute(req, &key, &tx_options).await?;

    println!(
        "gas wanted: {}, gas used: {}",
        response.res.gas_wanted.to_string().green(),
        response.res.gas_used.to_string().green()
    );
    println!("tx hash: {}", response.res.tx_hash.purple());

    Ok(())
}

pub trait Query: Serialize + DeserializeOwned + Display + Debug {
    fn query_msg(&self) -> Result<Value, DeployError>;
    fn parse(contract: &impl Contract) -> DeployResult<Self>;
}

pub async fn query(contract: &impl Query) -> Result<(), DeployError> {
    println!("Querying");
    let mut config = Config::load()?;
    let mut msg = contract.query_msg()?;
    replace_strings(&mut msg, &config.get_active_env()?.contracts)?;
    let chain_info = config.get_active_chain_info()?;
    let addr = config.get_contract_addr_mut(&contract.to_string())?;
    let client = CosmosgRPC::new(chain_info.grpc_endpoint.clone().unwrap());
    let cosm_tome = CosmTome::new(chain_info, client);
    let response = cosm_tome.wasm_query(Address::from_str(addr).unwrap(), &msg).await?;

    let string = String::from_utf8(response.res.data.unwrap()).unwrap();
    let value: serde_json::Value = serde_json::from_str(string.as_str()).unwrap();
    let color = to_colored_json_auto(&value)?;
    println!("{color}");

    Ok(())
}
src/wasm_msg.rs (line 69)
28
29
30
31
32
33
34
35
36
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
pub async fn msg_contract(contracts: &[impl Contract], msg_type: DeploymentStage) -> DeployResult<()> {
    let mut config = Config::load()?;
    let chain_info = config.get_active_chain_info()?;
    let key = config.get_active_key().await?;
    let client = CosmosgRPC::new(chain_info.grpc_endpoint.clone().unwrap());
    let cosm_tome = CosmTome::new(chain_info, client);
    let tx_options = TxOptions { timeout_height: None, fee: None, memo: "wasm_deploy".into() };

    let response: Option<ChainTxResponse> = match msg_type {
        DeploymentStage::StoreCode => {
            let mut reqs = vec![];
            for contract in contracts {
                println!("Storing code for {}", contract.name());
                let path = format!("./artifacts/{}.wasm", contract.name());
                let wasm_data = std::fs::read(path)?;
                reqs.push(StoreCodeRequest { wasm_data, instantiate_perms: None });
            }
            let response = cosm_tome.wasm_store_batch(reqs, &key, &tx_options).await?;

            for (i, contract) in contracts.iter().enumerate() {
                match config.get_contract(&contract.to_string()) {
                    Ok(contract_info) => contract_info.code_id = Some(response.code_ids[i]),
                    Err(_) => {
                        config.add_contract_from(ContractInfo {
                            name:    contract.name(),
                            addr:    None,
                            code_id: Some(response.code_ids[i]),
                        })?;
                    }
                }
            }
            config.save()?;
            Some(response.res)
        }
        DeploymentStage::Instantiate => {
            let mut reqs = vec![];
            let tx_options =
                TxOptions { timeout_height: None, fee: None, memo: "wasm_deploy".into() };
            for contract in contracts {
                println!("Instantiating {}", contract.name());
                let mut msg = contract.instantiate_msg()?;
                replace_strings(&mut msg, &config.get_active_env()?.contracts)?;
                let contract_info = config.get_contract(&contract.to_string())?;
                let code_id = contract_info.code_id.ok_or(DeployError::CodeIdNotFound)?;
                reqs.push(InstantiateRequest {
                    code_id,
                    msg,
                    label: contract.name(),
                    admin: Some(Address::from_str(&contract.admin()).unwrap()),
                    funds: vec![],
                });
                for mut external in contract.external_instantiate_msgs()? {
                    println!("Instantiating {}", external.name);
                    replace_strings(&mut external.msg, &config.get_active_env()?.contracts)?;
                    reqs.push(InstantiateRequest {
                        code_id: external.code_id,
                        msg:     external.msg,
                        label:   external.name.clone(),
                        admin:   Some(Address::from_str(&contract.admin()).unwrap()),
                        funds:   vec![],
                    });
                }
            }
            let response = cosm_tome.wasm_instantiate_batch(reqs, &key, &tx_options).await?;
            let mut index = 0;
            for contract in contracts {
                let contract_info = config.get_contract(&contract.to_string())?;
                contract_info.addr = Some(response.addresses[index].to_string());
                index += 1;
                for external in contract.external_instantiate_msgs()? {
                    config.add_contract_from(ContractInfo {
                        name:    external.name,
                        addr:    Some(response.addresses[index].to_string()),
                        code_id: Some(external.code_id),
                    })?;
                    index += 1;
                }
            }
            config.save()?;
            Some(response.res)
        }
        DeploymentStage::SetConfig => {
            let mut reqs = vec![];
            for contract in contracts {
                println!("Setting config for {}", contract.name());
                let Some(mut msg) = contract.config_msg()? else { return Ok(()) };
                replace_strings(&mut msg, &config.get_active_env()?.contracts)?;
                let contract_addr = config.get_contract_addr_mut(&contract.to_string())?.clone();
                reqs.push(ExecRequest { msg, funds: vec![], address: Address::from_str(&contract_addr).unwrap() });
            }
            let response = cosm_tome.wasm_execute_batch(reqs, &key, &tx_options).await?;
            Some(response.res)
        }
        DeploymentStage::SetUp => {
            let mut reqs = vec![];
            for contract in contracts {
                println!("Executing Set Up for {}", contract.name());
                for mut msg in contract.set_up_msgs()? {
                    replace_strings(&mut msg, &config.get_active_env()?.contracts)?;
                    let contract_addr = config.get_contract_addr_mut(&contract.to_string())?.clone();
                    reqs.push(ExecRequest { msg, funds: vec![], address: Address::from_str(&contract_addr).unwrap() });
                }
            }
            let response = cosm_tome.wasm_execute_batch(reqs, &key, &tx_options).await?;
            Some(response.res)
        }
        DeploymentStage::Migrate => {
            let mut reqs = vec![];
            for contract in contracts {
                if let Some(mut msg) = contract.migrate_msg()? {
                    println!("Migrating {}", contract.name());
                    replace_strings(&mut msg, &config.get_active_env()?.contracts)?;
                    let contract_info = config.get_contract(&contract.to_string())?;
                    let contract_addr = contract_info.addr.clone().ok_or(DeployError::AddrNotFound)?;
                    let code_id = contract_info.code_id.ok_or(DeployError::CodeIdNotFound)?;
                    reqs.push(MigrateRequest {
                        msg,
                        address: Address::from_str(&contract_addr).unwrap(),
                        new_code_id: code_id,
                    });
                }
            }
            let response = cosm_tome.wasm_migrate_batch(reqs, &key, &tx_options).await?;
            Some(response.res)
        }
    };
    if let Some(res) = response {
        println!("gas wanted: {}, gas used: {}", res.gas_wanted.to_string().green(), res.gas_used.to_string().green());
        println!("tx hash: {}", res.tx_hash.purple());
    }

    Ok(())
}

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Converts to this type from a reference to the input type.
Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Wrap the input message T in a tonic::Request
The none-equivalent value.
Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more