Skip to content

Commit

Permalink
Merge pull request #61 from osmosis-labs/boss/contract_admin
Browse files Browse the repository at this point in the history
  • Loading branch information
iboss-ptk authored Jul 2, 2022
2 parents b95c08a + 64e2b91 commit cb10163
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/cli/src/modules/wasm/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,17 @@ pub enum WasmCmd {
/// Label for the instantiated contract for later reference
#[clap(short, long, default_value = "default")]
label: String,

/// Raw json string to use as instantiate msg
#[clap(short, long)]
raw: Option<String>,

/// Specifying admin required for contract migration.
/// Use "signer" for setting tx signer as admin.
/// Use bech32 address (eg. "osmo1cyyzpxplxdzkeea7kwsydadg87357qnahakaks") for custom admin.
#[clap(long)]
admin: Option<String>,

/// Funds to send to instantiated contract
#[clap(short, long)]
funds: Option<String>,
Expand All @@ -74,6 +81,12 @@ pub enum WasmCmd {
#[clap(short, long)]
raw: Option<String>,

/// Specifying admin required for contract migration.
/// Use "signer" for setting tx signer as admin.
/// Use bech32 address (eg. "osmo1cyyzpxplxdzkeea7kwsydadg87357qnahakaks") for custom admin.
#[clap(long)]
admin: Option<String>,

/// Funds to send to instantiated contract
#[clap(short, long)]
funds: Option<String>,
Expand Down Expand Up @@ -145,6 +158,7 @@ impl<'a> Module<'a, WasmConfig, WasmCmd, anyhow::Error> for WasmModule {
contract_name,
label,
raw,
admin,
funds,
base_tx_args,
} => {
Expand All @@ -159,6 +173,7 @@ impl<'a> Module<'a, WasmConfig, WasmCmd, anyhow::Error> for WasmModule {
contract_name,
label.as_str(),
raw.as_ref(),
admin.as_ref(),
funds.as_ref().map(|s| s.as_str()).try_into()?,
network,
timeout_height,
Expand All @@ -178,6 +193,7 @@ impl<'a> Module<'a, WasmConfig, WasmCmd, anyhow::Error> for WasmModule {
contract_name,
label,
raw,
admin,
funds,
no_rebuild,
no_wasm_opt,
Expand All @@ -194,6 +210,7 @@ impl<'a> Module<'a, WasmConfig, WasmCmd, anyhow::Error> for WasmModule {
contract_name,
label.as_str(),
raw.as_ref(),
admin.as_ref(),
funds.as_ref().map(|s| s.as_str()).try_into()?,
network,
timeout_height,
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/modules/wasm/ops/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub fn deploy<'a, Ctx: Context<'a, WasmConfig>>(
contract_name: &str,
label: &str,
raw: Option<&String>,
admin: Option<&String>,
funds: Coins,
network: &str,
timeout_height: &u32,
Expand All @@ -43,6 +44,7 @@ pub fn deploy<'a, Ctx: Context<'a, WasmConfig>>(
contract_name,
label,
raw,
admin,
funds,
network,
timeout_height,
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/modules/wasm/ops/instantiate.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::attrs_format;
use crate::modules::wasm::config::WasmConfig;
use crate::support::admin::compute_admin;
use crate::support::coin::Coins;
use crate::support::cosmos::ResponseValuePicker;
use crate::support::future::block;
Expand All @@ -20,6 +21,7 @@ pub fn instantiate<'a, Ctx: Context<'a, WasmConfig>>(
contract_name: &str,
label: &str,
raw: Option<&String>,
admin: Option<&String>,
funds: Coins,
network: &str,
timeout_height: &u32,
Expand All @@ -45,7 +47,7 @@ pub fn instantiate<'a, Ctx: Context<'a, WasmConfig>>(

let msg_instantiate_contract = MsgInstantiateContract {
sender: client.signer_account_id(),
admin: None, // TODO: Fix this when working on migration
admin: compute_admin(admin, client.signer_account_id())?,
code_id,
label: Some(label.to_string()),
msg: raw
Expand Down
17 changes: 17 additions & 0 deletions packages/cli/src/support/admin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::str::FromStr;

use anyhow::anyhow;
use cosmrs::AccountId;

pub fn compute_admin(
admin: Option<&String>,
signer_account_id: AccountId,
) -> Result<Option<AccountId>, anyhow::Error> {
Ok(if admin == Some(&"signer".to_string()) {
Some(signer_account_id)
} else if let Some(addr) = admin {
Some(AccountId::from_str(addr).map_err(|e: cosmrs::ErrorReport| anyhow!(e))?)
} else {
None
})
}
1 change: 1 addition & 0 deletions packages/cli/src/support/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod admin;
pub mod coin;
pub mod cosmos;
pub mod future;
Expand Down

0 comments on commit cb10163

Please sign in to comment.