-
Notifications
You must be signed in to change notification settings - Fork 119
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
Add flag --all to cargo contract info #1319
Conversation
// Binary flag applied | ||
(_, true) => { | ||
let wasm_code = | ||
fetch_wasm_code(*info_to_json.code_hash(), &client).await?; |
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.
nit: using ok_or
may simplify code below by removing match.
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.
done
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.
Looks good. Just a few nitpicks and changes mainly to do with the coding style
// All flag applied | ||
if self.all { | ||
// 1000 is max allowed value | ||
const COUNT: u32 = 1000; |
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.
Nit:
const COUNT: u32 = 1000; | |
const MAX_COUNT: u32 = 1000; |
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.
Done
); | ||
pub async fn run(&self) -> Result<(), ErrorVariant> { | ||
let url = self.url.clone(); | ||
let client = OnlineClient::<DefaultConfig>::from_url(url).await?; |
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.
let client = OnlineClient::<DefaultConfig>::from_url(url).await?; | |
let client = OnlineClient::<DefaultConfig>::from_url(&self.url).await?; |
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.
Done
self.contract | ||
); | ||
pub async fn run(&self) -> Result<(), ErrorVariant> { | ||
let url = self.url.clone(); |
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.
let url = self.url.clone(); |
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.
Done
crates/extrinsics/src/lib.rs
Outdated
@@ -378,6 +384,42 @@ pub async fn fetch_wasm_code(hash: CodeHash, client: &Client) -> Result<Option<V | |||
Ok(pristine_bytes) | |||
} | |||
|
|||
/// Fetch all contracts addresses from the storage using the provided client and count of |
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.
/// Fetch all contracts addresses from the storage using the provided client and count of | |
/// Fetch all contract addresses from the storage using the provided client and count of |
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.
Done
crates/extrinsics/src/lib.rs
Outdated
pub async fn fetch_all_contracts( | ||
client: &Client, | ||
count: u32, | ||
from: Option<&AccountId32>, |
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.
from: Option<&AccountId32>, | |
count_from: Option<&AccountId32>, |
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.
Done
if self.all { | ||
// 1000 is max allowed value | ||
const COUNT: u32 = 1000; | ||
let mut from = None; |
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.
let mut from = None; | |
let mut count_from = None; |
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.
Done
crates/extrinsics/src/lib.rs
Outdated
.fetch_keys(key.as_ref(), count, start_key.as_deref()) | ||
.await?; | ||
|
||
// StorageKey is a concatention of contract_info_of root key and |
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.
// StorageKey is a concatention of contract_info_of root key and | |
// StorageKey is a concatenation of contract_info_of root key and |
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.
done
crates/extrinsics/src/lib.rs
Outdated
e.0.get(key.len() + 8..) | ||
.ok_or(anyhow!("Unexpected storage key size"))?; | ||
AccountId32::decode(&mut account) | ||
.map_err(|err| anyhow!("AccountId deserialization error: {}", err)) |
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.
I would extract it into a separate function for better readability
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.
Done
crates/cargo-contract/src/cmd/mod.rs
Outdated
pub fn display_all_contracts(contracts: &[<DefaultConfig as Config>::AccountId]) { | ||
contracts | ||
.iter() | ||
.for_each(|e: &<DefaultConfig as Config>::AccountId| { | ||
name_value_println!("Contract", format!("{}", e), MAX_KEY_COL_WIDTH); | ||
}) | ||
} |
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.
I would rewrite it to display the result something like:
Found contracts:
* <Address>
* <Address>
* <Address>
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.
I think that in case when we have more than 1000 contracts, it will be hard to see this line Found contracts
at the log beginning. I would opt to keep it as is. What do you think?
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.
Then I would enumerate them at least. Useful when you want to pipe the output into another bash command:
Found contracts:
1. <Address>
2. <Address>
...
1000. <Address>
It is up to you if you want to keep Found contracts:
or not.
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.
Useful when you want to pipe the output into another bash command
In this case it is best then to have only the list of contract addresses so instead of
Contract 5DpyotvcUDkFxTtHzkwR7Rqe37bdjc6M5Rxeiy57Gv2RQzp8
Contract 5GsoMKLTgFEpzHQTi7c4ZKCLZC6VxtHZxwMydSi79uemABez
have
5DpyotvcUDkFxTtHzkwR7Rqe37bdjc6M5Rxeiy57Gv2RQzp8
5GsoMKLTgFEpzHQTi7c4ZKCLZC6VxtHZxwMydSi79uemABez
I like it this way, unix command compatible.
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.
Agreed
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.
Done
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.
LGTM! Thanks
Closes #797
cargo info -all
is:Flags combination --binary --all is forbidden
Current implementation does not support response paging