Skip to content

Commit

Permalink
Remove serde from near-client-primitives. (#5515)
Browse files Browse the repository at this point in the history
We should remove `serde` from `near-client-primitives`. It's only needed by `jsonrpc`. 
More changes will be required, to separate `jsonrpc` api, from rest of the code base, but that's a first step.

See #5516

Blocks #5428 (review)
  • Loading branch information
pmnoxx authored Nov 29, 2021
1 parent 3ad7dc9 commit 4b68972
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion chain/client-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ description = "This crate hosts NEAR client-related error types"
[dependencies]
actix = "=0.11.0-beta.2"
chrono = { version = "0.4.4", features = ["serde"] }
serde = { version = "1", features = ["derive"] }
strum = { version = "0.20", features = ["derive"] }
thiserror = "1.0"

Expand Down
3 changes: 1 addition & 2 deletions chain/client-primitives/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::sync::Arc;
use actix::Message;
use chrono::DateTime;
use near_primitives::time::Utc;
use serde::{Deserialize, Serialize};

use near_chain_configs::ProtocolConfigView;
use near_network_primitives::types::{AccountOrPeerIdOrHash, KnownProducer, PeerInfo};
Expand Down Expand Up @@ -462,7 +461,7 @@ impl From<near_chain_primitives::Error> for GetGasPriceError {
}
}

#[derive(Serialize, Deserialize, Debug)]
#[derive(Debug)]
pub struct NetworkInfoResponse {
pub active_peers: Vec<PeerInfo>,
pub num_active_peers: usize,
Expand Down
1 change: 1 addition & 0 deletions chain/jsonrpc-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ near-client-primitives = { path = "../client-primitives" }
near-crypto = { path = "../../core/crypto" }
near-metrics = { path = "../../core/metrics" }
near-primitives = { path = "../../core/primitives" }
near-network-primitives = { path = "../../chain/network-primitives" }
near-primitives-core = { path = "../../core/primitives-core" }
near-rpc-error-macro = { path = "../../tools/rpctypegen/macro" }

Expand Down
21 changes: 17 additions & 4 deletions chain/jsonrpc-primitives/src/types/network_info.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use near_network_primitives::types::{KnownProducer, PeerInfo};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Debug)]
#[derive(Serialize, Deserialize, Debug)]
pub struct RpcNetworkInfoResponse {
#[serde(flatten)]
pub network_info_response: near_client_primitives::types::NetworkInfoResponse,
pub active_peers: Vec<PeerInfo>,
pub num_active_peers: usize,
pub peer_max_count: u32,
pub sent_bytes_per_sec: u64,
pub received_bytes_per_sec: u64,
/// Accounts of known block and chunk producers from routing table.
pub known_producers: Vec<KnownProducer>,
}

#[derive(thiserror::Error, Debug, Serialize, Deserialize)]
Expand All @@ -15,7 +21,14 @@ pub enum RpcNetworkInfoError {

impl From<near_client_primitives::types::NetworkInfoResponse> for RpcNetworkInfoResponse {
fn from(network_info_response: near_client_primitives::types::NetworkInfoResponse) -> Self {
Self { network_info_response }
Self {
active_peers: network_info_response.active_peers,
num_active_peers: network_info_response.num_active_peers,
peer_max_count: network_info_response.peer_max_count,
sent_bytes_per_sec: network_info_response.sent_bytes_per_sec,
received_bytes_per_sec: network_info_response.received_bytes_per_sec,
known_producers: network_info_response.known_producers,
}
}
}

Expand Down

0 comments on commit 4b68972

Please sign in to comment.