From 260d6bafdb9efbdfc272e78b836c280c4c30af0b Mon Sep 17 00:00:00 2001 From: Ranadeep Biswas Date: Mon, 4 Mar 2024 14:30:50 +0100 Subject: [PATCH] use nightly fmt --- rustfmt.toml | 5 +++++ src/account.rs | 41 +++++++++++++++++------------------------ src/broadcast.rs | 10 ++++------ src/cli/mod.rs | 14 ++++++-------- src/cli/tx.rs | 26 +++++++++++--------------- src/cli/utils.rs | 2 +- src/endpoint.rs | 13 +++++-------- src/keys.rs | 16 +++++++--------- src/ledger.rs | 5 +---- src/msg.rs | 10 ++++------ src/query.rs | 24 +++++++++--------------- src/txs.rs | 22 +++++++--------------- src/utils.rs | 6 ++++-- src/vanity.rs | 16 ++++++++-------- 14 files changed, 89 insertions(+), 121 deletions(-) create mode 100644 rustfmt.toml diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..e9e7427 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,5 @@ +reorder_imports = true + +# unstable features +group_imports = "StdExternalCrate" +imports_granularity = "Module" diff --git a/src/account.rs b/src/account.rs index 5a6871c..5210830 100644 --- a/src/account.rs +++ b/src/account.rs @@ -1,31 +1,24 @@ -use cosmos_sdk_proto::cosmos::{ - crypto::secp256k1::PubKey, - tx::{ - signing::v1beta1::SignMode, - v1beta1::{Tx, TxBody}, - }, -}; -use cosmos_sdk_proto::prost_wkt_types::Any; use std::str::FromStr; -use crate::{ - keys::{ - from_pk_bytes_to_address, get_priv_key_from_memory, get_priv_key_from_os, - get_uncompressed_pub_key_from_memory, get_uncompressed_pub_key_from_os, AddressType, - }, - ledger::{get_pub_key, get_signature}, - txs::{ - create_transaction, generate_auth_info, generate_legacy_amino_json, - get_account_number_and_sequence, - }, - Result, +use bip32::secp256k1::ecdsa::signature::Signer; +use bip32::secp256k1::ecdsa::{Signature, VerifyingKey}; +use bip32::{DerivationPath, PrivateKey, PublicKey}; +use cosmos_sdk_proto::cosmos::crypto::secp256k1::PubKey; +use cosmos_sdk_proto::cosmos::tx::signing::v1beta1::SignMode; +use cosmos_sdk_proto::cosmos::tx::v1beta1::{Tx, TxBody}; +use cosmos_sdk_proto::prost_wkt_types::Any; +use serde::{Deserialize, Serialize}; + +use crate::keys::{ + from_pk_bytes_to_address, get_priv_key_from_memory, get_priv_key_from_os, + get_uncompressed_pub_key_from_memory, get_uncompressed_pub_key_from_os, AddressType, }; -use bip32::{secp256k1::ecdsa::VerifyingKey, DerivationPath, PublicKey}; -use bip32::{ - secp256k1::ecdsa::{signature::Signer, Signature}, - PrivateKey, +use crate::ledger::{get_pub_key, get_signature}; +use crate::txs::{ + create_transaction, generate_auth_info, generate_legacy_amino_json, + get_account_number_and_sequence, }; -use serde::{Deserialize, Serialize}; +use crate::Result; #[derive(Serialize, Deserialize, Debug, Clone)] pub enum KeyStoreBackend { diff --git a/src/broadcast.rs b/src/broadcast.rs index 334d50a..83b0d62 100644 --- a/src/broadcast.rs +++ b/src/broadcast.rs @@ -1,18 +1,16 @@ use anyhow::Context; use cosmos_sdk_proto::cosmos::base::abci::v1beta1::TxResponse; +use cosmos_sdk_proto::cosmos::tx::v1beta1::service_client::ServiceClient; use cosmos_sdk_proto::cosmos::tx::v1beta1::{ - service_client::ServiceClient, BroadcastTxRequest, BroadcastTxResponse, + BroadcastMode, BroadcastTxRequest, BroadcastTxResponse, SimulateRequest, SimulateResponse, Tx, }; -use cosmos_sdk_proto::cosmos::tx::v1beta1::{BroadcastMode, SimulateRequest, SimulateResponse, Tx}; - use cosmos_sdk_proto::prost_wkt_types::MessageSerde; - -use crate::Result; - use serde::Serialize; use tendermint_rpc::endpoint::broadcast::tx_sync::Response as TendermintResponse; use tendermint_rpc::{Client, HttpClient}; +use crate::Result; + pub fn create_broadcast_sync_payload(tx: &Tx) -> Result { Ok(BroadcastTxRequest { tx_bytes: tx.try_encoded()?, diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 803d598..e563979 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -4,14 +4,12 @@ use anyhow::Context; use clap::Parser; use cosmos_sdk_proto::cosmos::base::v1beta1::Coin; -use crate::{ - account::{Account, KeyStoreBackend}, - endpoint::{get_rpc_endpoints, transform_to_grpc_endpoint}, - keys::{save_key_to_os_from_mmseed, AddressType}, - query::{get_chain_id_info, get_chain_id_rpc, get_rpc_endpoint_chain_info}, - utils::{read_data_from_yaml, write_data_as_yaml}, - Result, -}; +use crate::account::{Account, KeyStoreBackend}; +use crate::endpoint::{get_rpc_endpoints, transform_to_grpc_endpoint}; +use crate::keys::{save_key_to_os_from_mmseed, AddressType}; +use crate::query::{get_chain_id_info, get_chain_id_rpc, get_rpc_endpoint_chain_info}; +use crate::utils::{read_data_from_yaml, write_data_as_yaml}; +use crate::Result; pub mod tx; pub mod utils; diff --git a/src/cli/tx.rs b/src/cli/tx.rs index e0f77e6..1bdc8f5 100644 --- a/src/cli/tx.rs +++ b/src/cli/tx.rs @@ -1,26 +1,22 @@ use std::collections::HashMap; -use crate::endpoint::get_cosmos_directory_name; -use crate::txs::get_account_number_and_sequence; -use crate::{ - account::Account, endpoint::get_rpc_endpoints, msg::generate_grant_exec, - utils::read_data_from_yaml, Result, -}; use anyhow::Context; use clap::Subcommand; +use cosmos_sdk_proto::cosmos::base::v1beta1::Coin; +use cosmos_sdk_proto::cosmos::gov::v1beta1::MsgVote; +use cosmos_sdk_proto::cosmos::staking::v1beta1::{MsgBeginRedelegate, MsgDelegate}; +use cosmos_sdk_proto::cosmwasm::wasm::v1::MsgExecuteContract; +use cosmos_sdk_proto::ibc::applications::transfer::v1::MsgTransfer; use cosmos_sdk_proto::prost_wkt_types::Any; -use cosmos_sdk_proto::{ - cosmos::{ - base::v1beta1::Coin, - gov::v1beta1::MsgVote, - staking::v1beta1::{MsgBeginRedelegate, MsgDelegate}, - }, - cosmwasm::wasm::v1::MsgExecuteContract, - ibc::applications::transfer::v1::MsgTransfer, -}; use futures::StreamExt; use super::utils::{custom_coin, custom_io_string, VotePair}; +use crate::account::Account; +use crate::endpoint::{get_cosmos_directory_name, get_rpc_endpoints}; +use crate::msg::generate_grant_exec; +use crate::txs::get_account_number_and_sequence; +use crate::utils::read_data_from_yaml; +use crate::Result; #[derive(Subcommand, Debug)] pub enum Transaction { diff --git a/src/cli/utils.rs b/src/cli/utils.rs index 52d2747..caf8adc 100644 --- a/src/cli/utils.rs +++ b/src/cli/utils.rs @@ -1,3 +1,4 @@ +use std::io::BufRead; use std::str::FromStr; use anyhow::Context; @@ -6,7 +7,6 @@ use cosmos_sdk_proto::cosmos::gov::v1beta1::VoteOption; use crate::account::KeyStoreBackend; use crate::Result; -use std::io::BufRead; pub fn custom_keystorebackend(backend_str: &str) -> Result { Ok(if backend_str == "Ledger" { diff --git a/src/endpoint.rs b/src/endpoint.rs index f2a826c..cda1d15 100644 --- a/src/endpoint.rs +++ b/src/endpoint.rs @@ -1,16 +1,13 @@ -use crate::{ - query::{validate_grpc, validate_rpc}, - Result, -}; - use anyhow::Context; - use futures::future::join_all; -use serde::{de::Error, Deserialize, Deserializer, Serialize}; +use serde::de::Error; +use serde::{Deserialize, Deserializer, Serialize}; use serde_json::Value; - use url::Url; +use crate::query::{validate_grpc, validate_rpc}; +use crate::Result; + #[derive(Debug, Deserialize)] pub struct ZoneNodes { pub zone_nodes: Vec, diff --git a/src/keys.rs b/src/keys.rs index 1ad2fa3..42627ef 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -1,21 +1,19 @@ +use std::collections::HashMap; use std::str::FromStr; use std::sync::{Arc, Mutex}; use anyhow::Context; -use bip32::{secp256k1::ecdsa::SigningKey, DerivationPath, Language, Mnemonic, XPrv}; -use clap::ValueEnum; -use secp256k1::{PublicKey, Secp256k1, SecretKey}; - -use std::collections::HashMap; - -use crate::Result; - use base64::prelude::{Engine as _, BASE64_STANDARD}; +use bech32::{Bech32, Hrp}; +use bip32::secp256k1::ecdsa::SigningKey; +use bip32::{DerivationPath, Language, Mnemonic, XPrv}; +use clap::ValueEnum; use ripemd::Ripemd160; +use secp256k1::{PublicKey, Secp256k1, SecretKey}; use sha2::{Digest, Sha256}; use sha3::Keccak256; -use bech32::{Bech32, Hrp}; +use crate::Result; // https://iancoleman.io/bip39 diff --git a/src/ledger.rs b/src/ledger.rs index 639e214..3fa0bc1 100644 --- a/src/ledger.rs +++ b/src/ledger.rs @@ -1,10 +1,7 @@ use anyhow::Context; use bip32::DerivationPath; - -use ledger_transport_hid::{hidapi, TransportNativeHID}; - use ledger_transport::{APDUCommand, APDUErrorCode}; - +use ledger_transport_hid::{hidapi, TransportNativeHID}; use serde_json::Value; use crate::Result; diff --git a/src/msg.rs b/src/msg.rs index a3cb8fb..f8a0e8f 100644 --- a/src/msg.rs +++ b/src/msg.rs @@ -4,9 +4,6 @@ use cosmos_sdk_proto::cosmos::authz::v1beta1::{ }; use cosmos_sdk_proto::cosmos::bank::v1beta1::MsgSend; use cosmos_sdk_proto::cosmos::base::v1beta1::Coin; -use cosmos_sdk_proto::cosmos::staking::v1beta1::stake_authorization::{Policy, Validators}; -use cosmos_sdk_proto::cosmos::staking::v1beta1::{AuthorizationType, StakeAuthorization}; - use cosmos_sdk_proto::cosmos::distribution::v1beta1::{ MsgWithdrawDelegatorReward, QueryDelegationTotalRewardsRequest, QueryDelegationTotalRewardsResponse, @@ -14,10 +11,11 @@ use cosmos_sdk_proto::cosmos::distribution::v1beta1::{ use cosmos_sdk_proto::cosmos::feegrant::v1beta1::{ BasicAllowance, MsgGrantAllowance, MsgRevokeAllowance, }; - use cosmos_sdk_proto::cosmos::gov::v1beta1::MsgVote; -use cosmos_sdk_proto::cosmos::staking::v1beta1::MsgDelegate; - +use cosmos_sdk_proto::cosmos::staking::v1beta1::stake_authorization::{Policy, Validators}; +use cosmos_sdk_proto::cosmos::staking::v1beta1::{ + AuthorizationType, MsgDelegate, StakeAuthorization, +}; use cosmos_sdk_proto::prost_wkt_types::{Any, MessageSerde}; use crate::query::perform_rpc_query; diff --git a/src/query.rs b/src/query.rs index 2806492..0528ddb 100644 --- a/src/query.rs +++ b/src/query.rs @@ -1,28 +1,22 @@ use anyhow::Context; -use cosmos_sdk_proto::cosmos::bank::v1beta1::{ - query_client::QueryClient as QueryTotalSupplyClient, QueryTotalSupplyRequest, - QueryTotalSupplyResponse, -}; -use cosmos_sdk_proto::cosmos::base::query::v1beta1::PageRequest; -use cosmos_sdk_proto::cosmos::vesting::v1beta1::ContinuousVestingAccount; -use cosmos_sdk_proto::prost_wkt_types::{Any, MessageSerde}; - use cosmos_sdk_proto::cosmos::auth::v1beta1::{ BaseAccount, QueryAccountRequest, QueryAccountResponse, QueryAccountsRequest, QueryAccountsResponse, }; - +use cosmos_sdk_proto::cosmos::bank::v1beta1::query_client::QueryClient as QueryTotalSupplyClient; +use cosmos_sdk_proto::cosmos::bank::v1beta1::{QueryTotalSupplyRequest, QueryTotalSupplyResponse}; +use cosmos_sdk_proto::cosmos::base::query::v1beta1::PageRequest; +use cosmos_sdk_proto::cosmos::vesting::v1beta1::ContinuousVestingAccount; +use cosmos_sdk_proto::prost_wkt_types::{Any, MessageSerde}; +use futures::stream::StreamExt; use serde_json::Value; -use tracing::info; - -use crate::endpoint::get_rpc_endpoints; -use crate::Result; - use tendermint::abci::response::Info; use tendermint_rpc::endpoint::status::Response as NodeStatus; use tendermint_rpc::Client; +use tracing::info; -use futures::stream::StreamExt; +use crate::endpoint::get_rpc_endpoints; +use crate::Result; pub async fn perform_rpc_query(endpoint: &str, query: S) -> Result where diff --git a/src/txs.rs b/src/txs.rs index a272bf1..01a78bf 100644 --- a/src/txs.rs +++ b/src/txs.rs @@ -1,23 +1,15 @@ use anyhow::Context; -use bip32::secp256k1::ecdsa::signature::SignatureEncoding; -use bip32::secp256k1::ecdsa::{signature::Signer, signature::Verifier, Signature}; - -use cosmos_sdk_proto::cosmos::tx::v1beta1::{AuthInfo, TxBody}; -use cosmos_sdk_proto::cosmos::vesting::v1beta1::ContinuousVestingAccount; -use cosmos_sdk_proto::cosmos::{ - auth::v1beta1::BaseAccount, - crypto::secp256k1::PubKey, - tx::v1beta1::{Fee, ModeInfo, SignDoc, Tx}, -}; - +use bip32::secp256k1::ecdsa::signature::{SignatureEncoding, Signer, Verifier}; +use bip32::secp256k1::ecdsa::Signature; +use cosmos_sdk_proto::cosmos::auth::v1beta1::BaseAccount; use cosmos_sdk_proto::cosmos::base::v1beta1::Coin; - +use cosmos_sdk_proto::cosmos::crypto::secp256k1::PubKey; use cosmos_sdk_proto::cosmos::tx::signing::v1beta1::SignMode; +use cosmos_sdk_proto::cosmos::tx::v1beta1::mode_info::{Single, Sum}; use cosmos_sdk_proto::cosmos::tx::v1beta1::{ - mode_info::{Single, Sum}, - SignerInfo, + AuthInfo, Fee, ModeInfo, SignDoc, SignerInfo, Tx, TxBody, }; - +use cosmos_sdk_proto::cosmos::vesting::v1beta1::ContinuousVestingAccount; use cosmos_sdk_proto::prost_wkt_types::{Any, MessageSerde}; use serde_json::Value; diff --git a/src/utils.rs b/src/utils.rs index 10d712c..7b62ec3 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,10 +1,12 @@ -use crate::Result; use base64::prelude::{Engine as _, BASE64_STANDARD}; use bech32::{Bech32, Hrp}; use cosmos_sdk_proto::prost_wkt_types::MessageSerde; -use serde::{de::DeserializeOwned, Serialize}; +use serde::de::DeserializeOwned; +use serde::Serialize; use serde_json::Value; +use crate::Result; + pub fn write_base64_to_file(t: &T, file_name: &str) -> Result<()> where T: MessageSerde, diff --git a/src/vanity.rs b/src/vanity.rs index 19c58fc..47562bc 100644 --- a/src/vanity.rs +++ b/src/vanity.rs @@ -1,14 +1,14 @@ -use std::{ - sync::{atomic::Ordering, Arc, RwLock}, - time::SystemTime, -}; +use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::{Arc, RwLock}; +use std::time::SystemTime; -use crate::keys::mnemonic_to_cosmos_addr; -use crate::Result; use anyhow::Context; -use bip32::{secp256k1::elliptic_curve::rand_core::OsRng, Language, Mnemonic}; +use bip32::secp256k1::elliptic_curve::rand_core::OsRng; +use bip32::{Language, Mnemonic}; use rayon::prelude::*; -use std::sync::atomic::AtomicU64; + +use crate::keys::mnemonic_to_cosmos_addr; +use crate::Result; pub fn find_parallel(vanity_prefix: &str, coin_type: &u64) -> Result<(String, Mnemonic)> { // https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#bech32