Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix storage deposit limit encoding #751

Merged
merged 11 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Fix storage deposit limit encoding - [#751](https://github.com/paritytech/cargo-contract/pull/751)

## [2.0.0-alpha.3] - 2022-09-21

This release supports compatibility with the [`v4.0.0-alpha.3`](https://github.com/paritytech/ink/releases/tag/v4.0.0-alpha.3)
Expand Down
47 changes: 29 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/cargo-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ regex = "1.6.0"
async-std = { version = "1.12.0", features = ["attributes", "tokio1"] }
sp-core = "6.0.0"
pallet-contracts-primitives = "6.0.0"
subxt = "0.23.0"
subxt = "0.24.0"
hex = "0.4.3"
jsonrpsee = { version = "0.15.1", features = ["ws-client"] }

Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-contract/src/cmd/extrinsics/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ impl CallCommand {
self.contract.clone().into(),
self.value,
gas_limit,
self.extrinsic_opts.storage_deposit_limit,
self.extrinsic_opts.storage_deposit_limit(),
data,
);

Expand Down
17 changes: 9 additions & 8 deletions crates/cargo-contract/src/cmd/extrinsics/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,27 @@ impl DisplayEvents {

let event_data = &mut event.field_bytes();
let mut unnamed_field_name = 0;
for (field, field_ty) in event_fields {
for field in event_fields {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note that changes here are only to fix compilation because of the updating to subxt 0.24, and unrelated to the bugfix itself.

if <ContractEmitted as StaticEvent>::is_event(
event.pallet_name(),
event.variant_name(),
) && field.as_ref() == Some(&"data".to_string())
) && field.name() == Some("data")
{
tracing::debug!("event data: {:?}", hex::encode(&event_data));
let contract_event = transcoder.decode_contract_event(event_data)?;
let field = Field::new(String::from("data"), contract_event);
event_entry.fields.push(field);
} else {
let field_name = field.clone().unwrap_or_else(|| {
let name = unnamed_field_name.to_string();
unnamed_field_name += 1;
name
});
let field_name =
field.name().map(ToOwned::to_owned).unwrap_or_else(|| {
let name = unnamed_field_name.to_string();
unnamed_field_name += 1;
name
});

let decoded_field = events_transcoder.decode(
&runtime_metadata.types,
*field_ty,
field.type_id(),
event_data,
)?;
let field = Field::new(field_name, decoded_field);
Expand Down
10 changes: 8 additions & 2 deletions crates/cargo-contract/src/cmd/extrinsics/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ struct InstantiateArgs {
salt: Vec<u8>,
}

impl InstantiateArgs {
fn storage_deposit_limit_compact(&self) -> Option<scale::Compact<Balance>> {
self.storage_deposit_limit.map(Into::into)
}
}

pub struct Exec {
opts: ExtrinsicOpts,
args: InstantiateArgs,
Expand Down Expand Up @@ -283,7 +289,7 @@ impl Exec {
let call = api::tx().contracts().instantiate_with_code(
self.args.value,
gas_limit,
self.args.storage_deposit_limit,
self.args.storage_deposit_limit_compact(),
code.to_vec(),
self.args.data.clone(),
self.args.salt.clone(),
Expand Down Expand Up @@ -322,7 +328,7 @@ impl Exec {
let call = api::tx().contracts().instantiate(
self.args.value,
gas_limit,
self.args.storage_deposit_limit,
self.args.storage_deposit_limit_compact(),
code_hash,
self.args.data.clone(),
self.args.salt.clone(),
Expand Down
5 changes: 5 additions & 0 deletions crates/cargo-contract/src/cmd/extrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ impl ExtrinsicOpts {
_ => res,
}
}

/// Get the storage deposit limit converted to compact for passing to extrinsics.
pub fn storage_deposit_limit(&self) -> Option<scale::Compact<Balance>> {
self.storage_deposit_limit.map(Into::into)
}
}

/// Parse Rust style integer balance literals which can contain underscores.
Expand Down
2 changes: 1 addition & 1 deletion crates/cargo-contract/src/cmd/extrinsics/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl UploadCommand {
) -> Result<Option<api::contracts::events::CodeStored>, ErrorVariant> {
let call = super::runtime_api::api::tx()
.contracts()
.upload_code(code, self.extrinsic_opts.storage_deposit_limit);
.upload_code(code, self.extrinsic_opts.storage_deposit_limit());

let result = submit_extrinsic(client, &call, signer).await?;
let display_events =
Expand Down