Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
archiver_pk=...
archiver_pk=...
network="./networks/your_network.json"
9 changes: 0 additions & 9 deletions config.json

This file was deleted.

11 changes: 11 additions & 0 deletions networks/optimism.json
Original file line number Diff line number Diff line change
@@ -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"
}
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@ 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());
println!("{:?}", x);
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);
Expand Down
2 changes: 1 addition & 1 deletion src/utils/get_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use borsh::{BorshSerialize, BorshDeserialize, from_slice, to_vec};

pub async fn by_number(number: u64) -> Result<Option<Block<H256>>, 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;
Expand Down
25 changes: 19 additions & 6 deletions src/utils/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand All @@ -30,11 +34,20 @@ impl Network {
network
}

pub async fn provider(&self) -> Provider<Http> {
pub async fn provider(&self, rpc: bool) -> Provider<Http> {
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<Http> = Provider::<Http>::try_from(
network.rpc
target_rpc
).expect("could not instantiate HTTP Provider");

provider
Expand Down
10 changes: 5 additions & 5 deletions src/utils/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ type Client = SignerMiddleware<Provider<Http>, Wallet<k256::ecdsa::SigningKey>>;

pub async fn test_send(block_data: Vec<u8>) -> Result<(), Box<dyn std::error::Error>> {
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::<LocalWallet>()?
.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::<Address>()?;
let address_to = network.archive_pool_address.parse::<Address>()?;

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(())
}
Expand All @@ -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(())
Expand Down