-
Notifications
You must be signed in to change notification settings - Fork 121
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 the instantiate command for Substrate 0.9.42-based chains #1564
Changes from 7 commits
875e55a
2490b10
d235147
0a1b261
34ab731
a2242ac
5eb05af
d51f104
1084ce5
4399d4c
498463b
1732b77
d040ddd
705b6e9
591388a
1f47446
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,8 +47,13 @@ use super::parse_account; | |
#[clap(name = "storage", about = "Inspect contract storage")] | ||
pub struct StorageCommand { | ||
/// The address of the contract to inspect storage of. | ||
#[clap(name = "contract", long, env = "CONTRACT")] | ||
contract: String, | ||
#[clap( | ||
name = "contract", | ||
long, | ||
env = "CONTRACT", | ||
required_unless_present = "version" | ||
)] | ||
contract: Option<String>, | ||
/// Fetch the "raw" storage keys and values for the contract. | ||
#[clap(long)] | ||
raw: bool, | ||
|
@@ -70,6 +75,9 @@ pub struct StorageCommand { | |
default_value = "ws://localhost:9944" | ||
)] | ||
url: url::Url, | ||
/// Fetch the storage version of the pallet contracts (pallet version). | ||
smiasojed marked this conversation as resolved.
Show resolved
Hide resolved
|
||
#[clap(long, short)] | ||
version: bool, | ||
/// The chain config to be used as part of the call. | ||
#[clap(name = "config", long, default_value = "Polkadot")] | ||
config: String, | ||
|
@@ -90,55 +98,66 @@ impl StorageCommand { | |
{ | ||
let rpc = ContractStorageRpc::<C>::new(&self.url).await?; | ||
let storage_layout = ContractStorage::<C, C>::new(rpc); | ||
let contract = parse_account(&self.contract) | ||
.map_err(|e| anyhow::anyhow!("Failed to parse contract option: {}", e))?; | ||
|
||
if self.raw { | ||
let storage_data = | ||
storage_layout.load_contract_storage_data(&contract).await?; | ||
println!( | ||
"{json}", | ||
json = serde_json::to_string_pretty(&storage_data)? | ||
); | ||
return Ok(()) | ||
} | ||
|
||
let contract_artifacts = ContractArtifacts::from_manifest_or_file( | ||
self.manifest_path.as_ref(), | ||
self.file.as_ref(), | ||
); | ||
|
||
match contract_artifacts { | ||
Ok(contract_artifacts) => { | ||
let transcoder = contract_artifacts.contract_transcoder()?; | ||
let contract_storage = storage_layout | ||
.load_contract_storage_with_layout(&contract, &transcoder) | ||
.await?; | ||
if self.output_json { | ||
println!( | ||
"{json}", | ||
json = serde_json::to_string_pretty(&contract_storage)? | ||
); | ||
} else { | ||
let table = StorageDisplayTable::new(&contract_storage); | ||
table.display(); | ||
} | ||
} | ||
Err(_) => { | ||
eprintln!( | ||
"{} Displaying raw storage: no valid contract metadata artifacts found", | ||
"Info:".cyan().bold(), | ||
); | ||
if self.version { | ||
println!("{}", storage_layout.version().await?); | ||
Ok(()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please return early here to save us from the else indentation. |
||
} else { | ||
// Contract arg shall be always present in this case, it is enforced by | ||
// clap configuration | ||
let contract = self | ||
.contract | ||
.as_ref() | ||
.map(|c| parse_account(c)) | ||
.transpose()? | ||
.expect("Contract argument shall be present"); | ||
|
||
if self.raw { | ||
let storage_data = | ||
storage_layout.load_contract_storage_data(&contract).await?; | ||
println!( | ||
"{json}", | ||
json = serde_json::to_string_pretty(&storage_data)? | ||
); | ||
return Ok(()) | ||
} | ||
|
||
let contract_artifacts = ContractArtifacts::from_manifest_or_file( | ||
self.manifest_path.as_ref(), | ||
self.file.as_ref(), | ||
); | ||
|
||
match contract_artifacts { | ||
Ok(contract_artifacts) => { | ||
let transcoder = contract_artifacts.contract_transcoder()?; | ||
let contract_storage = storage_layout | ||
.load_contract_storage_with_layout(&contract, &transcoder) | ||
.await?; | ||
if self.output_json { | ||
println!( | ||
"{json}", | ||
json = serde_json::to_string_pretty(&contract_storage)? | ||
); | ||
} else { | ||
let table = StorageDisplayTable::new(&contract_storage); | ||
table.display(); | ||
} | ||
} | ||
Err(_) => { | ||
eprintln!( | ||
"{} Displaying raw storage: no valid contract metadata artifacts found", | ||
"Info:".cyan().bold(), | ||
); | ||
let storage_data = | ||
storage_layout.load_contract_storage_data(&contract).await?; | ||
println!( | ||
"{json}", | ||
json = serde_json::to_string_pretty(&storage_data)? | ||
); | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
Ok(()) | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ use sp_weights::Weight; | |
/// the `ContractsApi` version. Therefore when SCALE decoding a `ContractResult` its | ||
/// trailing data should be ignored to avoid any potential compatibility issues. | ||
#[derive(Clone, Eq, PartialEq, Encode, Decode, RuntimeDebug, TypeInfo)] | ||
pub struct ContractResult<R, Balance, EventRecord> { | ||
pub struct ContractResult<R, Balance> { | ||
/// How much weight was consumed during execution. | ||
pub gas_consumed: Weight, | ||
/// How much weight is required as gas limit in order to execute this call. | ||
|
@@ -78,21 +78,15 @@ pub struct ContractResult<R, Balance, EventRecord> { | |
pub debug_message: Vec<u8>, | ||
/// The execution result of the wasm code. | ||
pub result: R, | ||
/// The events that were emitted during execution. It is an option as event | ||
/// collection is optional. | ||
pub events: Option<Vec<EventRecord>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about chains that still have the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we do not use it in our code, so it is just not decoded from binary data. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where do the events depicted after calling/instantiating/etc. come from if not the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they come from https://github.com/paritytech/cargo-contract/blob/83600e4e0b0df1c804c8197049794da83daa3d3d/crates/extrinsics/src/lib.rs#L142 They are read from the block, please take a look at subxt function: |
||
} | ||
|
||
/// Result type of a `bare_call` call as well as `ContractsApi::call`. | ||
pub type ContractExecResult<Balance, EventRecord> = | ||
ContractResult<Result<ExecReturnValue, DispatchError>, Balance, EventRecord>; | ||
pub type ContractExecResult<Balance> = | ||
ContractResult<Result<ExecReturnValue, DispatchError>, Balance>; | ||
|
||
/// Result type of a `bare_instantiate` call as well as `ContractsApi::instantiate`. | ||
pub type ContractInstantiateResult<AccountId, Balance, EventRecord> = ContractResult< | ||
Result<InstantiateReturnValue<AccountId>, DispatchError>, | ||
Balance, | ||
EventRecord, | ||
>; | ||
pub type ContractInstantiateResult<AccountId, Balance> = | ||
ContractResult<Result<InstantiateReturnValue<AccountId>, DispatchError>, Balance>; | ||
|
||
/// Result type of a `bare_code_upload` call. | ||
pub type CodeUploadResult<CodeHash, Balance> = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.