Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
4764: Derive `Serialize` for some of the types r=rafal-ch a=rafal-ch

This PR will enable some additional types in the `types` crate to be serde-serialized. It'll allow presenting these types in an user-friendly form, for example a Json representation for`RewardResponse`:
```
{
  "amount": "8446000000000002",
  "era_id": 1
}
```


Co-authored-by: Rafał Chabowski <[email protected]>
  • Loading branch information
casperlabs-bors-ng[bot] and Rafał Chabowski authored Jun 26, 2024
2 parents a201c8d + 8c34457 commit 30797fb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion binary_port/src/global_state_query_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ use casper_types::testing::TestRng;

#[cfg(test)]
use casper_types::{ByteCode, ByteCodeKind};
use serde::Serialize;

/// Carries the successful result of the global state query.
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Clone, Serialize)]
pub struct GlobalStateQueryResult {
/// Stored value.
value: StoredValue,
Expand Down
3 changes: 2 additions & 1 deletion binary_port/src/node_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ use casper_types::{
use casper_types::testing::TestRng;
#[cfg(test)]
use rand::Rng;
use serde::Serialize;

use crate::{minimal_block_info::MinimalBlockInfo, type_wrappers::ReactorStateName};

/// Status information about the node.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Serialize)]
pub struct NodeStatus {
/// The node ID and network address of each connected peer.
pub peers: Peers,
Expand Down
17 changes: 9 additions & 8 deletions binary_port/src/type_wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use casper_types::{
bytesrepr::{self, Bytes, FromBytes, ToBytes},
EraId, ExecutionInfo, Key, PublicKey, TimeDiff, Timestamp, Transaction, ValidatorChange, U512,
};
use serde::Serialize;

use super::GlobalStateQueryResult;

Expand Down Expand Up @@ -39,7 +40,7 @@ macro_rules! impl_bytesrepr_for_type_wrapper {
}

/// Type representing uptime.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
pub struct Uptime(u64);

impl Uptime {
Expand Down Expand Up @@ -69,7 +70,7 @@ impl TryFrom<Uptime> for TimeDiff {
}

/// Type representing changes in consensus validators.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Serialize)]
#[cfg_attr(feature = "datasize", derive(DataSize))]
pub struct ConsensusValidatorChanges(BTreeMap<PublicKey, Vec<(EraId, ValidatorChange)>>);

Expand All @@ -92,7 +93,7 @@ impl From<ConsensusValidatorChanges> for BTreeMap<PublicKey, Vec<(EraId, Validat
}

/// Type representing network name.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Serialize)]
pub struct NetworkName(String);

impl NetworkName {
Expand All @@ -114,7 +115,7 @@ impl From<NetworkName> for String {
}

/// Type representing the reactor state name.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Serialize)]
pub struct ReactorStateName(String);

impl ReactorStateName {
Expand All @@ -136,7 +137,7 @@ impl From<ReactorStateName> for String {
}

/// Type representing last progress of the sync process.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Serialize)]
pub struct LastProgress(Timestamp);

impl LastProgress {
Expand Down Expand Up @@ -174,7 +175,7 @@ impl GetTrieFullResult {
}

/// Type representing the reward of a validator or a delegator.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Serialize)]
pub struct RewardResponse {
amount: U512,
era_id: EraId,
Expand Down Expand Up @@ -223,7 +224,7 @@ impl FromBytes for RewardResponse {
}

/// Describes the consensus status.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Serialize)]
pub struct ConsensusStatus {
validator_public_key: PublicKey,
round_length: Option<TimeDiff>,
Expand Down Expand Up @@ -278,7 +279,7 @@ impl FromBytes for ConsensusStatus {
}

/// A transaction with execution info.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, Serialize)]
pub struct TransactionWithExecutionInfo {
transaction: Transaction,
execution_info: Option<ExecutionInfo>,
Expand Down

0 comments on commit 30797fb

Please sign in to comment.