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
d3fc06cd
Unverified
Commit
d3fc06cd
authored
May 30, 2022
by
Andrew Jones
Committed by
GitHub
May 30, 2022
Browse files
Fix `instantiate_with_code` with already uploaded code (#594)
parent
2e2998f7
Pipeline
#196342
passed with stages
in 14 minutes
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/cmd/extrinsics/instantiate.rs
View file @
d3fc06cd
...
...
@@ -251,7 +251,9 @@ impl<'a> Exec<'a> {
Code
::
Upload
(
code
)
=>
{
let
(
code_hash
,
contract_account
)
=
self
.instantiate_with_code
(
code
)
.await
?
;
name_value_println!
(
"Code hash"
,
format!
(
"{:?}"
,
code_hash
));
if
let
Some
(
code_hash
)
=
code_hash
{
name_value_println!
(
"Code hash"
,
format!
(
"{:?}"
,
code_hash
));
}
name_value_println!
(
"Contract"
,
contract_account
.to_ss58check
());
}
Code
::
Existing
(
code_hash
)
=>
{
...
...
@@ -265,7 +267,7 @@ impl<'a> Exec<'a> {
async
fn
instantiate_with_code
(
&
self
,
code
:
Bytes
,
)
->
Result
<
(
CodeHash
,
ContractAccount
)
>
{
)
->
Result
<
(
Option
<
CodeHash
>
,
ContractAccount
)
>
{
let
api
=
self
.subxt_api
()
.await
?
;
let
tx_progress
=
api
.tx
()
...
...
@@ -287,14 +289,16 @@ impl<'a> Exec<'a> {
display_events
(
&
result
,
&
self
.transcoder
,
metadata
,
&
self
.verbosity
)
?
;
let
code_stored
=
result
// The CodeStored event is only raised if the contract has not already been uploaded.
let
code_hash
=
result
.find_first
::
<
api
::
contracts
::
events
::
CodeStored
>
()
?
.ok_or_else
(||
anyhow!
(
"Failed to find CodeStored event"
))
?
;
.map
(|
code_stored
|
code_stored
.code_hash
);
let
instantiated
=
result
.find_first
::
<
api
::
contracts
::
events
::
Instantiated
>
()
?
.ok_or_else
(||
anyhow!
(
"Failed to find Instantiated event"
))
?
;
Ok
((
code_
stored
.code_
hash
,
instantiated
.contract
))
Ok
((
code_hash
,
instantiated
.contract
))
}
async
fn
instantiate
(
&
self
,
code_hash
:
CodeHash
)
->
Result
<
ContractAccount
>
{
...
...
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