-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove ethers dependency on system txs (#436)
- Loading branch information
1 parent
3df0bb1
commit 51c1e8e
Showing
4 changed files
with
40 additions
and
70 deletions.
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
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 |
---|---|---|
@@ -1,61 +1,49 @@ | ||
use alloy_primitives::{address, Address}; | ||
use ethers_contract::BaseContract; | ||
use ethers_core::abi::Abi; | ||
use ethers_core::types::Bytes; | ||
|
||
fn make_contract_from_abi(abi_json: &str) -> BaseContract { | ||
let j: serde_json::Value = serde_json::from_str(abi_json).unwrap(); | ||
let abi = &j.as_object().unwrap()["abi"]; | ||
let abi: Abi = serde_json::from_value(abi.to_owned()).unwrap(); | ||
BaseContract::from(abi) | ||
} | ||
use alloy_primitives::{address, Address, Bytes, U256}; | ||
|
||
/// L1BlockHashList wrapper. | ||
pub struct L1BlockHashList { | ||
base_contract: BaseContract, | ||
} | ||
|
||
impl Default for L1BlockHashList { | ||
fn default() -> Self { | ||
let base_contract = make_contract_from_abi(include_str!( | ||
"./out/L1BlockHashList.sol/L1BlockHashList.json" | ||
)); | ||
Self { base_contract } | ||
} | ||
} | ||
pub struct L1BlockHashList {} | ||
|
||
impl L1BlockHashList { | ||
pub(crate) fn address() -> Address { | ||
address!("3100000000000000000000000000000000000001") | ||
} | ||
|
||
pub(crate) fn init(&self, block_number: u64) -> Bytes { | ||
let args = ethereum_types::U256::from(block_number); | ||
self.base_contract | ||
.encode("initializeBlockNumber", args) | ||
.expect("ABI for system contract should be correct") | ||
pub(crate) fn init(block_number: u64) -> Bytes { | ||
let mut func_selector: Vec<u8> = vec![0x1f, 0x57, 0x83, 0x33]; // initializeBlockNumber(u256) 1f578333 | ||
|
||
let block_number = U256::from(block_number); | ||
func_selector.extend_from_slice(&block_number.to_be_bytes::<32>()); | ||
|
||
Bytes::from(func_selector) | ||
} | ||
|
||
pub(crate) fn set_block_info(&self, block_hash: [u8; 32], txs_commitments: [u8; 32]) -> Bytes { | ||
let args = (block_hash, txs_commitments); | ||
self.base_contract | ||
.encode("setBlockInfo", args) | ||
.expect("ABI for system contract should be correct") | ||
pub(crate) fn set_block_info(block_hash: [u8; 32], txs_commitments: [u8; 32]) -> Bytes { | ||
let mut func_selector = vec![0x0e, 0x27, 0xbc, 0x11]; // setBlockInfo(bytes32, bytes32) 0e27bc11 | ||
|
||
func_selector.extend_from_slice(&block_hash); | ||
func_selector.extend_from_slice(&txs_commitments); | ||
|
||
Bytes::from(func_selector) | ||
} | ||
|
||
/// Return input data to query the block hash by block number mapping | ||
pub fn get_block_hash(&self, block_number: u64) -> Bytes { | ||
let args = ethereum_types::U256::from(block_number); | ||
self.base_contract | ||
.encode("getBlockHash", args) | ||
.expect("ABI for system contract should be correct") | ||
pub fn get_block_hash(block_number: u64) -> Bytes { | ||
let mut func_selector: Vec<u8> = vec![0xee, 0x82, 0xac, 0x5e]; // getBlockHash(uint256) ee82ac5e | ||
|
||
let block_number = U256::from(block_number); | ||
println!("block_number: {:?}", block_number); | ||
func_selector.extend_from_slice(&block_number.to_be_bytes::<32>()); | ||
|
||
Bytes::from(func_selector) | ||
} | ||
|
||
#[allow(dead_code)] | ||
pub(crate) fn get_witness_root_by_number(&self, block_number: u64) -> Bytes { | ||
let args = ethereum_types::U256::from(block_number); | ||
self.base_contract | ||
.encode("getWitnessRootByNumber", args) | ||
.expect("ABI for system contract should be correct") | ||
pub(crate) fn get_witness_root_by_number(block_number: u64) -> Bytes { | ||
let mut func_selector: Vec<u8> = vec![0x61, 0xb2, 0x07, 0xe2]; // getWitnessRootByNumber(uint256) 61b207e2 | ||
|
||
let block_number = U256::from(block_number); | ||
func_selector.extend_from_slice(&block_number.to_be_bytes::<32>()); | ||
|
||
Bytes::from(func_selector) | ||
} | ||
} |
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