Skip to content

Commit 50427ed

Browse files
karim-ensept-en
andauthored
eth-types: make Eth2 dependencies optional (#786)
* `eth-types`: make Eth2 dependencies optional. * Update build files. Co-authored-by: Kirill <[email protected]>
1 parent e598524 commit 50427ed

File tree

9 files changed

+31
-20
lines changed

9 files changed

+31
-20
lines changed

β€Žcontracts/near/Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žcontracts/near/eth-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2021"
88
crate-type = ["cdylib", "rlib"]
99

1010
[dependencies]
11-
eth-types = { path = "../eth-types" }
11+
eth-types = { path = "../eth-types", default-features = false }
1212
admin-controlled = { path = "../admin-controlled" }
1313
near-sdk = "4.0.0"
1414
borsh = "0.9.3"

β€Žcontracts/near/eth-prover/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ crate-type = ["cdylib", "rlib"]
99

1010
[dependencies]
1111
wee_alloc = { version = "0.4.5", default-features = false, features = [] }
12-
eth-types = { path = "../eth-types" }
12+
eth-types = { path = "../eth-types", default-features = false }
1313
admin-controlled = { path = "../admin-controlled" }
1414
serde = { version = "1.0", features = ["derive"] }
1515
serde_json = "1.0"

β€Žcontracts/near/eth-types/Cargo.toml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ rlp = "0.4.2"
1515
rlp-derive = "0.1.0"
1616
ethereum-types = "0.9.2"
1717
derive_more = "^0.99.2"
18-
eth2_ssz = { git = "https://github.com/aurora-is-near/lighthouse.git", rev = "b624c3f0d3c5bc9ea46faa14c9cb2d90ee1e1dec" }
19-
eth2_ssz_derive = { git = "https://github.com/aurora-is-near/lighthouse.git", rev = "b624c3f0d3c5bc9ea46faa14c9cb2d90ee1e1dec" }
20-
tree_hash = { git = "https://github.com/aurora-is-near/lighthouse.git", rev = "b624c3f0d3c5bc9ea46faa14c9cb2d90ee1e1dec" }
21-
tree_hash_derive = { git = "https://github.com/aurora-is-near/lighthouse.git", rev = "b624c3f0d3c5bc9ea46faa14c9cb2d90ee1e1dec" }
22-
eth2_serde_utils = { git = "https://github.com/aurora-is-near/lighthouse.git", rev = "b624c3f0d3c5bc9ea46faa14c9cb2d90ee1e1dec" }
18+
eth2_ssz = { git = "https://github.com/aurora-is-near/lighthouse.git", rev = "b624c3f0d3c5bc9ea46faa14c9cb2d90ee1e1dec", optional = true }
19+
eth2_ssz_derive = { git = "https://github.com/aurora-is-near/lighthouse.git", rev = "b624c3f0d3c5bc9ea46faa14c9cb2d90ee1e1dec", optional = true }
20+
tree_hash = { git = "https://github.com/aurora-is-near/lighthouse.git", rev = "b624c3f0d3c5bc9ea46faa14c9cb2d90ee1e1dec", optional = true }
21+
tree_hash_derive = { git = "https://github.com/aurora-is-near/lighthouse.git", rev = "b624c3f0d3c5bc9ea46faa14c9cb2d90ee1e1dec", optional = true }
22+
eth2_serde_utils = { git = "https://github.com/aurora-is-near/lighthouse.git", rev = "b624c3f0d3c5bc9ea46faa14c9cb2d90ee1e1dec", optional = true }
2323
hex = "0.4.0"
2424

2525
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
2626
serde-big-array = "0.4.1"
2727

2828
[features]
29-
default = ["eip1559"]
29+
default = ["eip1559", "eth2"]
3030
eip1559 = []
31+
eth2 = ["dep:eth2_ssz", "dep:eth2_ssz_derive", "dep:tree_hash", "dep:tree_hash_derive", "dep:eth2_serde_utils"]

β€Žcontracts/near/eth-types/src/lib.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ use rlp_derive::RlpDecodable as RlpDecodableDerive;
1111
#[cfg(not(target_arch = "wasm32"))]
1212
use serde::{Deserialize, Serialize};
1313
use std::io::{Error, Write};
14+
#[cfg(feature = "eth2")]
1415
use tree_hash::{Hash256, TreeHash, TreeHashType};
1516

17+
#[cfg(feature = "eth2")]
1618
pub mod eth2;
1719
#[macro_use]
1820
pub mod macros;
@@ -25,6 +27,7 @@ arr_ethereum_types_wrapper_impl_borsh_serde_ssz!(H512, 64);
2527
arr_ethereum_types_wrapper_impl_borsh_serde_ssz!(H520, 65);
2628
arr_ethereum_types_wrapper_impl_borsh_serde_ssz!(Bloom, 256);
2729

30+
#[cfg(feature = "eth2")]
2831
impl TreeHash for H256 {
2932
fn tree_hash_type() -> TreeHashType {
3033
TreeHashType::Vector
@@ -129,24 +132,27 @@ pub struct BlockHeader {
129132
pub log_bloom: Bloom,
130133
pub difficulty: U256,
131134
#[cfg_attr(
132-
not(target_arch = "wasm32"),
135+
all(feature = "eth2", not(target_arch = "wasm32")),
133136
serde(with = "eth2_serde_utils::u64_hex_be")
134137
)]
135138
pub number: u64,
136139
pub gas_limit: U256,
137140
pub gas_used: U256,
138141
#[cfg_attr(
139-
not(target_arch = "wasm32"),
142+
all(feature = "eth2", not(target_arch = "wasm32")),
140143
serde(with = "eth2_serde_utils::u64_hex_be")
141144
)]
142145
pub timestamp: u64,
143-
#[cfg_attr(not(target_arch = "wasm32"), serde(with = "eth2_serde_utils::hex_vec"))]
146+
#[cfg_attr(
147+
all(feature = "eth2", not(target_arch = "wasm32")),
148+
serde(with = "eth2_serde_utils::hex_vec")
149+
)]
144150
pub extra_data: Vec<u8>,
145151
pub mix_hash: H256,
146152
pub nonce: H64,
147153
#[cfg(feature = "eip1559")]
148154
#[cfg_attr(
149-
not(target_arch = "wasm32"),
155+
all(feature = "eth2", not(target_arch = "wasm32")),
150156
serde(with = "eth2_serde_utils::u64_hex_be")
151157
)]
152158
pub base_fee_per_gas: u64,

