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

refactor(jsonrpc-primitives): ensure impl Deserialize on all public jsonrpc-related types #4770

Merged
merged 19 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from 18 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
2 changes: 1 addition & 1 deletion chain/jsonrpc-primitives/src/types/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub enum BlockReference {
SyncCheckpoint(near_primitives::types::SyncCheckpoint),
}

#[derive(thiserror::Error, Debug, Serialize)]
#[derive(thiserror::Error, Debug, Serialize, Deserialize)]
#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RpcBlockError {
#[error("Block not found: {error_message}")]
Expand Down
2 changes: 1 addition & 1 deletion chain/jsonrpc-primitives/src/types/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct RpcChunkResponse {
pub chunk_view: near_primitives::views::ChunkView,
}

#[derive(thiserror::Error, Debug, Serialize)]
#[derive(thiserror::Error, Debug, Serialize, Deserialize)]
#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RpcChunkError {
#[error("The node reached its limits. Try again later. More details: {error_message}")]
Expand Down
2 changes: 1 addition & 1 deletion chain/jsonrpc-primitives/src/types/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct RpcProtocolConfigResponse {
pub config_view: near_chain_configs::ProtocolConfigView,
}

#[derive(thiserror::Error, Debug, Serialize)]
#[derive(thiserror::Error, Debug, Serialize, Deserialize)]
#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RpcProtocolConfigError {
#[error("Block has never been observed: {error_message}")]
Expand Down
2 changes: 1 addition & 1 deletion chain/jsonrpc-primitives/src/types/gas_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct RpcGasPriceResponse {
pub gas_price_view: near_primitives::views::GasPriceView,
}

#[derive(thiserror::Error, Debug, Serialize)]
#[derive(thiserror::Error, Debug, Serialize, Deserialize)]
#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RpcGasPriceError {
#[error("Internal error: {error_message}")]
Expand Down
4 changes: 2 additions & 2 deletions chain/jsonrpc-primitives/src/types/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct RpcLightClientNextBlockResponse {
pub light_client_block: Option<near_primitives::views::LightClientBlockView>,
}

#[derive(thiserror::Error, Debug, Serialize)]
#[derive(thiserror::Error, Debug, Serialize, Deserialize)]
#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RpcLightClientProofError {
#[error("Block either has never been observed on the node or has been garbage collected: {error_message}")]
Expand All @@ -53,7 +53,7 @@ pub enum RpcLightClientProofError {
InternalError { error_message: String },
}

#[derive(thiserror::Error, Debug, Serialize)]
#[derive(thiserror::Error, Debug, Serialize, Deserialize)]
#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RpcLightClientNextBlockError {
#[error("Internal error: {error_message}")]
Expand Down
4 changes: 2 additions & 2 deletions chain/jsonrpc-primitives/src/types/network_info.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use serde::Serialize;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Debug)]
pub struct RpcNetworkInfoResponse {
#[serde(flatten)]
pub network_info_response: near_client_primitives::types::NetworkInfoResponse,
}

#[derive(thiserror::Error, Debug, Serialize)]
#[derive(thiserror::Error, Debug, Serialize, Deserialize)]
#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RpcNetworkInfoError {
#[error("Internal error: {error_message}")]
Expand Down
2 changes: 1 addition & 1 deletion chain/jsonrpc-primitives/src/types/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct RpcQueryRequest {
pub request: near_primitives::views::QueryRequest,
}

#[derive(thiserror::Error, Debug, Serialize)]
#[derive(thiserror::Error, Debug, Serialize, Deserialize)]
#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RpcQueryError {
#[error("There are no fully synchronized blocks on the node yet")]
Expand Down
2 changes: 1 addition & 1 deletion chain/jsonrpc-primitives/src/types/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct RpcReceiptResponse {
pub receipt_view: near_primitives::views::ReceiptView,
}

#[derive(thiserror::Error, Debug, Serialize)]
#[derive(thiserror::Error, Debug, Serialize, Deserialize)]
#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RpcReceiptError {
#[error("The node reached its limits. Try again later. More details: {error_message}")]
Expand Down
2 changes: 1 addition & 1 deletion chain/jsonrpc-primitives/src/types/sandbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl RpcSandboxPatchStateRequest {
#[derive(Deserialize, Serialize)]
pub struct RpcSandboxPatchStateResponse {}

#[derive(thiserror::Error, Debug, Serialize)]
#[derive(thiserror::Error, Debug, Serialize, Deserialize)]
#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RpcSandboxPatchStateError {
#[error("The node reached its limits. Try again later. More details: {error_message}")]
Expand Down
2 changes: 1 addition & 1 deletion chain/jsonrpc-primitives/src/types/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct RpcStatusResponse {
#[derive(Debug, Serialize)]
pub struct RpcHealthResponse;

#[derive(thiserror::Error, Debug, Serialize)]
#[derive(thiserror::Error, Debug, Serialize, Deserialize)]
#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RpcStatusError {
#[error("Node is syncing")]
Expand Down
4 changes: 2 additions & 2 deletions chain/jsonrpc-primitives/src/types/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ pub enum TransactionInfo {
},
}

#[derive(thiserror::Error, Debug, Serialize)]
#[derive(thiserror::Error, Debug, Serialize, Deserialize)]
#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RpcTransactionError {
#[error("An error happened during transaction execution: {context:?}")]
InvalidTransaction {
#[serde(skip)]
#[serde(skip_serializing)]
context: near_primitives::errors::InvalidTxError,
},
#[error("Node doesn't track this shard. Cannot determine whether the transaction is valid")]
Expand Down
2 changes: 1 addition & 1 deletion chain/jsonrpc-primitives/src/types/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde_json::Value;
pub type RpcValidatorsOrderedResponse =
Vec<near_primitives::views::validator_stake_view::ValidatorStakeView>;

#[derive(thiserror::Error, Debug, Serialize)]
#[derive(thiserror::Error, Debug, Serialize, Deserialize)]
#[serde(tag = "name", content = "info", rename_all = "SCREAMING_SNAKE_CASE")]
pub enum RpcValidatorError {
#[error("Epoch not found")]
Expand Down
3 changes: 2 additions & 1 deletion core/primitives/src/sharding.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use borsh::{BorshDeserialize, BorshSerialize};
use reed_solomon_erasure::galois_8::{Field, ReedSolomon};
use serde::Serialize;
use serde::{Deserialize, Serialize};

use near_crypto::Signature;

Expand All @@ -21,6 +21,7 @@ use std::sync::Arc;
BorshSerialize,
BorshDeserialize,
Serialize,
Deserialize,
Hash,
Eq,
PartialEq,
Expand Down
2 changes: 1 addition & 1 deletion core/primitives/src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1406,7 +1406,7 @@ pub struct NextEpochValidatorInfo {
pub shards: Vec<ShardId>,
}

#[derive(Serialize, PartialEq, Eq, Debug, Clone, BorshDeserialize, BorshSerialize)]
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, BorshDeserialize, BorshSerialize)]
pub struct LightClientBlockView {
pub prev_block_hash: CryptoHash,
pub next_block_inner_hash: CryptoHash,
Expand Down