Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(jsonrpc): cleanup adversarial-primitives #6851

Merged
merged 1 commit into from
May 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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