Skip to content

Commit

Permalink
chore(jsonrpc): cleanup adversarial-primitives (#6851)
Browse files Browse the repository at this point in the history
Tracking issue: #6850

Cleanup feature flags in `near-jsonrpc-adversarial-primitives`.
  • Loading branch information
miraclx authored May 20, 2022
1 parent 010b32f commit e3c9bf8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
15 changes: 5 additions & 10 deletions chain/jsonrpc-adversarial-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ rust-version = "1.60.0"
edition = "2021"

[dependencies]
serde = { version = "1", features = ["derive"], optional = true }
serde_json = { version = "1", optional = true }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
near-primitives = { path = "../../core/primitives" }

near-jsonrpc-primitives = { path = "../jsonrpc-primitives", optional = true }
near-jsonrpc-primitives = { path = "../jsonrpc-primitives" }
near-network-primitives = { path = "../network-primitives" }
deepsize = { version = "0.2.0", optional = true }

[features]
ser_de = [
"serde_json",
"serde",
"near-jsonrpc-primitives",
"near-network-primitives/test_features"
]
deepsize_feature = ["deepsize", "near-primitives/deepsize_feature"]
test_features = ["near-network-primitives/test_features"]
deepsize_feature = ["deepsize", "near-primitives/deepsize_feature"]
26 changes: 13 additions & 13 deletions chain/jsonrpc-adversarial-primitives/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
#[cfg(feature = "ser_de")]
use near_jsonrpc_primitives::errors::RpcError;
use near_network_primitives::types::{Edge, SimpleEdge};
use near_primitives::network::PeerId;
#[cfg(feature = "ser_de")]
use serde::Deserialize;
#[cfg(feature = "ser_de")]
use serde_json::Value;

#[cfg_attr(feature = "ser_de", derive(Deserialize))]
#[cfg_attr(feature = "test_features", derive(Deserialize))]
#[cfg_attr(feature = "deepsize_feature", derive(deepsize::DeepSizeOf))]
pub struct SetRoutingTableRequest {
pub add_edges: Option<Vec<Edge>>,
pub remove_edges: Option<Vec<SimpleEdge>>,
pub prune_edges: Option<bool>,
}

#[cfg(feature = "ser_de")]
#[cfg(feature = "test_features")]
impl SetRoutingTableRequest {
pub fn parse(value: Option<Value>) -> Result<Self, RpcError> {
pub fn parse(
value: Option<serde_json::Value>,
) -> Result<Self, near_jsonrpc_primitives::errors::RpcError> {
if let Some(value) = value {
serde_json::from_value(value)
.map_err(|err| RpcError::parse_error(format!("Error {:?}", err)))
serde_json::from_value(value).map_err(|err| {
near_jsonrpc_primitives::errors::RpcError::parse_error(format!("Error {:?}", err))
})
} else {
Err(RpcError::parse_error("Require at least one parameter".to_owned()))
Err(near_jsonrpc_primitives::errors::RpcError::parse_error(
"Require at least one parameter".to_owned(),
))
}
}
}

#[cfg_attr(feature = "ser_de", derive(Deserialize))]
#[derive(Deserialize)]
pub struct SetAdvOptionsRequest {
pub disable_edge_signature_verification: Option<bool>,
pub disable_edge_propagation: Option<bool>,
pub disable_edge_pruning: Option<bool>,
}

#[cfg_attr(feature = "ser_de", derive(Deserialize))]
#[derive(Deserialize)]
pub struct StartRoutingTableSyncRequest {
pub peer_id: PeerId,
}
2 changes: 1 addition & 1 deletion chain/jsonrpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test_features = [
"near-client/test_features",
"near-network/test_features",
"near-jsonrpc-primitives/test_features",
"near-jsonrpc-adversarial-primitives/ser_de",
"near-jsonrpc-adversarial-primitives/test_features",
]
nightly = ["nightly_protocol"]
nightly_protocol = ["near-primitives/nightly_protocol"]
Expand Down

0 comments on commit e3c9bf8

Please sign in to comment.