From 1f0d9bd72911eb2fc2dbb622b8229ebb46631dd6 Mon Sep 17 00:00:00 2001 From: Xiangyi Zheng Date: Fri, 3 Nov 2023 15:32:44 -0700 Subject: [PATCH] formatting --- chain/jsonrpc/client/src/lib.rs | 4 +--- chain/jsonrpc/src/api/validator.rs | 11 ++++++----- integration-tests/src/tests/nearcore/rpc_nodes.rs | 4 +++- integration-tests/src/user/rpc_user.rs | 11 ++++++++--- tools/state-parts-dump-check/src/cli.rs | 13 +++++++------ 5 files changed, 25 insertions(+), 18 deletions(-) diff --git a/chain/jsonrpc/client/src/lib.rs b/chain/jsonrpc/client/src/lib.rs index fa7b04f01b4..9a0750c51dd 100644 --- a/chain/jsonrpc/client/src/lib.rs +++ b/chain/jsonrpc/client/src/lib.rs @@ -10,9 +10,7 @@ use near_jsonrpc_primitives::types::transactions::{ }; use near_jsonrpc_primitives::types::validator::RpcValidatorsOrderedRequest; use near_primitives::hash::CryptoHash; -use near_primitives::types::{ - BlockId, BlockReference, MaybeEpochReference, MaybeBlockId, ShardId, -}; +use near_primitives::types::{BlockId, BlockReference, MaybeBlockId, MaybeEpochReference, ShardId}; use near_primitives::views::validator_stake_view::ValidatorStakeView; use near_primitives::views::{ BlockView, ChunkView, EpochValidatorInfo, GasPriceView, StatusResponse, diff --git a/chain/jsonrpc/src/api/validator.rs b/chain/jsonrpc/src/api/validator.rs index b8424996eb6..d95bbc21403 100644 --- a/chain/jsonrpc/src/api/validator.rs +++ b/chain/jsonrpc/src/api/validator.rs @@ -11,13 +11,17 @@ use super::{Params, RpcFrom, RpcRequest}; impl RpcRequest for RpcValidatorRequest { fn parse(value: Value) -> Result { + // this takes care of the legacy input format [block_id] if let Ok(epoch_reference) = Params::new(value.clone()) .try_singleton(|block_id| match block_id { Some(id) => Ok(EpochReference::BlockId(id)), None => Ok(EpochReference::Latest), - }).unwrap_or_parse() { - Ok(Self {epoch_reference}) + }) + .unwrap_or_parse() + { + Ok(Self { epoch_reference }) } else { + // this takes care of the map format input, e.g. {"epoch_id": "5Yheiw"} or {"block_id": 12345} Params::parse(value).map(|epoch_reference| Self { epoch_reference }) } } @@ -76,7 +80,6 @@ mod tests { fn test_serialize_validators_params_as_object_input_block_height() { let block_height: u64 = 12345; let params = serde_json::json!({"block_id": block_height}); - println!("result is: {:?}", RpcValidatorRequest::parse(params.clone())); assert!(RpcValidatorRequest::parse(params).is_ok()); } @@ -84,8 +87,6 @@ mod tests { fn test_serialize_validators_params_as_object_input_epoch_id() { let epoch_id = CryptoHash::new().to_string(); let params = serde_json::json!({"epoch_id": epoch_id}); - println!("result is: {:?}", RpcValidatorRequest::parse(params.clone())); assert!(RpcValidatorRequest::parse(params).is_ok()); } - } diff --git a/integration-tests/src/tests/nearcore/rpc_nodes.rs b/integration-tests/src/tests/nearcore/rpc_nodes.rs index d176e1fe0d2..50686526936 100644 --- a/integration-tests/src/tests/nearcore/rpc_nodes.rs +++ b/integration-tests/src/tests/nearcore/rpc_nodes.rs @@ -56,7 +56,9 @@ fn test_get_validator_info_rpc() { if block_view.header.height > 1 { let client = new_client(&format!("http://{}", rpc_addrs_copy[0])); let block_hash = block_view.header.hash; - let invalid_res = client.validators(Some(EpochReference::BlockId(BlockId::Hash(block_hash)))).await; + let invalid_res = client + .validators(Some(EpochReference::BlockId(BlockId::Hash(block_hash)))) + .await; assert!(invalid_res.is_err()); let res = client.validators(None).await.unwrap(); assert_eq!(res.current_validators.len(), 1); diff --git a/integration-tests/src/user/rpc_user.rs b/integration-tests/src/user/rpc_user.rs index 65451d10e83..ff43570e70f 100644 --- a/integration-tests/src/user/rpc_user.rs +++ b/integration-tests/src/user/rpc_user.rs @@ -16,7 +16,7 @@ use near_primitives::receipt::Receipt; use near_primitives::serialize::to_base64; use near_primitives::transaction::SignedTransaction; use near_primitives::types::{ - AccountId, BlockHeight, BlockId, BlockReference, ShardId, MaybeEpochReference, + AccountId, BlockHeight, BlockId, BlockReference, MaybeEpochReference, ShardId, }; use near_primitives::views::{ AccessKeyView, AccountView, BlockView, CallResult, ChunkView, ContractCodeView, @@ -56,8 +56,13 @@ impl RpcUser { self.actix(move |client| client.query(request).map_err(|err| err.to_string())) } - pub fn validators(&self, epoch_id_or_block_id: MaybeEpochReference) -> Result { - self.actix(move |client| client.validators(epoch_id_or_block_id).map_err(|err| err.to_string())) + pub fn validators( + &self, + epoch_id_or_block_id: MaybeEpochReference, + ) -> Result { + self.actix(move |client| { + client.validators(epoch_id_or_block_id).map_err(|err| err.to_string()) + }) } } diff --git a/tools/state-parts-dump-check/src/cli.rs b/tools/state-parts-dump-check/src/cli.rs index 2bde488796c..9e9f39f92a0 100644 --- a/tools/state-parts-dump-check/src/cli.rs +++ b/tools/state-parts-dump-check/src/cli.rs @@ -8,7 +8,9 @@ use near_client::sync::external::{ use near_jsonrpc::client::{new_client, JsonRpcClient}; use near_primitives::hash::CryptoHash; use near_primitives::state_part::PartId; -use near_primitives::types::{BlockId, BlockReference, EpochId, EpochReference, Finality, ShardId, StateRoot}; +use near_primitives::types::{ + BlockId, BlockReference, EpochId, EpochReference, Finality, ShardId, StateRoot, +}; use near_primitives::views::BlockView; use near_store::Trie; use nearcore::state_sync::extract_part_id_from_part_file_name; @@ -640,11 +642,10 @@ async fn get_processing_epoch_information( .await .or_else(|_| Err(anyhow!("get final block failed")))?; let latest_epoch_id = latest_block_response.header.epoch_id; - let latest_epoch_response = - rpc_client - .validators(Some(EpochReference::EpochId(EpochId(latest_epoch_id)))) - .await - .or_else(|_| Err(anyhow!("validators_by_epoch_id for prev_epoch_id failed")))?; + let latest_epoch_response = rpc_client + .validators(Some(EpochReference::EpochId(EpochId(latest_epoch_id)))) + .await + .or_else(|_| Err(anyhow!("validators_by_epoch_id for prev_epoch_id failed")))?; let latest_epoch_height = latest_epoch_response.epoch_height; let prev_epoch_last_block_response = get_previous_epoch_last_block_response(rpc_client, latest_epoch_id).await?;