Skip to content

Commit

Permalink
feat(up-contract): custom errors in contracts crate
Browse files Browse the repository at this point in the history
  • Loading branch information
peterwht committed Dec 11, 2024
1 parent 1342b1a commit 01e9a30
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions crates/pop-contracts/src/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use ink_env::{DefaultEnvironment, Environment};
use sp_core::{bytes::from_hex, Bytes};
use sp_weights::Weight;
use std::{
fmt::Write,
fmt::{format, Write},
path::{Path, PathBuf},
};
use subxt::{
Expand Down Expand Up @@ -171,7 +171,10 @@ pub async fn get_contract_code(

let artifacts_path = artifacts.artifact_path().to_path_buf();
let code = artifacts.code.ok_or_else(|| {
anyhow::anyhow!("Contract code not found from artifact file {}", artifacts_path.display())
Error::UploadContractError(format!(
"Contract code not found from artifact file {}",
artifacts_path.display()
))
})?;
Ok(code)
}
Expand Down Expand Up @@ -201,7 +204,9 @@ pub async fn instantiate_contract_signed(

let instantiated = events
.find_first::<ContractInstantiated<subxt::config::substrate::AccountId32>>()?
.ok_or_else(|| anyhow::anyhow!("Failed to find Instantiated event"))?;
.ok_or_else(|| {
Error::InstantiateContractError("Failed to find Instantiated event".to_string())
})?;

Ok(InstantiateExecResult { events, code_hash, contract_address: instantiated.contract })
}
Expand Down

0 comments on commit 01e9a30

Please sign in to comment.