diff --git a/lib/cli.rs b/lib/cli.rs index 7415624d..c4d22f85 100644 --- a/lib/cli.rs +++ b/lib/cli.rs @@ -235,8 +235,7 @@ pub async fn query_global_state( let rpc_id = parse::rpc_id(maybe_rpc_id); let verbosity = parse::verbosity(verbosity_level); let global_state_identifier = - parse::global_state_identifier(maybe_block_id, maybe_state_root_hash)? - .ok_or(CliError::FailedToParseStateIdentifier)?; + parse::global_state_identifier(maybe_block_id, maybe_state_root_hash)?; let key = parse::key_for_query(key)?; let path = if path.is_empty() { vec![] diff --git a/lib/cli/error.rs b/lib/cli/error.rs index 7d6d1a6b..0cca9e6b 100644 --- a/lib/cli/error.rs +++ b/lib/cli/error.rs @@ -13,7 +13,7 @@ pub use uint::FromDecStrErr; use crate::cli::JsonArgsError; #[cfg(doc)] -use crate::rpcs::{DictionaryItemIdentifier, GlobalStateIdentifier}; +use crate::rpcs::DictionaryItemIdentifier; /// Error that can be returned by the `cli` API. #[derive(Error, Debug)] diff --git a/lib/cli/parse.rs b/lib/cli/parse.rs index de93f7d4..793ea70c 100644 --- a/lib/cli/parse.rs +++ b/lib/cli/parse.rs @@ -733,6 +733,10 @@ pub(super) fn global_state_identifier( maybe_block_id: &str, maybe_state_root_hash: &str, ) -> Result, CliError> { + if maybe_state_root_hash.is_empty() && maybe_block_id.is_empty() { + return Ok(None); + } + match block_identifier(maybe_block_id)? { Some(BlockIdentifier::Hash(hash)) => { return Ok(Some(GlobalStateIdentifier::BlockHash(hash))) diff --git a/lib/lib.rs b/lib/lib.rs index 7a5687d1..9e00acf2 100644 --- a/lib/lib.rs +++ b/lib/lib.rs @@ -440,7 +440,7 @@ pub async fn query_global_state( rpc_id: JsonRpcId, node_address: &str, verbosity: Verbosity, - global_state_identifier: GlobalStateIdentifier, + global_state_identifier: Option, key: Key, path: Vec, ) -> Result, Error> { diff --git a/lib/rpcs.rs b/lib/rpcs.rs index fd776795..ca3da80e 100644 --- a/lib/rpcs.rs +++ b/lib/rpcs.rs @@ -17,5 +17,4 @@ pub use v2_0_0::{ get_entity::{AddressableEntity, EntityIdentifier, EntityOrAccount}, get_reward::EraIdentifier, query_balance::PurseIdentifier, - query_global_state::GlobalStateIdentifier, }; diff --git a/lib/rpcs/v1_5_0.rs b/lib/rpcs/v1_5_0.rs index 90f7c2c4..4b940801 100644 --- a/lib/rpcs/v1_5_0.rs +++ b/lib/rpcs/v1_5_0.rs @@ -87,11 +87,4 @@ pub(crate) mod put_deploy { pub(crate) use crate::rpcs::v1_4_5::put_deploy::{PutDeployParams, PUT_DEPLOY_METHOD}; } -pub(crate) mod query_global_state { - pub use crate::rpcs::v1_4_5::query_global_state::{ - GlobalStateIdentifier, QueryGlobalStateResult, - }; - pub(crate) use crate::rpcs::v1_4_5::query_global_state::{ - QueryGlobalStateParams, QUERY_GLOBAL_STATE_METHOD, - }; -} +pub(crate) mod query_global_state {} diff --git a/lib/rpcs/v1_6_0.rs b/lib/rpcs/v1_6_0.rs index 947ea5e6..3f9d4ad8 100644 --- a/lib/rpcs/v1_6_0.rs +++ b/lib/rpcs/v1_6_0.rs @@ -2,8 +2,9 @@ pub(crate) mod get_account; -// The following RPCs are all unchanged from v1.5.0, so we just re-export them. +pub mod query_global_state; +// The following RPCs are all unchanged from v1.5.0, so we just re-export them. pub(crate) mod get_chainspec { pub use crate::rpcs::v1_5_0::get_chainspec::GetChainspecResult; pub(crate) use crate::rpcs::v1_5_0::get_chainspec::GET_CHAINSPEC_METHOD; @@ -109,12 +110,3 @@ pub(crate) mod put_deploy { pub use crate::rpcs::v1_5_0::put_deploy::PutDeployResult; pub(crate) use crate::rpcs::v1_5_0::put_deploy::{PutDeployParams, PUT_DEPLOY_METHOD}; } - -pub(crate) mod query_global_state { - pub use crate::rpcs::v1_5_0::query_global_state::{ - GlobalStateIdentifier, QueryGlobalStateResult, - }; - pub(crate) use crate::rpcs::v1_5_0::query_global_state::{ - QueryGlobalStateParams, QUERY_GLOBAL_STATE_METHOD, - }; -} diff --git a/lib/rpcs/v1_6_0/query_global_state.rs b/lib/rpcs/v1_6_0/query_global_state.rs index c9472974..145c2a79 100644 --- a/lib/rpcs/v1_6_0/query_global_state.rs +++ b/lib/rpcs/v1_6_0/query_global_state.rs @@ -1,12 +1,9 @@ use serde::{Deserialize, Serialize}; -use casper_types::{Key, ProtocolVersion}; +use casper_types::{BlockHeader, Key, ProtocolVersion, StoredValue}; +use crate::rpcs::common::GlobalStateIdentifier; pub(crate) use crate::rpcs::v1_4_5::query_global_state::QUERY_GLOBAL_STATE_METHOD; -use crate::{ - rpcs::common::GlobalStateIdentifier, - types::{BlockHeader, StoredValue}, -}; #[cfg(doc)] use crate::BlockIdentifier; diff --git a/lib/rpcs/v2_0_0.rs b/lib/rpcs/v2_0_0.rs index a5385507..23ccb3da 100644 --- a/lib/rpcs/v2_0_0.rs +++ b/lib/rpcs/v2_0_0.rs @@ -89,11 +89,10 @@ pub(crate) mod put_deploy { pub(crate) use crate::rpcs::v1_6_0::put_deploy::{PutDeployParams, PUT_DEPLOY_METHOD}; } -pub(crate) mod query_global_state { - pub use crate::rpcs::v1_6_0::query_global_state::{ - GlobalStateIdentifier, QueryGlobalStateResult, - }; +pub mod query_global_state { pub(crate) use crate::rpcs::v1_6_0::query_global_state::{ QueryGlobalStateParams, QUERY_GLOBAL_STATE_METHOD, }; + + pub use crate::rpcs::v1_6_0::query_global_state::QueryGlobalStateResult; } diff --git a/lib/rpcs/v2_0_0/query_balance_details.rs b/lib/rpcs/v2_0_0/query_balance_details.rs index eced8d69..fc634edb 100644 --- a/lib/rpcs/v2_0_0/query_balance_details.rs +++ b/lib/rpcs/v2_0_0/query_balance_details.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use casper_types::{BlockTime, ProtocolVersion, U512}; -use crate::rpcs::{GlobalStateIdentifier, PurseIdentifier}; +use crate::rpcs::{common::GlobalStateIdentifier, PurseIdentifier}; pub(crate) const QUERY_BALANCE_DETAILS_METHOD: &str = "query_balance_details"; diff --git a/src/main.rs b/src/main.rs index b93d6eb9..d6e0dd69 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,7 +23,6 @@ mod query_balance; mod query_balance_details; mod query_global_state; mod transaction; -mod verify_contract; use std::process; @@ -61,8 +60,6 @@ use query_global_state::QueryGlobalState; use transaction::{ ListTransactions, MakeTransaction, PutTransaction, SendTransaction, SignTransaction, }; -use verify_contract::VerifyContract; - const APP_NAME: &str = "Casper client"; static VERSION: Lazy = @@ -117,7 +114,6 @@ enum DisplayOrder { Keygen, AccountAddress, GenerateCompletion, - VerifyContract, } fn cli() -> Command { @@ -182,7 +178,6 @@ fn cli() -> Command { .subcommand(GenerateCompletion::build( DisplayOrder::GenerateCompletion as usize, )) - .subcommand(VerifyContract::build(DisplayOrder::VerifyContract as usize)) } #[tokio::main(flavor = "current_thread")] @@ -231,7 +226,6 @@ async fn main() { Keygen::NAME => Keygen::run(matches).await, AccountAddress::NAME => AccountAddress::run(matches).await, GenerateCompletion::NAME => GenerateCompletion::run(matches).await, - VerifyContract::NAME => VerifyContract::run(matches).await, _ => { let _ = cli().print_long_help(); println!(); diff --git a/src/verify_contract.rs b/src/verify_contract.rs deleted file mode 100644 index 5cf9110d..00000000 --- a/src/verify_contract.rs +++ /dev/null @@ -1,103 +0,0 @@ -use std::str; - -use async_trait::async_trait; -use casper_client::cli::CliError; -use clap::{ArgMatches, Command}; - -use crate::{command::ClientCommand, common, Success}; - -pub struct VerifyContract; - -/// This struct defines the order in which the args are shown for this subcommand's help message. -enum DisplayOrder { - Verbose, - TransactionHash, - VerificationUrlBasePath, - VerificationProjectPath, -} - -mod verification_url_base_path { - use clap::{Arg, ArgMatches}; - - static ARG_NAME: &str = "verification-url-basepath"; - - pub fn arg(order: usize) -> Arg { - Arg::new(ARG_NAME) - .long(ARG_NAME) - .short('u') - .required(false) - .default_value("http://localhost:8080") - .value_name("HOST:PORT") - .help("Hostname or IP and port of the verification API") - .display_order(order) - } - - pub fn get(matches: &ArgMatches) -> &str { - matches - .get_one::(ARG_NAME) - .map(String::as_str) - .unwrap_or_else(|| panic!("should have {ARG_NAME} arg")) - } -} - -mod verification_project_path { - use clap::{Arg, ArgMatches}; - - static ARG_NAME: &str = "verification-source-code-path"; - - pub fn arg(order: usize) -> Arg { - Arg::new(ARG_NAME) - .long(ARG_NAME) - .short('p') - .required(false) - .value_name("PATH") - .help("Source code path") - .display_order(order) - } - - pub fn get(matches: &ArgMatches) -> Option<&str> { - matches.get_one::(ARG_NAME).map(String::as_str) - } -} - -#[async_trait] -impl ClientCommand for VerifyContract { - const NAME: &'static str = "verify-contract"; - const ABOUT: &'static str = - "Verifies a smart contracts source code using verification service. \ - The source code will be uploaded, built, and compared against the deployed contract binary. \ - You may specify a path from which the code will be read and compressed from, or omit the path. \ - If the path is omitted, the archive will be built from the current working directory."; - - fn build(display_order: usize) -> Command { - Command::new(Self::NAME) - .about(Self::ABOUT) - .display_order(display_order) - .arg(common::verbose::arg(DisplayOrder::Verbose as usize)) - .arg(common::transaction_hash::arg( - DisplayOrder::TransactionHash as usize, - )) - .arg(verification_url_base_path::arg( - DisplayOrder::VerificationUrlBasePath as usize, - )) - .arg(verification_project_path::arg( - DisplayOrder::VerificationProjectPath as usize, - )) - } - - async fn run(matches: &ArgMatches) -> Result { - let transaction_hash = common::transaction_hash::get(matches); - let verification_url_base_path = verification_url_base_path::get(matches); - let verification_project_path = verification_project_path::get(matches); - let verbosity_level = common::verbose::get(matches); - - casper_client::cli::verify_contract( - transaction_hash, - verification_url_base_path, - verification_project_path, - verbosity_level, - ) - .await - .map(Success::from) - } -}