Commit 64d40149 authored by Andrew Jones's avatar Andrew Jones
Browse files

Fix gas estimation and fmt

parent 2f887683
Pipeline #201163 failed with stages
in 19 seconds
......@@ -32,6 +32,7 @@ use super::{
EXEC_RESULT_MAX_KEY_COL_WIDTH,
};
use crate::{
cmd::extrinsics::prompt_gas_estimate,
name_value_println,
util::decode_hex,
Verbosity,
......@@ -56,7 +57,6 @@ use sp_core::{
Bytes,
};
use std::{
io::{self, Write},
fs,
path::{
Path,
......@@ -348,7 +348,7 @@ impl<'a> Exec<'a> {
async fn instantiate_dry_run(&self, code: Code) -> Result<ContractInstantiateResult> {
let cli = WsClientBuilder::default().build(&self.url).await?;
let gas_limit = self.args.gas_limit.as_ref().unwrap_or(&50000000000);
let gas_limit = self.args.gas_limit.as_ref().unwrap_or(&5000000000000);
let storage_deposit_limit = self
.args
.storage_deposit_limit
......@@ -379,21 +379,7 @@ impl<'a> Exec<'a> {
Ok(gas_limit)
} else {
let instantiate_result = self.instantiate_dry_run(code).await?;
let gas_required = instantiate_result.gas_required;
println!();
println!("Confirm estimated gas limit for this transaction.");
println!("Override with the --gas option, or skip this prompt with --skip-gas-prompt");
print!("Gas required estimated at {}. Accept? (Y/n): ", gas_required);
let mut buf = String::new();
io::stdout().flush()?;
io::stdin().read_line(&mut buf)?;
match buf.trim() {
"Y" => Ok(gas_required),
"n" => Err(anyhow!("Estimated gas limit not accepted, transaction not submitted")),
c => Err(anyhow!("Expected either 'Y' or 'n', got '{}'", c))
}
prompt_gas_estimate(instantiate_result.gas_required)
}
}
}
......
......@@ -31,6 +31,10 @@ use anyhow::{
};
use std::{
fs::File,
io::{
self,
Write,
},
path::PathBuf,
};
......@@ -263,3 +267,29 @@ async fn dry_run_error_details(
};
Ok(error)
}
/// Prompt the user to accept or reject the estimated gas required
fn prompt_gas_estimate(gas_required: u64) -> Result<u64> {
println!();
println!("Confirm estimated gas limit for this transaction.");
println!(
"Override with the --gas option, or skip this prompt with --skip-gas-prompt"
);
print!(
"Gas required estimated at {}. Accept? (Y/n): ",
gas_required
);
let mut buf = String::new();
io::stdout().flush()?;
io::stdin().read_line(&mut buf)?;
match buf.trim() {
"Y" => Ok(gas_required),
"n" => {
Err(anyhow!(
"Estimated gas limit not accepted, transaction not submitted"
))
}
c => Err(anyhow!("Expected either 'Y' or 'n', got '{}'", c)),
}
}
......@@ -432,38 +432,40 @@ mod tests {
(
Value::String("d".to_string()),
Value::Seq(
vec![Value::Map(
vec![
(Value::String("a".to_string()), Value::UInt(2)),
(
Value::String("b".to_string()),
Value::String("ink!".to_string()),
),
(
Value::String("c".to_string()),
Value::Seq(
vec![
Value::UInt(0xDE),
Value::UInt(0xAD),
Value::UInt(0xBE),
Value::UInt(0xEF),
]
.into(),
vec![
Value::Map(
vec![
(Value::String("a".to_string()), Value::UInt(2)),
(
Value::String("b".to_string()),
Value::String("ink!".to_string()),
),
),
(
Value::String("d".to_string()),
Value::Seq(
Vec::new()
.into_iter()
.collect::<Vec<_>>()
(
Value::String("c".to_string()),
Value::Seq(
vec![
Value::UInt(0xDE),
Value::UInt(0xAD),
Value::UInt(0xBE),
Value::UInt(0xEF),
]
.into(),
),
),
(
Value::String("d".to_string()),
Value::Seq(
Vec::new()
.into_iter()
.collect::<Vec<_>>()
.into(),
),
),
),
]
.into_iter()
.collect(),
)]
]
.into_iter()
.collect(),
),
]
.into(),
),
),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment