Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
a4c4775
add info structure
lean-apple Feb 28, 2023
83e02db
add info import
lean-apple Feb 28, 2023
19c6dd8
change function call
lean-apple Feb 28, 2023
8657bb6
wip - fix some issues
lean-apple Mar 1, 2023
2f9bab1
fix client error
lean-apple Mar 1, 2023
3b13b04
fix: fix info_contract_call getter
lean-apple Mar 1, 2023
9cab620
remove from extrenstics condition
lean-apple Mar 2, 2023
32723ac
Decode bytes into type.
ascjones Mar 2, 2023
ef400f8
add first accountid handling
lean-apple Mar 3, 2023
ef22bb2
refactor contract info getter and decoder by using fetch
lean-apple Mar 3, 2023
835b38b
first draft for print in a good way contract ways
lean-apple Mar 3, 2023
a505dce
add integration test for info
lean-apple Mar 3, 2023
ad14610
remove extrenstics and add url flag for info command
lean-apple Mar 3, 2023
1c5c2e7
remove the useless check for accountId
lean-apple Mar 6, 2023
0de3eb4
add last changes
lean-apple Mar 6, 2023
26bfc36
add doc
lean-apple Mar 6, 2023
39dac30
fix fmt
lean-apple Mar 6, 2023
d96cc4a
update changelog
lean-apple Mar 6, 2023
357f66a
refactor: move out extrinstics info command
lean-apple Mar 6, 2023
e1fc3c6
add last changes
lean-apple Mar 6, 2023
3f1a13b
remove ignore comments for integration tests
lean-apple Mar 6, 2023
4b493a1
change output format for info command
lean-apple Mar 6, 2023
ca5509e
remove tracing debug in integration tests
lean-apple Mar 6, 2023
945206c
fix fmt
lean-apple Mar 6, 2023
2442dea
change trie id format
lean-apple Mar 7, 2023
9200774
fix fmt and format in a better way comments and output
lean-apple Mar 7, 2023
97c4c25
remove output_json
lean-apple Mar 7, 2023
95a5eba
fix fmt
lean-apple Mar 7, 2023
b68960b
fix fmt output for trie_id
lean-apple Mar 7, 2023
2b50898
change comments, docs and removing debug for inetgration tests
lean-apple Mar 7, 2023
3ee9892
complete doc
lean-apple Mar 7, 2023
8ac5b0d
docs: change minor term
lean-apple Mar 8, 2023
e173f02
first draft to add output_json flag
lean-apple Mar 8, 2023
311eb63
fix serde_json data to print
lean-apple Mar 9, 2023
c06c7d7
remove useless comments for tests and doc
lean-apple Mar 9, 2023
0b3f56d
Derive `Default` instances, make clippy happy :t-rex:
ascjones Mar 9, 2023
3741ef9
fix output-json result
lean-apple Mar 9, 2023
c9266a1
remove useless return + fmt
lean-apple Mar 9, 2023
934e7dd
update changelog + doc
lean-apple Mar 9, 2023
1bc5320
Merge branch 'master' into ln-info-prinstine-code
lean-apple Mar 9, 2023
a6a9e09
Merge branch ln-info-output-json into ln-info-prinstine-code
lean-apple Mar 9, 2023
034064c
Merge branch 'aj/clippy' into ln-info-prinstine-code
lean-apple Mar 9, 2023
3f8d00c
Merge branch 'ln-add-info-command' into ln-info-prinstine-code
lean-apple Mar 9, 2023
a252a41
first draft to print pristine_code
lean-apple Mar 9, 2023
5093738
fix fmt and clippy
lean-apple Mar 9, 2023
0a4250b
wip - second draft for binary flag
lean-apple Mar 13, 2023
a6809e7
merge last changes
lean-apple Mar 16, 2023
0571c81
wip - format ouput depending on the flag
lean-apple Mar 17, 2023
8e67cf6
optimize the display
lean-apple Mar 17, 2023
c704a51
fix fmt
lean-apple Mar 17, 2023
1ffbffa
fix master merge and restore changes
lean-apple Mar 17, 2023
793cb4a
add docs + first draft of test
lean-apple Mar 17, 2023
d0b18ce
complete tests
lean-apple Mar 20, 2023
fa22b0a
fix error merge
lean-apple Mar 20, 2023
c01759e
fix error merge
lean-apple Mar 20, 2023
bbb4f59
change to display only pristine code
lean-apple Mar 21, 2023
68a29b2
fix temporary test
lean-apple Mar 21, 2023
133aea6
fix fmt
lean-apple Mar 21, 2023
234b258
reimport items in binary outpuson
lean-apple Mar 21, 2023
2a357b5
Update crates/cargo-contract/src/cmd/info.rs
lean-apple Mar 23, 2023
91d883e
Update crates/cargo-contract/src/cmd/info.rs
lean-apple Mar 23, 2023
92ab29a
Merge branch 'master' into ln-info-prinstine-code
smiasojed Aug 31, 2023
c73fc53
Implemented combination of --binary and --output-json including code …
smiasojed Sep 4, 2023
71b4560
Merge remote-tracking branch 'origin/master' into ln-info-prinstine-code
smiasojed Sep 4, 2023
c3eb3fc
Removed BoundedVec from API
smiasojed Sep 4, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Adds workflow for publishing docker images for the verifiable builds - [#1267](https://github.com/paritytech/cargo-contract/pull/1267)
- Detect `INK_STATIC_BUFFER_SIZE` env var - [#1310](https://github.com/paritytech/cargo-contract/pull/1310)
- Add `verify` command - [#1306](https://github.com/paritytech/cargo-contract/pull/1306)
- Add `--binary` flag for `info` command - [#1311](https://github.com/paritytech/cargo-contract/pull/1311/)

## [4.0.0-alpha]

Expand Down
53 changes: 48 additions & 5 deletions crates/cargo-contract/src/cmd/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ use anyhow::{
};
use contract_extrinsics::{
fetch_contract_info,
fetch_wasm_code,
ErrorVariant,
};
use std::fmt::Debug;
use std::{
fmt::Debug,
io::Write,
};
use subxt::{
Config,
OnlineClient,
Expand All @@ -50,6 +54,9 @@ pub struct InfoCommand {
/// Export the instantiate output in JSON format.
#[clap(name = "output-json", long)]
output_json: bool,
/// Display the contract's Wasm bytecode.
Comment thread
ascjones marked this conversation as resolved.
#[clap(name = "binary", long)]
binary: bool,
}

impl InfoCommand {
Expand All @@ -67,10 +74,46 @@ impl InfoCommand {

match info_result {
Some(info_to_json) => {
if self.output_json {
println!("{}", info_to_json.to_json()?);
} else {
basic_display_format_contract_info(&info_to_json);
match (self.output_json, self.binary) {
(true, false) => println!("{}", info_to_json.to_json()?),
(false, false) => {
basic_display_format_contract_info(&info_to_json)
}
// Binary flag applied
(_, true) => {
let wasm_code =
fetch_wasm_code(*info_to_json.code_hash(), &client)
.await?;
match (wasm_code, self.output_json) {
(Some(code), false) => {
std::io::stdout()
.write_all(&code)
.expect("Writing to stdout failed")
}
(Some(code), true) => {
let wasm = serde_json::json!({
"wasm": format!("0x{}", hex::encode(code))
});
println!(
"{}",
serde_json::to_string_pretty(&wasm).map_err(
|err| {
anyhow!(
"JSON serialization failed: {}",
err
)
}
)?
);
}
(None, _) => {
return Err(anyhow!(
"Contract wasm code was not found"
)
.into())
}
}
}
}
Ok(())
}
Expand Down
31 changes: 29 additions & 2 deletions crates/extrinsics/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{
UploadCommandBuilder,
};
use anyhow::Result;
use contract_build::code_hash;
use predicates::prelude::*;
use std::{
ffi::OsStr,
Expand Down Expand Up @@ -358,15 +359,15 @@ async fn build_upload_instantiate_info() {
let contract_account = extract_contract_address(stdout);
assert_eq!(48, contract_account.len(), "{stdout:?}");

cargo_contract(project_path.as_path())
let output = cargo_contract(project_path.as_path())
.arg("info")
.args(["--contract", contract_account])
.output()
.expect("failed to execute process");
let stderr = str::from_utf8(&output.stderr).unwrap();
assert!(output.status.success(), "getting info failed: {stderr}");

cargo_contract(project_path.as_path())
let output = cargo_contract(project_path.as_path())
.arg("info")
.args(["--contract", contract_account])
.arg("--output-json")
Expand All @@ -378,6 +379,32 @@ async fn build_upload_instantiate_info() {
"getting info as JSON format failed: {stderr}"
);

let output = cargo_contract(project_path.as_path())
.arg("info")
.args(["--contract", contract_account])
.arg("--binary")
.output()
.expect("failed to execute process");
let stderr = str::from_utf8(&output.stderr).unwrap();
assert!(
output.status.success(),
"getting Wasm code failed: {stderr}"
);

// construct the contract file path
let contract_wasm = project_path.join("target/ink/flipper.wasm");

let code = std::fs::read(contract_wasm).expect("contract Wasm file not found");
assert_eq!(code_hash(&code), code_hash(&output.stdout));

cargo_contract(project_path.as_path())
.arg("info")
.args(["--contract", contract_account])
.arg("--output-json")
.arg("--binary")
.assert()
.stdout(predicate::str::contains(r#""wasm": "0x"#));

// prevent the node_process from being dropped and killed
let _ = node_process;
}
Expand Down
17 changes: 16 additions & 1 deletion crates/extrinsics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use jsonrpsee::{
};
use std::path::PathBuf;

use crate::runtime_api::api::{self,};
use crate::runtime_api::api;
use contract_build::{
CrateMetadata,
DEFAULT_KEY_COL_WIDTH,
Expand Down Expand Up @@ -363,6 +363,21 @@ impl ContractInfo {
}
}

/// Fetch the contract wasm code from the storage using the provided client and code hash.
pub async fn fetch_wasm_code(hash: CodeHash, client: &Client) -> Result<Option<Vec<u8>>> {
let pristine_code_address = api::storage().contracts().pristine_code(hash);

let pristine_bytes = client
.storage()
.at_latest()
.await?
.fetch(&pristine_code_address)
.await?
.map(|v| v.0);

Ok(pristine_bytes)
}

/// Copy of `pallet_contracts_primitives::StorageDeposit` which implements `Serialize`,
/// required for json output.
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, serde::Serialize)]
Expand Down
1 change: 1 addition & 0 deletions docs/info.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ cargo contract info \
*Optional*
- `--url` the url of the rpc endpoint you want to specify - by default `ws://localhost:9944`.
- `--output-json` to export the output as JSON.
- `--binary` outputs Wasm code as a binary blob. If used in combination with `--output-json`, outputs Wasm code as JSON object with hex string.