diff --git a/.env.example b/.env.example index ea142ad..56ab087 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ -archiver_pk=... \ No newline at end of file +archiver_pk=... +network="./networks/your_network.json" \ No newline at end of file diff --git a/config.json b/config.json deleted file mode 100644 index 7def512..0000000 --- a/config.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "Ethereum", - "chain_id": 1, - "rpc": "https://eth.llamarpc.com", - "block_time": 12, - "start_block": 0, - "archiver_address": "0x197f818c1313DC58b32D88078ecdfB40EA822614", - "archive_pool_address": "0xa2A0D977847805fE224B789D8C4d3D711ab251e7" -} \ No newline at end of file diff --git a/networks/optimism.json b/networks/optimism.json new file mode 100644 index 0000000..f7d0475 --- /dev/null +++ b/networks/optimism.json @@ -0,0 +1,11 @@ +{ + "name": "Optimism", + "network_chain_id": 10, + "wvm_chain_id": 9999777, + "network_rpc": "https://mainnet.optimism.io", + "wvm_rpc": "https://testnet-rpc.wvm.dev", + "block_time": 2, + "start_block": 123820363, + "archiver_address": "0x197f818c1313DC58b32D88078ecdfB40EA822614", + "archive_pool_address": "0xa2A0D977847805fE224B789D8C4d3D711ab251e7" +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index f1e47b8..d77fa87 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ mod utils; #[tokio::main] async fn main() { // test_send().await; - let block = by_number(20490776).await; + let block = by_number(123820363).await; // let res = Some(Block {block.unwrap()}); println!("{:?}", block.as_ref().unwrap()); let x = serde_json::json!(block.as_ref().unwrap()); @@ -15,8 +15,9 @@ async fn main() { let y = Block::load_block_from_value(x).unwrap(); let borsh_res = to_vec(&y).unwrap(); let brotli_res = Block::brotli_compress(&borsh_res); - println!("{:?}", brotli_res); - let abc = vec![1,2]; + println!("borsh vec length: {:?}", borsh_res.len()); + println!("brotli vec length: {:?}", brotli_res.len()); + let _ = test_send(brotli_res).await; // if let Ok(Some(block_result)) = block { // println!("{:?}", block_result); diff --git a/src/utils/get_block.rs b/src/utils/get_block.rs index 1366f8f..ac60a45 100644 --- a/src/utils/get_block.rs +++ b/src/utils/get_block.rs @@ -5,7 +5,7 @@ use borsh::{BorshSerialize, BorshDeserialize, from_slice, to_vec}; pub async fn by_number(number: u64) -> Result>, ProviderError> { let network: Network = Network::config(); - let provider = Network::provider(&network).await; + let provider = Network::provider(&network, false).await; println!("{:#?}", network); let block = provider.get_block(number).await; diff --git a/src/utils/schema.rs b/src/utils/schema.rs index 9fa46eb..7a35ba7 100644 --- a/src/utils/schema.rs +++ b/src/utils/schema.rs @@ -5,12 +5,15 @@ use ethers_providers::{Http, Provider}; use std::convert::TryFrom; use serde_json::Value; use borsh_derive::{BorshDeserialize, BorshSerialize}; +use crate::utils::env_var::get_env_var; #[derive(Serialize, Deserialize, Debug)] pub struct Network { pub name: String, - pub chain_id: u32, - pub rpc: String, + pub network_chain_id: u32, + pub wvm_chain_id: u32, + pub network_rpc: String, + pub wvm_rpc: String, pub block_time: u32, pub start_block: u32, pub archiver_address: String, @@ -19,7 +22,8 @@ pub struct Network { impl Network { pub fn config() -> Network { - let mut file = File::open("./config.json").unwrap(); + let network_config = get_env_var("network").unwrap(); + let mut file = File::open(network_config).unwrap(); let mut data = String::new(); file.read_to_string(&mut data).unwrap(); @@ -30,11 +34,20 @@ impl Network { network } - pub async fn provider(&self) -> Provider { + pub async fn provider(&self, rpc: bool) -> Provider { + let target_rpc: &String; + let network: Network = Self::config(); - println!("{:#?}", network); + if rpc { + target_rpc = &network.wvm_rpc; + } else { + target_rpc = &network.network_rpc + } + + println!("TARGET RPC {}", target_rpc); + println!("{:#?}", &network); let provider: Provider = Provider::::try_from( - network.rpc + target_rpc ).expect("could not instantiate HTTP Provider"); provider diff --git a/src/utils/transaction.rs b/src/utils/transaction.rs index 7086cee..176d5e9 100644 --- a/src/utils/transaction.rs +++ b/src/utils/transaction.rs @@ -7,18 +7,18 @@ type Client = SignerMiddleware, Wallet>; pub async fn test_send(block_data: Vec) -> Result<(), Box> { let network = Network::config(); - let provider = Network::provider(&network).await; + let provider = Network::provider(&network, true).await; let private_key = get_env_var("archiver_pk").unwrap(); let wallet: LocalWallet = private_key .parse::()? - .with_chain_id(network.chain_id); // Change to correct network + .with_chain_id(network.wvm_chain_id); let client = SignerMiddleware::new(provider.clone(), wallet.clone()); let address_from = network.archiver_address.parse::
()?; let address_to = network.archive_pool_address.parse::
()?; - - send_transaction(&client, &address_from, &address_to, block_data).await?; + print_balances(&provider, &address_from, &address_to).await?; + send_transaction(&client, &address_from, &address_to, block_data).await?; Ok(()) } @@ -42,8 +42,8 @@ async fn send_transaction(client: &Client, address_from: &Address, address_to: & .value(U256::from(utils::parse_ether(0)?)) .from(address_from.clone()) .data(block_data); + println!("{:?}", tx); let tx = client.send_transaction(tx, None).await?.await?; - println!("Transaction Receipt: {}", serde_json::to_string(&tx)?); Ok(())