Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Review suggestions
  • Loading branch information
ascjones committed Jan 12, 2023
commit 63b71d66960e0ef8938b067b7a3af316af6f9242
9 changes: 9 additions & 0 deletions crates/cargo-contract/src/cmd/extrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ impl ExtrinsicOpts {
/// Contract artifacts for use with extrinsic commands.
#[derive(Debug)]
pub struct ContractArtifacts {
/// The original artifact path
artifacts_path: PathBuf,
/// The expected path of the file containing the contract metadata.
metadata_path: PathBuf,
/// The deserialized contract metadata if the expected metadata file exists.
Expand Down Expand Up @@ -241,12 +243,18 @@ impl ContractArtifacts {
}
};
Ok(Self {
artifacts_path: path.into(),
metadata_path,
metadata,
code,
})
}

/// Get the path of the artifact file used to load the artifacts.
pub fn artifact_path(&self) -> &Path {
self.artifacts_path.as_path()
}

/// Get contract metadata, if available.
///
/// ## Errors
Expand Down Expand Up @@ -280,6 +288,7 @@ impl ContractArtifacts {
pub struct WasmCode(Vec<u8>);

impl WasmCode {
/// The hash of the contract code: uniquely identifies the contract code on-chain.
pub fn code_hash(&self) -> [u8; 32] {
Comment thread
ascjones marked this conversation as resolved.
contract_build::code_hash(&self.0)
}
Expand Down
9 changes: 6 additions & 3 deletions crates/cargo-contract/src/cmd/extrinsics/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ impl UploadCommand {
let artifacts = self.extrinsic_opts.contract_artifacts()?;
let signer = super::pair_signer(self.extrinsic_opts.signer()?);

let code = artifacts
.code
.ok_or_else(|| anyhow::anyhow!("Contract code not found"))?; // todo: add more detail
let code = artifacts.code.ok_or_else(|| {
anyhow::anyhow!(
"Contract code not found from artifact file {}",
artifacts.artifacts_path().display()
)
})?;
let code_hash = code.code_hash();

async_std::task::block_on(async {
Expand Down