Skip to content

Commit

Permalink
chore: rename feature with-codec => with-scale
Browse files Browse the repository at this point in the history
  • Loading branch information
koushiro committed Feb 23, 2024
1 parent 1fe20e2 commit 5d46cd8
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- uses: actions-rs/cargo@v1
with:
command: build
args: --all --release
args: --all --release --all-features
- uses: actions-rs/cargo@v1
with:
command: build
Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rlp = { version = "0.5.2", default-features = false, features = ["derive"] }
sha3 = { version = "0.10", default-features = false }
trie-root = { version = "0.18", default-features = false }

codec = { package = "parity-scale-codec", version = "3.2", default-features = false, features = ["derive"], optional = true }
scale-codec = { package = "parity-scale-codec", version = "3.2", default-features = false, features = ["derive"], optional = true }
scale-info = { version = "2.3", default-features = false, features = ["derive"], optional = true }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }

Expand All @@ -29,17 +29,17 @@ triehash = "0.8.4"

[features]
default = ["std"]
with-codec = ["codec", "scale-info", "ethereum-types/codec"]
with-scale = ["scale-codec", "scale-info", "ethereum-types/codec"]
with-serde = ["serde", "ethereum-types/serialize"]
std = [
"bytes/std",
"codec/std",
"ethereum-types/std",
"hash-db/std",
"hash256-std-hasher/std",
"rlp/std",
"scale-info/std",
"serde/std",
"sha3/std",
"trie-root/std",
"scale-codec?/std",
"scale-info?/std",
"serde?/std",
]
5 changes: 4 additions & 1 deletion src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use ethereum_types::{H256, U256};

#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(rlp::RlpEncodable, rlp::RlpDecodable)]
#[cfg_attr(feature = "with-codec", derive(codec::Encode, codec::Decode))]
#[cfg_attr(
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Account {
pub nonce: U256,
Expand Down
4 changes: 2 additions & 2 deletions src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::{

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Block<T> {
Expand Down
8 changes: 4 additions & 4 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use sha3::{Digest, Keccak256};

use crate::Bytes;

/// Ethereum header definition.
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(rlp::RlpEncodable, rlp::RlpDecodable)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
/// Ethereum header definition.
pub struct Header {
pub parent_hash: H256,
pub ommers_hash: H256,
Expand Down Expand Up @@ -57,8 +57,8 @@ impl Header {
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
/// Partial header definition without ommers hash and transactions root.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PartialHeader {
pub parent_hash: H256,
pub beneficiary: H160,
Expand Down
4 changes: 2 additions & 2 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use crate::Bytes;
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(rlp::RlpEncodable, rlp::RlpDecodable)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Log {
Expand Down
20 changes: 10 additions & 10 deletions src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use crate::{
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(rlp::RlpEncodable, rlp::RlpDecodable)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct FrontierReceiptData {
Expand All @@ -26,8 +26,8 @@ pub struct FrontierReceiptData {
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(rlp::RlpEncodable, rlp::RlpDecodable)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EIP658ReceiptData {
Expand Down Expand Up @@ -81,8 +81,8 @@ impl EnvelopedDecodable for ReceiptV1 {

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(
feature = "with-serde",
Expand Down Expand Up @@ -148,8 +148,8 @@ impl From<ReceiptV2> for EIP658ReceiptData {

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(
feature = "with-serde",
Expand Down Expand Up @@ -224,8 +224,8 @@ impl From<ReceiptV3> for EIP658ReceiptData {

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(
feature = "with-serde",
Expand Down
4 changes: 2 additions & 2 deletions src/transaction/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::{

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EIP1559Transaction {
Expand Down
14 changes: 5 additions & 9 deletions src/transaction/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ use crate::{transaction::TransactionAction, Bytes};

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(
feature = "with-serde",
derive(serde::Serialize, serde::Deserialize),
serde(rename_all = "camelCase")
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AccessListItem {
pub address: Address,
pub storage_keys: Vec<H256>,
Expand All @@ -42,8 +38,8 @@ pub type AccessList = Vec<AccessListItem>;

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EIP2930Transaction {
Expand Down
36 changes: 16 additions & 20 deletions src/transaction/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::Bytes;

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TransactionAction {
Expand Down Expand Up @@ -44,8 +44,8 @@ impl rlp::Decodable for TransactionAction {

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TransactionRecoveryId(pub u64);
Expand Down Expand Up @@ -77,7 +77,7 @@ impl TransactionRecoveryId {
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "with-codec", derive(scale_info::TypeInfo))]
#[cfg_attr(feature = "with-scale", derive(scale_info::TypeInfo))]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TransactionSignature {
v: TransactionRecoveryId,
Expand Down Expand Up @@ -146,32 +146,32 @@ impl TransactionSignature {
}
}

#[cfg(feature = "codec")]
impl codec::Encode for TransactionSignature {
#[cfg(feature = "with-scale")]
impl scale_codec::Encode for TransactionSignature {
fn size_hint(&self) -> usize {
codec::Encode::size_hint(&(self.v.0, self.r, self.s))
scale_codec::Encode::size_hint(&(self.v.0, self.r, self.s))
}

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
codec::Encode::using_encoded(&(self.v.0, self.r, self.s), f)
scale_codec::Encode::using_encoded(&(self.v.0, self.r, self.s), f)
}
}

#[cfg(feature = "codec")]
impl codec::Decode for TransactionSignature {
fn decode<I: codec::Input>(value: &mut I) -> Result<Self, codec::Error> {
let (v, r, s) = codec::Decode::decode(value)?;
#[cfg(feature = "with-scale")]
impl scale_codec::Decode for TransactionSignature {
fn decode<I: scale_codec::Input>(value: &mut I) -> Result<Self, scale_codec::Error> {
let (v, r, s) = scale_codec::Decode::decode(value)?;
match Self::new(v, r, s) {
Some(signature) => Ok(signature),
None => Err(codec::Error::from("Invalid signature")),
None => Err(scale_codec::Error::from("Invalid signature")),
}
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(feature = "with-serde", derive(serde::Serialize, serde::Deserialize))]
pub struct LegacyTransaction {
Expand Down Expand Up @@ -250,10 +250,6 @@ impl rlp::Decodable for LegacyTransaction {
}

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
)]
pub struct LegacyTransactionMessage {
pub nonce: U256,
pub gas_price: U256,
Expand Down
8 changes: 4 additions & 4 deletions src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ impl EnvelopedDecodable for TransactionV0 {

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(
feature = "with-serde",
Expand Down Expand Up @@ -104,8 +104,8 @@ impl EnvelopedDecodable for TransactionV1 {

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(
feature = "with-codec",
derive(codec::Encode, codec::Decode, scale_info::TypeInfo)
feature = "with-scale",
derive(scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)
)]
#[cfg_attr(
feature = "with-serde",
Expand Down

0 comments on commit 5d46cd8

Please sign in to comment.