Skip to content

Commit

Permalink
Upgrade num to 0.2, use enum-primitive-derive (openethereum#11636)
Browse files Browse the repository at this point in the history
  • Loading branch information
vorot93 authored Jun 7, 2020
1 parent 58fde98 commit 596d011
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 76 deletions.
74 changes: 37 additions & 37 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion ethcore/builtin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ethereum-types = "0.9.0"
ethjson = { path = "../../json" }
keccak-hash = "0.5.0"
log = "0.4"
num = { version = "0.1", default-features = false, features = ["bigint"] }
num = "0.2"
parity-bytes = "0.1"
parity-crypto = { version = "0.6.1", features = ["publickey"] }
eth_pairings = { git = "https://github.com/matter-labs/eip1962.git", default-features = false, features = ["eip_2537"], rev = "ece6cbabc41948db4200e41f0bfdab7ab94c7af8" }
Expand Down
3 changes: 2 additions & 1 deletion ethcore/sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ bytes = { package = "parity-bytes", version = "0.1" }
client-traits = { path = "../client-traits" }
common-types = { path = "../types" }
devp2p = { package = "ethcore-network-devp2p", path = "../../util/network-devp2p" }
enum_primitive = "0.1.1"
enum-primitive-derive = "0.2"
ethcore-io = { path = "../../util/io" }
ethcore-private-tx = { path = "../private-tx" }
ethereum-forkid = "0.2"
Expand All @@ -25,6 +25,7 @@ keccak-hash = "0.5.0"
light = { package = "ethcore-light", path = "../light" }
log = "0.4"
network = { package = "ethcore-network", path = "../../util/network" }
num-traits = "0.2"
parity-runtime = "0.1.1"
parity-crypto = { version = "0.6.1", features = ["publickey"] }
parity-util-mem = "0.6.0"
Expand Down
2 changes: 1 addition & 1 deletion ethcore/sync/src/chain/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use crate::{
};

use bytes::Bytes;
use enum_primitive::FromPrimitive;
use num_traits::FromPrimitive;
use ethereum_types::{H256, U256};
use keccak_hash::keccak;
use network::PeerId;
Expand Down
2 changes: 1 addition & 1 deletion ethcore/sync/src/chain/supplier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::time::{Duration, Instant};
use crate::sync_io::SyncIo;

use bytes::Bytes;
use enum_primitive::FromPrimitive;
use num_traits::FromPrimitive;
use ethereum_types::H256;
use log::{debug, trace, warn};
use network::{self, PeerId};
Expand Down
68 changes: 33 additions & 35 deletions ethcore/sync/src/chain/sync_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,40 @@
use crate::api::{ETH_PROTOCOL, WARP_SYNC_PROTOCOL_ID};
use self::SyncPacket::*;

use enum_primitive::{enum_from_primitive, enum_from_primitive_impl, enum_from_primitive_impl_ty};
use enum_primitive_derive::Primitive;
use network::{PacketId, ProtocolId};

enum_from_primitive! {
/// An enum that defines all known packet ids in the context of
/// synchronization and provides a mechanism to convert from
/// packet ids (of type PacketId or u8) directly read from the network
/// to enum variants. This implicitly provides a mechanism to
/// check whether a given packet id is known, and to prevent
/// packet id clashes when defining new ids.
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum SyncPacket {
StatusPacket = 0x00,
NewBlockHashesPacket = 0x01,
TransactionsPacket = 0x02,
GetBlockHeadersPacket = 0x03,
BlockHeadersPacket = 0x04,
GetBlockBodiesPacket = 0x05,
BlockBodiesPacket = 0x06,
NewBlockPacket = 0x07,

GetNodeDataPacket = 0x0d,
NodeDataPacket = 0x0e,
GetReceiptsPacket = 0x0f,
ReceiptsPacket = 0x10,

GetSnapshotManifestPacket = 0x11,
SnapshotManifestPacket = 0x12,
GetSnapshotDataPacket = 0x13,
SnapshotDataPacket = 0x14,
ConsensusDataPacket = 0x15,
PrivateTransactionPacket = 0x16,
SignedPrivateTransactionPacket = 0x17,
GetPrivateStatePacket = 0x18,
PrivateStatePacket = 0x19,
}
/// An enum that defines all known packet ids in the context of
/// synchronization and provides a mechanism to convert from
/// packet ids (of type PacketId or u8) directly read from the network
/// to enum variants. This implicitly provides a mechanism to
/// check whether a given packet id is known, and to prevent
/// packet id clashes when defining new ids.
#[derive(Clone, Copy, Debug, PartialEq, Primitive)]
pub enum SyncPacket {
StatusPacket = 0x00,
NewBlockHashesPacket = 0x01,
TransactionsPacket = 0x02,
GetBlockHeadersPacket = 0x03,
BlockHeadersPacket = 0x04,
GetBlockBodiesPacket = 0x05,
BlockBodiesPacket = 0x06,
NewBlockPacket = 0x07,

GetNodeDataPacket = 0x0d,
NodeDataPacket = 0x0e,
GetReceiptsPacket = 0x0f,
ReceiptsPacket = 0x10,

GetSnapshotManifestPacket = 0x11,
SnapshotManifestPacket = 0x12,
GetSnapshotDataPacket = 0x13,
SnapshotDataPacket = 0x14,
ConsensusDataPacket = 0x15,
PrivateTransactionPacket = 0x16,
SignedPrivateTransactionPacket = 0x17,
GetPrivateStatePacket = 0x18,
PrivateStatePacket = 0x19,
}


Expand Down Expand Up @@ -118,7 +116,7 @@ impl PacketInfo for SyncPacket {
#[cfg(test)]
mod tests {
use super::*;
use enum_primitive::FromPrimitive;
use num_traits::FromPrimitive;

#[test]
fn packet_ids_from_u8_when_from_primitive_zero_then_equals_status_packet() {
Expand Down

0 comments on commit 596d011

Please sign in to comment.