β€Žcontracts/near/eth-types/src/macros.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(feature = "eth2")]
12
#[macro_export]
23
macro_rules! arr_wrapper_impl_tree_hash_and_borsh {
34
($name: ident, $len: expr) => {
@@ -89,6 +90,7 @@ macro_rules! arr_wrapper_impl_tree_hash_and_borsh {
8990
};
9091
}
9192

93+
#[cfg(feature = "eth2")]
9294
#[macro_export]
9395
macro_rules! vec_wrapper_impl_tree_hash {
9496
($name: ident) => {
@@ -199,6 +201,7 @@ macro_rules! arr_ethereum_types_wrapper_impl_borsh_serde_ssz {
199201
}
200202
}
201203

204+
#[cfg(feature = "eth2")]
202205
impl ssz::Decode for $name {
203206
fn is_ssz_fixed_len() -> bool {
204207
true
@@ -220,6 +223,7 @@ macro_rules! arr_ethereum_types_wrapper_impl_borsh_serde_ssz {
220223
}
221224
}
222225

226+
#[cfg(feature = "eth2")]
223227
impl ssz::Encode for $name {
224228
fn is_ssz_fixed_len() -> bool {
225229
true
-202 Bytes
Binary file not shown.

β€Žcontracts/near/res/eth_client.wasm

-147 Bytes
Binary file not shown.

β€Žcontracts/near/res/eth_prover.wasm

-1 Bytes
Binary file not shown.

0 commit comments

Comments
Β (0)