use crate::{App, result::Result, utils::Hex};
use clap::Parser;
#[derive(Clone, Debug, Parser)]
pub struct Create {
code_id: String,
#[arg(short, long, default_value = "0x")]
salt: String,
#[arg(short, long, default_value = "0x")]
init_payload: String,
#[arg(short, long)]
gas_limit: Option<u64>,
#[arg(short, long, default_value = "0")]
value: u128,
}
impl Create {
pub async fn exec(&self, app: &impl App) -> Result<()> {
let code_id = self.code_id.to_hash()?.into();
let payload = self.init_payload.to_vec()?;
let signer = app.signer().await?;
let gas_limit = if let Some(gas_limit) = self.gas_limit {
gas_limit
} else {
signer
.calculate_create_gas(None, code_id, payload.clone(), self.value, false)
.await?
.min_limit
};
signer
.create_program(code_id, self.salt.to_vec()?, payload, gas_limit, self.value)
.await?;
Ok(())
}
}