-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from akjong/feat/init
Init
- Loading branch information
Showing
8 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: Rust Check & Build | ||
|
||
on: | ||
push: | ||
tags: | ||
- v* | ||
branches: | ||
- master | ||
- main | ||
paths-ignore: | ||
- '**.md' | ||
pull_request: | ||
paths-ignore: | ||
- '**.md' | ||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
env: | ||
# Not needed in CI, should make things a bit faster | ||
CARGO_INCREMENTAL: 0 | ||
CARGO_TERM_COLOR: always | ||
# Build smaller artifacts to avoid running out of space in CI | ||
RUSTFLAGS: -C strip=debuginfo | ||
|
||
jobs: | ||
check_and_build: | ||
name: Check and Build | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Cancel Previous Runs | ||
uses: styfle/cancel-workflow-action@main | ||
with: | ||
access_token: ${{ github.token }} | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup Rust toolchain | ||
uses: dtolnay/rust-toolchain@nightly | ||
with: | ||
components: clippy,rustfmt,miri | ||
- uses: taiki-e/install-action@v2 | ||
with: | ||
tool: cargo-sort,cargo-machete | ||
- name: Setup Rust cache | ||
uses: Swatinem/rust-cache@v2 | ||
with: | ||
cache-on-failure: true | ||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
- name: Install Protoc | ||
uses: arduino/setup-protoc@v3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
unstable_features = true | ||
newline_style = "Unix" | ||
imports_granularity = "Crate" | ||
group_imports = "StdExternalCrate" | ||
reorder_imports = true | ||
normalize_comments = true | ||
normalize_doc_attributes = true | ||
format_code_in_doc_comments = true | ||
use_field_init_shorthand = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "alloy-compact" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
alloy = { version = "0.6.4", features = ["full", "node-bindings", "rlp", "rpc-types-engine"] } | ||
ethereum-consensus = { git = "https://github.com/ralexstokes/ethereum-consensus", rev = "8fbd8a53dca0170bedeca40a92ee70fd48c4615b" } | ||
reth-primitives = { git = "https://github.com/paradigmxyz/reth", tag = "v1.1.2" } | ||
|
||
[dev-dependencies] | ||
tokio = "1.41.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use alloy::{ | ||
eips::eip4895::Withdrawal, | ||
primitives::{Address, B256, U256}, | ||
rpc::types::engine::{ | ||
ExecutionPayload as AlloyExecutionPayload, ExecutionPayloadV1, ExecutionPayloadV2, | ||
ExecutionPayloadV3, | ||
}, | ||
}; | ||
use reth_primitives::SealedBlock; | ||
|
||
pub fn to_alloy_withdrawal(value: ethereum_consensus::deneb::Withdrawal) -> Withdrawal { | ||
Withdrawal { | ||
index: value.index as u64, | ||
validator_index: value.validator_index as u64, | ||
address: Address::from_slice(value.address.as_ref()), | ||
amount: value.amount, | ||
} | ||
} | ||
|
||
pub fn to_alloy_execution_payload(block: &SealedBlock, block_hash: B256) -> AlloyExecutionPayload { | ||
let alloy_withdrawals = block | ||
.body | ||
.withdrawals | ||
.as_ref() | ||
.map(|withdrawals| { | ||
withdrawals | ||
.iter() | ||
.map(|w| Withdrawal { | ||
index: w.index, | ||
validator_index: w.validator_index, | ||
address: w.address, | ||
amount: w.amount, | ||
}) | ||
.collect::<Vec<_>>() | ||
}) | ||
.unwrap_or_default(); | ||
|
||
AlloyExecutionPayload::V3(ExecutionPayloadV3 { | ||
blob_gas_used: block.blob_gas_used(), | ||
excess_blob_gas: block.excess_blob_gas.unwrap_or_default(), | ||
payload_inner: ExecutionPayloadV2 { | ||
payload_inner: ExecutionPayloadV1 { | ||
base_fee_per_gas: U256::from(block.base_fee_per_gas.unwrap_or_default()), | ||
block_hash, | ||
block_number: block.number, | ||
extra_data: block.extra_data.clone(), | ||
transactions: block.raw_transactions(), | ||
fee_recipient: block.header.beneficiary, | ||
gas_limit: block.gas_limit, | ||
gas_used: block.gas_used, | ||
logs_bloom: block.logs_bloom, | ||
parent_hash: block.parent_hash, | ||
prev_randao: block.mix_hash, | ||
receipts_root: block.receipts_root, | ||
state_root: block.state_root, | ||
timestamp: block.timestamp, | ||
}, | ||
withdrawals: alloy_withdrawals, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod block; | ||
pub mod time; | ||
pub mod transaction; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use std::time::{SystemTime, SystemTimeError, UNIX_EPOCH}; | ||
|
||
pub fn get_nanos_timestamp() -> Result<u64, SystemTimeError> { | ||
SystemTime::now() | ||
.duration_since(UNIX_EPOCH) | ||
.map(|d| d.as_nanos() as u64) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
#[test] | ||
fn test_get_nanos_timestamp() { | ||
let timestamp = get_nanos_timestamp().unwrap(); | ||
assert!(timestamp > 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use alloy::{ | ||
consensus::TxEnvelope, | ||
eips::eip2718::Encodable2718, | ||
network::{Ethereum, EthereumWallet, TransactionBuilder, TransactionBuilderError}, | ||
primitives::{Bytes, ChainId}, | ||
rpc::types::TransactionRequest, | ||
}; | ||
|
||
pub fn envelope_to_raw_tx(tx: &TxEnvelope) -> Bytes { | ||
let mut encoded = Vec::new(); | ||
tx.encode_2718(&mut encoded); | ||
encoded.into() | ||
} | ||
|
||
pub async fn tx_req_to_envelope( | ||
tx_req: TransactionRequest, | ||
chain_id: ChainId, | ||
wallet: EthereumWallet, | ||
) -> Result<TxEnvelope, TransactionBuilderError<Ethereum>> { | ||
<TransactionRequest as TransactionBuilder<Ethereum>>::with_chain_id(tx_req, chain_id) | ||
.build(&wallet) | ||
.await | ||
} |