diff --git a/Cargo.lock b/Cargo.lock index f48eefa..825c2e8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -333,6 +333,28 @@ dependencies = [ "generic-array 0.14.6", ] +[[package]] +name = "client" +version = "0.1.0" +dependencies = [ + "blst", + "bytes", + "common", + "consensus", + "ethers", + "execution", + "eyre", + "futures", + "hex", + "jsonrpsee", + "reqwest", + "revm", + "serde", + "ssz-rs", + "tokio", + "toml", +] + [[package]] name = "coins-bip32" version = "0.7.0" @@ -390,6 +412,45 @@ dependencies = [ "thiserror", ] +[[package]] +name = "common" +version = "0.1.0" +dependencies = [ + "blst", + "bytes", + "ethers", + "eyre", + "futures", + "hex", + "jsonrpsee", + "reqwest", + "revm", + "serde", + "ssz-rs", + "tokio", + "toml", +] + +[[package]] +name = "consensus" +version = "0.1.0" +dependencies = [ + "blst", + "bytes", + "common", + "ethers", + "eyre", + "futures", + "hex", + "jsonrpsee", + "reqwest", + "revm", + "serde", + "ssz-rs", + "tokio", + "toml", +] + [[package]] name = "const-oid" version = "0.9.0" @@ -791,6 +852,27 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" +[[package]] +name = "execution" +version = "0.1.0" +dependencies = [ + "blst", + "bytes", + "common", + "consensus", + "ethers", + "eyre", + "futures", + "hex", + "jsonrpsee", + "reqwest", + "revm", + "serde", + "ssz-rs", + "tokio", + "toml", +] + [[package]] name = "eyre" version = "0.6.8" @@ -1599,6 +1681,8 @@ version = "0.1.0" dependencies = [ "blst", "bytes", + "client", + "common", "ethers", "eyre", "futures", diff --git a/Cargo.toml b/Cargo.toml index 0b6469b..14474f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,21 +1,9 @@ -[package] -name = "lightclient" -version = "0.1.0" -edition = "2021" +[workspace] -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -reqwest = { version = "0.11", features = ["json"] } -tokio = { version = "1", features = ["full"] } -eyre = "0.6.8" -serde = { version = "1.0.143", features = ["derive"] } -hex = "0.4.3" -ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs" } -blst = "0.3.10" -ethers = "0.17.0" -jsonrpsee = { version = "0.15.1", features = ["full"] } -revm = "1.9.0" -bytes = "1.2.1" -futures = "0.3.23" -toml = "0.5.9" +members = [ + "cli", + "client", + "common", + "consensus", + "execution", +] diff --git a/cli/Cargo.toml b/cli/Cargo.toml new file mode 100644 index 0000000..204e1c0 --- /dev/null +++ b/cli/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "lightclient" +version = "0.1.0" +edition = "2021" + +[dependencies] +reqwest = { version = "0.11", features = ["json"] } +tokio = { version = "1", features = ["full"] } +eyre = "0.6.8" +serde = { version = "1.0.143", features = ["derive"] } +hex = "0.4.3" +ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs" } +blst = "0.3.10" +ethers = "0.17.0" +jsonrpsee = { version = "0.15.1", features = ["full"] } +revm = "1.9.0" +bytes = "1.2.1" +futures = "0.3.23" +toml = "0.5.9" + +client = { path = "../client" } +common = { path = "../common" } diff --git a/src/main.rs b/cli/src/main.rs similarity index 88% rename from src/main.rs rename to cli/src/main.rs index 3d05147..7eaf005 100644 --- a/src/main.rs +++ b/cli/src/main.rs @@ -6,11 +6,6 @@ use tokio::time::sleep; use client::{rpc::Rpc, Client}; use common::config::Config; -pub mod client; -pub mod common; -pub mod consensus; -pub mod execution; - #[tokio::main] async fn main() -> Result<()> { let config = Config::from_file(Path::new("./configs/goerli.toml"))?; diff --git a/client/Cargo.toml b/client/Cargo.toml new file mode 100644 index 0000000..89557b2 --- /dev/null +++ b/client/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "client" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +reqwest = { version = "0.11", features = ["json"] } +tokio = { version = "1", features = ["full"] } +eyre = "0.6.8" +serde = { version = "1.0.143", features = ["derive"] } +hex = "0.4.3" +ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs" } +blst = "0.3.10" +ethers = "0.17.0" +jsonrpsee = { version = "0.15.1", features = ["full"] } +revm = "1.9.0" +bytes = "1.2.1" +futures = "0.3.23" +toml = "0.5.9" + +common = { path = "../common" } +consensus = { path = "../consensus" } +execution = { path = "../execution" } diff --git a/src/client/client.rs b/client/src/client.rs similarity index 94% rename from src/client/client.rs rename to client/src/client.rs index f86460c..7c8c7de 100644 --- a/src/client/client.rs +++ b/client/src/client.rs @@ -3,11 +3,11 @@ use std::sync::Arc; use ethers::prelude::{Address, U256}; use eyre::Result; -use crate::common::config::Config; -use crate::consensus::types::Header; -use crate::consensus::ConsensusClient; -use crate::execution::evm::Evm; -use crate::execution::ExecutionClient; +use common::config::Config; +use consensus::types::Header; +use consensus::ConsensusClient; +use execution::evm::Evm; +use execution::ExecutionClient; pub struct Client { consensus: ConsensusClient, diff --git a/src/client/mod.rs b/client/src/lib.rs similarity index 100% rename from src/client/mod.rs rename to client/src/lib.rs diff --git a/src/client/rpc.rs b/client/src/rpc.rs similarity index 98% rename from src/client/rpc.rs rename to client/src/rpc.rs index 9177226..da6bf54 100644 --- a/src/client/rpc.rs +++ b/client/src/rpc.rs @@ -12,7 +12,7 @@ use jsonrpsee::{ proc_macros::rpc, }; -use crate::common::utils::{hex_str_to_bytes, u64_to_hex_string}; +use common::utils::{hex_str_to_bytes, u64_to_hex_string}; use super::Client; diff --git a/common/Cargo.toml b/common/Cargo.toml new file mode 100644 index 0000000..85207d8 --- /dev/null +++ b/common/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "common" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +reqwest = { version = "0.11", features = ["json"] } +tokio = { version = "1", features = ["full"] } +eyre = "0.6.8" +serde = { version = "1.0.143", features = ["derive"] } +hex = "0.4.3" +ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs" } +blst = "0.3.10" +ethers = "0.17.0" +jsonrpsee = { version = "0.15.1", features = ["full"] } +revm = "1.9.0" +bytes = "1.2.1" +futures = "0.3.23" +toml = "0.5.9" diff --git a/src/common/config.rs b/common/src/config.rs similarity index 100% rename from src/common/config.rs rename to common/src/config.rs diff --git a/src/common/mod.rs b/common/src/lib.rs similarity index 67% rename from src/common/mod.rs rename to common/src/lib.rs index 472f7fc..3e1b405 100644 --- a/src/common/mod.rs +++ b/common/src/lib.rs @@ -1,2 +1,3 @@ pub mod config; +pub mod types; pub mod utils; diff --git a/common/src/types.rs b/common/src/types.rs new file mode 100644 index 0000000..cf51f19 --- /dev/null +++ b/common/src/types.rs @@ -0,0 +1,3 @@ +use ssz_rs::Vector; + +pub type Bytes32 = Vector; diff --git a/src/common/utils.rs b/common/src/utils.rs similarity index 94% rename from src/common/utils.rs rename to common/src/utils.rs index 9c0794f..97baf91 100644 --- a/src/common/utils.rs +++ b/common/src/utils.rs @@ -2,7 +2,7 @@ use ethers::prelude::Address; use eyre::Result; use ssz_rs::{Node, Vector}; -use crate::consensus::types::Bytes32; +use super::types::Bytes32; pub fn hex_str_to_bytes(s: &str) -> Result> { let stripped = s.strip_prefix("0x").unwrap_or(s); diff --git a/consensus/Cargo.toml b/consensus/Cargo.toml new file mode 100644 index 0000000..be1ff64 --- /dev/null +++ b/consensus/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "consensus" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +reqwest = { version = "0.11", features = ["json"] } +tokio = { version = "1", features = ["full"] } +eyre = "0.6.8" +serde = { version = "1.0.143", features = ["derive"] } +hex = "0.4.3" +ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs" } +blst = "0.3.10" +ethers = "0.17.0" +jsonrpsee = { version = "0.15.1", features = ["full"] } +revm = "1.9.0" +bytes = "1.2.1" +futures = "0.3.23" +toml = "0.5.9" + +common = { path = "../common" } + diff --git a/src/consensus/consensus.rs b/consensus/src/consensus.rs similarity index 99% rename from src/consensus/consensus.rs rename to consensus/src/consensus.rs index abbefff..c68afb6 100644 --- a/src/consensus/consensus.rs +++ b/consensus/src/consensus.rs @@ -5,10 +5,12 @@ use blst::BLST_ERROR; use eyre::Result; use ssz_rs::prelude::*; +use common::config::Config; +use common::types::*; +use common::utils::*; + use super::rpc::Rpc; use super::types::*; -use crate::common::config::Config; -use crate::common::utils::*; pub struct ConsensusClient { rpc: Rpc, diff --git a/src/consensus/mod.rs b/consensus/src/lib.rs similarity index 100% rename from src/consensus/mod.rs rename to consensus/src/lib.rs diff --git a/src/consensus/rpc.rs b/consensus/src/rpc.rs similarity index 100% rename from src/consensus/rpc.rs rename to consensus/src/rpc.rs diff --git a/src/consensus/types.rs b/consensus/src/types.rs similarity index 99% rename from src/consensus/types.rs rename to consensus/src/types.rs index 09d7cd7..08e6c52 100644 --- a/src/consensus/types.rs +++ b/consensus/src/types.rs @@ -2,11 +2,11 @@ use eyre::Result; use serde::de::Error; use ssz_rs::prelude::*; -use crate::common::utils::hex_str_to_bytes; +use common::types::Bytes32; +use common::utils::hex_str_to_bytes; pub type BLSPubKey = Vector; pub type SignatureBytes = Vector; -pub type Bytes32 = Vector; pub type Address = Vector; pub type LogsBloom = Vector; pub type Transaction = List; diff --git a/execution/Cargo.toml b/execution/Cargo.toml new file mode 100644 index 0000000..95e2ad0 --- /dev/null +++ b/execution/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "execution" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +reqwest = { version = "0.11", features = ["json"] } +tokio = { version = "1", features = ["full"] } +eyre = "0.6.8" +serde = { version = "1.0.143", features = ["derive"] } +hex = "0.4.3" +ssz-rs = { git = "https://github.com/ralexstokes/ssz-rs" } +blst = "0.3.10" +ethers = "0.17.0" +jsonrpsee = { version = "0.15.1", features = ["full"] } +revm = "1.9.0" +bytes = "1.2.1" +futures = "0.3.23" +toml = "0.5.9" + +common = { path = "../common" } +consensus = { path = "../consensus" } diff --git a/src/execution/evm.rs b/execution/src/evm.rs similarity index 98% rename from src/execution/evm.rs rename to execution/src/evm.rs index 0769d74..d2709df 100644 --- a/src/execution/evm.rs +++ b/execution/src/evm.rs @@ -6,8 +6,9 @@ use eyre::Result; use revm::{AccountInfo, Bytecode, Database, Env, TransactOut, TransactTo, EVM}; use tokio::runtime::Runtime; +use consensus::types::ExecutionPayload; + use super::ExecutionClient; -use crate::consensus::types::ExecutionPayload; pub struct Evm { evm: EVM, diff --git a/src/execution/execution.rs b/execution/src/execution.rs similarity index 96% rename from src/execution/execution.rs rename to execution/src/execution.rs index 06a3992..6baffb9 100644 --- a/src/execution/execution.rs +++ b/execution/src/execution.rs @@ -6,11 +6,12 @@ use ethers::utils::keccak256; use ethers::utils::rlp::encode; use eyre::Result; +use common::utils::hex_str_to_bytes; +use consensus::types::ExecutionPayload; + use super::proof::{encode_account, verify_proof}; use super::rpc::Rpc; use super::types::Account; -use crate::common::utils::hex_str_to_bytes; -use crate::consensus::types::ExecutionPayload; #[derive(Clone)] pub struct ExecutionClient { diff --git a/src/execution/mod.rs b/execution/src/lib.rs similarity index 100% rename from src/execution/mod.rs rename to execution/src/lib.rs diff --git a/src/execution/proof.rs b/execution/src/proof.rs similarity index 98% rename from src/execution/proof.rs rename to execution/src/proof.rs index 05a1738..57c1197 100644 --- a/src/execution/proof.rs +++ b/execution/src/proof.rs @@ -1,7 +1,7 @@ use ethers::utils::keccak256; use ethers::utils::rlp::{decode_list, RlpStream}; -use crate::execution::types::Proof; +use super::types::Proof; pub fn verify_proof(proof: &Vec>, root: &Vec, path: &Vec, value: &Vec) -> bool { let mut expected_hash = root.clone(); diff --git a/src/execution/rpc.rs b/execution/src/rpc.rs similarity index 94% rename from src/execution/rpc.rs rename to execution/src/rpc.rs index b4226b9..9a2d1d9 100644 --- a/src/execution/rpc.rs +++ b/execution/src/rpc.rs @@ -7,7 +7,7 @@ use jsonrpsee::{ rpc_params, }; -use crate::common::utils::{address_to_hex_string, hex_str_to_bytes, u64_to_hex_string}; +use common::utils::{address_to_hex_string, hex_str_to_bytes, u64_to_hex_string}; use super::types::Proof; diff --git a/src/execution/types.rs b/execution/src/types.rs similarity index 96% rename from src/execution/types.rs rename to execution/src/types.rs index 988bbb3..8f85c40 100644 --- a/src/execution/types.rs +++ b/execution/src/types.rs @@ -5,7 +5,7 @@ use eyre::Result; use serde::de::Error; use serde::Deserialize; -use crate::common::utils::hex_str_to_bytes; +use common::utils::hex_str_to_bytes; #[derive(Deserialize, Debug)] #[serde(rename_all = "camelCase")]