Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ppca committed Nov 3, 2023
1 parent 72f29e2 commit 1f0d9bd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
4 changes: 1 addition & 3 deletions chain/jsonrpc/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 6 additions & 5 deletions chain/jsonrpc/src/api/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ use super::{Params, RpcFrom, RpcRequest};

impl RpcRequest for RpcValidatorRequest {
fn parse(value: Value) -> Result<Self, RpcParseError> {
// 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 })
}
}
Expand Down Expand Up @@ -76,16 +80,13 @@ 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());
}

#[test]
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());
}

}
4 changes: 3 additions & 1 deletion integration-tests/src/tests/nearcore/rpc_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions integration-tests/src/user/rpc_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<EpochValidatorInfo, String> {
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<EpochValidatorInfo, String> {
self.actix(move |client| {
client.validators(epoch_id_or_block_id).map_err(|err| err.to_string())
})
}
}

Expand Down
13 changes: 7 additions & 6 deletions tools/state-parts-dump-check/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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?;
Expand Down

0 comments on commit 1f0d9bd

Please sign in to comment.