Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
contract upload: emitting a warning instead of an error when the cont…
…ract already existed is more user friendly

Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
  • Loading branch information
xermicus committed Jul 12, 2022
commit a1c914bb951fa7795f3f7073ab2e280711cf420b
24 changes: 16 additions & 8 deletions src/cmd/extrinsics/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use anyhow::{
Context,
Result,
};
use colored::Colorize;
use jsonrpsee::{
core::client::ClientT,
rpc_params,
Expand Down Expand Up @@ -106,10 +107,19 @@ impl UploadCommand {
}
Ok(())
} else {
let code_stored =
self.upload_code(&api, code, &signer, &transcoder).await?;

name_value_println!("Code hash", format!("{:?}", code_stored.code_hash));
if let Some(code_stored) =
self.upload_code(&api, code, &signer, &transcoder).await?
{
name_value_println!(
"Code hash",
format!("{:?}", code_stored.code_hash)
);
} else {
eprintln!(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually to be consistent could we return Err(anyhow!( as we do elsewhere, then it will eprintln! at the top level.

"{} This contract has already been uploaded",
"warning:".yellow().bold(),
);
}

Ok(())
}
Expand Down Expand Up @@ -149,7 +159,7 @@ impl UploadCommand {
code: Vec<u8>,
signer: &PairSigner,
transcoder: &ContractMessageTranscoder<'_>,
) -> Result<api::contracts::events::CodeStored> {
) -> Result<Option<api::contracts::events::CodeStored>> {
let tx_progress = api
.tx()
.contracts()
Expand All @@ -166,9 +176,7 @@ impl UploadCommand {
&self.extrinsic_opts.verbosity()?,
)?;

let code_stored = result
.find_first::<api::contracts::events::CodeStored>()?
.ok_or_else(|| anyhow::anyhow!("Failed to find CodeStored event"))?;
let code_stored = result.find_first::<api::contracts::events::CodeStored>()?;

Ok(code_stored)
}
Expand Down