helios/src/main.rs

42 lines
1.2 KiB
Rust
Raw Normal View History

use eyre::Result;
2022-08-16 22:59:07 +00:00
2022-08-19 22:43:58 +00:00
use consensus::*;
2022-08-20 14:10:28 +00:00
use execution_rpc::*;
use proof::*;
use utils::hex_str_to_bytes;
2022-08-19 22:43:58 +00:00
pub mod consensus;
pub mod consensus_rpc;
2022-08-20 14:10:28 +00:00
pub mod execution_rpc;
2022-08-16 22:59:07 +00:00
pub mod utils;
2022-08-19 00:33:44 +00:00
pub mod proof;
#[tokio::main]
async fn main() -> Result<()> {
2022-08-19 22:43:58 +00:00
let rpc = "http://testing.prater.beacon-api.nimbus.team";
let checkpoint = "0x172128eadf1da46467f4d6a822206698e2d3f957af117dd650954780d680dc99";
let mut client = ConsensusClient::new(rpc, checkpoint).await?;
2022-08-20 14:10:28 +00:00
let rpc = "https://eth-goerli.g.alchemy.com:443/v2/o_8Qa9kgwDPf9G8sroyQ-uQtyhyWa3ao";
let execution = ExecutionRpc::new(rpc);
2022-08-19 22:43:58 +00:00
client.sync().await?;
2022-08-19 00:33:44 +00:00
2022-08-19 22:43:58 +00:00
let payload = client.get_execution_payload().await?;
println!("verified execution block hash: {}", hex::encode(payload.block_hash));
2022-08-20 14:10:28 +00:00
let addr = "0x25c4a76E7d118705e7Ea2e9b7d8C59930d8aCD3b";
let proof = execution.get_proof(addr, payload.block_number).await?;
let account_path = get_account_path(&hex_str_to_bytes(addr)?);
let account_encoded = encode_account(&proof);
let is_valid = verify_proof(&proof.account_proof, &payload.state_root, &account_path, &account_encoded);
println!("is account proof valid: {}", is_valid);
Ok(())
}