Update to 2024 edition (#2001)

* Update to 2024 edition

* Update to 2024 edition; fmt, use<> and remove refs

* async functions
This commit is contained in:
James Wilson
2025-05-09 16:12:18 +01:00
committed by GitHub
parent 98c1d153b6
commit 23c62f3d5d
120 changed files with 399 additions and 322 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use crate::utils::{validate_url_security, FileOrUrl};
use crate::utils::{FileOrUrl, validate_url_security};
use clap::Parser as ClapParser;
use codec::Decode;
use color_eyre::eyre::eyre;
+3 -3
View File
@@ -5,11 +5,11 @@ use frame_metadata::RuntimeMetadataPrefixed;
use std::collections::HashMap;
use std::hash::Hash;
use crate::utils::{validate_url_security, FileOrUrl};
use crate::utils::{FileOrUrl, validate_url_security};
use color_eyre::owo_colors::OwoColorize;
use scale_info::form::PortableForm;
use scale_info::Variant;
use scale_info::form::PortableForm;
use subxt_metadata::{
ConstantMetadata, Metadata, PalletMetadata, RuntimeApiMetadata, StorageEntryMetadata,
@@ -441,7 +441,7 @@ fn diff<T, C: PartialEq, I: Hash + PartialEq + Eq + Ord>(
#[cfg(test)]
mod test {
use crate::commands::diff::{diff, Diff};
use crate::commands::diff::{Diff, diff};
#[test]
fn test_diff_fn() {
+16 -12
View File
@@ -1,6 +1,6 @@
use crate::utils::validate_url_security;
use crate::utils::FileOrUrl;
use clap::{command, Parser, Subcommand};
use crate::utils::validate_url_security;
use clap::{Parser, Subcommand, command};
use codec::Decode;
use color_eyre::eyre::eyre;
use color_eyre::owo_colors::OwoColorize;
@@ -447,18 +447,22 @@ pub mod tests {
run("--url wss://rpc.polkadot.io:443").await.unwrap();
// Errors, because the --allow-insecure is not set:
assert!(run("--url ws://rpc.polkadot.io:443")
.await
.unwrap_err()
.to_string()
.contains("is not secure"));
assert!(
run("--url ws://rpc.polkadot.io:443")
.await
.unwrap_err()
.to_string()
.contains("is not secure")
);
// This checks, that we never prevent (insecure) requests to localhost, even if the `--allow-insecure` flag is not set.
// It errors, because there is no node running locally, which results in the "Request error".
assert!(run("--url ws://localhost")
.await
.unwrap_err()
.to_string()
.contains("Request error"));
assert!(
run("--url ws://localhost")
.await
.unwrap_err()
.to_string()
.contains("Request error")
);
}
}
+4 -4
View File
@@ -10,14 +10,14 @@ use std::str::FromStr;
use subxt::tx;
use subxt::utils::H256;
use subxt::{
config::SubstrateConfig,
metadata::{types::PalletMetadata, Metadata},
OfflineClient,
config::SubstrateConfig,
metadata::{Metadata, types::PalletMetadata},
};
use crate::utils::{
fields_composite_example, fields_description, parse_string_into_scale_value, Indent,
SyntaxHighlight,
Indent, SyntaxHighlight, fields_composite_example, fields_description,
parse_string_into_scale_value,
};
#[derive(Debug, Clone, Args)]
@@ -2,9 +2,9 @@ use clap::Args;
use color_eyre::eyre::eyre;
use indoc::{formatdoc, writedoc};
use scale_typegen_description::type_description;
use subxt::metadata::{types::PalletMetadata, Metadata};
use subxt::metadata::{Metadata, types::PalletMetadata};
use crate::utils::{first_paragraph_of_docs, format_scale_value, Indent, SyntaxHighlight};
use crate::utils::{Indent, SyntaxHighlight, first_paragraph_of_docs, format_scale_value};
#[derive(Debug, Clone, Args)]
pub struct ConstantsSubcommand {
+3 -3
View File
@@ -1,10 +1,10 @@
use clap::Args;
use color_eyre::eyre::eyre;
use indoc::{formatdoc, writedoc};
use scale_info::{form::PortableForm, Variant};
use subxt::metadata::{types::PalletMetadata, Metadata};
use scale_info::{Variant, form::PortableForm};
use subxt::metadata::{Metadata, types::PalletMetadata};
use crate::utils::{fields_description, first_paragraph_of_docs, Indent};
use crate::utils::{Indent, fields_description, first_paragraph_of_docs};
#[derive(Debug, Clone, Args)]
pub struct EventsSubcommand {
+2 -2
View File
@@ -4,12 +4,12 @@ use indoc::writedoc;
use subxt::Metadata;
use subxt_metadata::PalletMetadata;
use crate::utils::{first_paragraph_of_docs, FileOrUrl, Indent};
use crate::utils::{FileOrUrl, Indent, first_paragraph_of_docs};
use self::{
calls::CallsSubcommand,
constants::ConstantsSubcommand,
events::{explore_events, EventsSubcommand},
events::{EventsSubcommand, explore_events},
storage::StorageSubcommand,
};
+6 -4
View File
@@ -12,14 +12,14 @@ use std::write;
use subxt::{
ext::scale_encode::EncodeAsType,
metadata::{
types::{PalletMetadata, StorageEntryType, StorageMetadata},
Metadata,
types::{PalletMetadata, StorageEntryType, StorageMetadata},
},
};
use crate::utils::{
create_client, first_paragraph_of_docs, parse_string_into_scale_value, type_example, FileOrUrl,
Indent, SyntaxHighlight,
FileOrUrl, Indent, SyntaxHighlight, create_client, first_paragraph_of_docs,
parse_string_into_scale_value, type_example,
};
#[derive(Debug, Clone, Args)]
@@ -151,7 +151,9 @@ pub async fn explore_storage(
let storage_entry_keys: Vec<Value> = match (trailing_args.is_empty(), key_ty_id) {
(false, None) => {
let warning = format!("Warning: You submitted a key, but no key is needed: \"{trailing_args}\". To access the storage value, please do not provide any key.");
let warning = format!(
"Warning: You submitted a key, but no key is needed: \"{trailing_args}\". To access the storage value, please do not provide any key."
);
writeln!(output, "{}", warning.yellow())?;
return Ok(());
}
+7 -4
View File
@@ -1,6 +1,6 @@
use crate::utils::{
create_client, fields_composite_example, fields_description, first_paragraph_of_docs,
parse_string_into_scale_value, FileOrUrl, Indent, SyntaxHighlight,
FileOrUrl, Indent, SyntaxHighlight, create_client, fields_composite_example,
fields_description, first_paragraph_of_docs, parse_string_into_scale_value,
};
use color_eyre::{
@@ -12,8 +12,8 @@ use indoc::{formatdoc, writedoc};
use scale_typegen_description::type_description;
use scale_value::Value;
use subxt::{
ext::{scale_decode::DecodeAsType, scale_encode::EncodeAsType},
Metadata,
ext::{scale_decode::DecodeAsType, scale_encode::EncodeAsType},
};
use subxt_metadata::RuntimeApiMetadata;
@@ -144,7 +144,10 @@ pub async fn run<'a>(
}
if trailing_args.len() != method.inputs().len() {
bail!("The number of trailing arguments you provided after the `execute` flag does not match the expected number of inputs!\n{}", execute_usage());
bail!(
"The number of trailing arguments you provided after the `execute` flag does not match the expected number of inputs!\n{}",
execute_usage()
);
}
// encode each provided input as bytes of the correct type:
+4 -2
View File
@@ -2,7 +2,7 @@
// This file is dual-licensed as Apache-2.0 or GPL-3.0.
// see LICENSE for license details.
use crate::utils::{validate_url_security, FileOrUrl};
use crate::utils::{FileOrUrl, validate_url_security};
use clap::Parser as ClapParser;
use codec::{Decode, Encode};
use color_eyre::eyre::{self, bail};
@@ -62,7 +62,9 @@ pub async fn run(opts: Opts, output: &mut impl Write) -> color_eyre::Result<()>
RuntimeMetadata::V15(md) => md.strip_metadata(keep_pallets_fn, keep_runtime_apis_fn),
RuntimeMetadata::V16(md) => md.strip_metadata(keep_pallets_fn, keep_runtime_apis_fn),
_ => {
bail!("Unsupported metadata version for stripping pallets/runtime APIs: V14, V15 or V16 metadata is expected.")
bail!(
"Unsupported metadata version for stripping pallets/runtime APIs: V14, V15 or V16 metadata is expected."
)
}
}
}
+3 -1
View File
@@ -313,7 +313,9 @@ pub fn validate_url_security(url: Option<&Url>, allow_insecure: bool) -> color_e
match subxt::utils::url_is_secure(url.as_str()) {
Ok(is_secure) => {
if !allow_insecure && !is_secure {
bail!("URL {url} is not secure!\nIf you are really want to use this URL, try using --allow-insecure (-a)");
bail!(
"URL {url} is not secure!\nIf you are really want to use this URL, try using --allow-insecure (-a)"
);
}
}
Err(err) => {