Skip to content

Commit

Permalink
feat(gcli): make gas limit optional argument (#3753)
Browse files Browse the repository at this point in the history
Co-authored-by: Dmitrii Novikov <novikov.dm.al@gmail.com>
  • Loading branch information
clearloop and breathx authored Feb 28, 2024
1 parent fd97f06 commit 93b3e79
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 21 deletions.
12 changes: 6 additions & 6 deletions gcli/src/cmd/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ pub struct Create {
init_payload: String,
/// gear program gas limit
///
/// if zero, gear will estimate this automatically
#[arg(short, long, default_value = "0")]
gas_limit: u64,
/// Use estimated gas limit automatically if not set.
#[arg(short, long)]
gas_limit: Option<u64>,
/// gear program balance
#[arg(short, long, default_value = "0")]
value: u128,
Expand All @@ -49,13 +49,13 @@ impl Create {
let signer = app.signer().await?;

// estimate gas
let gas_limit = if self.gas_limit == 0 {
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
} else {
self.gas_limit
};

// create program
Expand Down
12 changes: 7 additions & 5 deletions gcli/src/cmd/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ pub struct Reply {
#[arg(short, long, default_value = "0x")]
payload: String,
/// Reply gas limit
#[arg(short, long, default_value = "0")]
gas_limit: u64,
///
/// Use estimated gas limit automatically if not set.
#[arg(short, long)]
gas_limit: Option<u64>,
/// Reply value
#[arg(short, long, default_value = "0")]
value: u128,
Expand All @@ -52,7 +54,9 @@ impl Reply {
let signer = app.signer().await?;
let reply_to_id = self.reply_to_id.to_hash()?;

let gas_limit = if self.gas_limit == 0 {
let gas_limit = if let Some(gas_limit) = self.gas_limit {
gas_limit
} else {
signer
.calculate_reply_gas(
None,
Expand All @@ -63,8 +67,6 @@ impl Reply {
)
.await?
.min_limit
} else {
self.gas_limit
};

signer
Expand Down
12 changes: 7 additions & 5 deletions gcli/src/cmd/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ pub struct Send {
#[arg(short, long, default_value = "0x")]
pub payload: String,
/// Send gas limit
#[arg(short, long, default_value = "0")]
pub gas_limit: u64,
///
/// Use estimated gas limit automatically if not set.
#[arg(short, long)]
pub gas_limit: Option<u64>,
/// Send value
#[arg(short, long, default_value = "0")]
pub value: u128,
Expand All @@ -55,7 +57,9 @@ pub struct Send {
impl Send {
pub async fn exec(&self, app: &impl App) -> Result<()> {
let signer = app.signer().await?;
let gas_limit = if self.gas_limit == 0 {
let gas_limit = if let Some(gas_limit) = self.gas_limit {
gas_limit
} else {
signer
.calculate_handle_gas(
None,
Expand All @@ -66,8 +70,6 @@ impl Send {
)
.await?
.min_limit
} else {
self.gas_limit
};

let (message_id, _) = signer
Expand Down
12 changes: 7 additions & 5 deletions gcli/src/cmd/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ pub struct Upload {
#[arg(short, long, default_value = "0x")]
payload: String,
/// Maximum amount of gas the program can spend before it is halted.
#[arg(short, long, default_value = "0")]
gas_limit: u64,
///
/// Use estimated gas limit automatically if not set.
#[arg(short, long)]
gas_limit: Option<u64>,
/// Balance to be transferred to the program once it's been created.
#[arg(short, long, default_value = "0")]
value: u128,
Expand Down Expand Up @@ -77,14 +79,14 @@ impl Upload {
}

let payload = self.payload.to_vec()?;
let gas_limit = if self.gas_limit == 0 {
let gas_limit = if let Some(gas_limit) = self.gas_limit {
gas_limit
} else {
signer
.rpc
.calculate_upload_gas(None, code.clone(), payload.clone(), self.value, false, None)
.await?
.min_limit
} else {
self.gas_limit
};

let tx = signer
Expand Down

0 comments on commit 93b3e79

Please sign in to comment.