Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
cargo-contract
Commits
64d40149
Commit
64d40149
authored
Jul 01, 2022
by
Andrew Jones
Browse files
Fix gas estimation and fmt
parent
2f887683
Pipeline
#201163
failed with stages
in 19 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/cmd/extrinsics/instantiate.rs
View file @
64d40149
...
...
@@ -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
(
&
50000000000
00
);
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
)
}
}
}
...
...
src/cmd/extrinsics/mod.rs
View file @
64d40149
...
...
@@ -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
)),
}
}
transcode/src/transcoder.rs
View file @
64d40149
...
...
@@ -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
(),
),
),
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment