2022-08-21 15:21:50 +00:00
|
|
|
use ethers::prelude::Address;
|
|
|
|
use eyre::Result;
|
|
|
|
use jsonrpsee::{core::client::ClientT, http_client::HttpClientBuilder, rpc_params};
|
|
|
|
|
|
|
|
use super::types::Proof;
|
|
|
|
|
2022-08-21 16:27:19 +00:00
|
|
|
pub struct Rpc {
|
2022-08-21 15:21:50 +00:00
|
|
|
rpc: String,
|
|
|
|
}
|
|
|
|
|
2022-08-21 16:27:19 +00:00
|
|
|
impl Rpc {
|
2022-08-21 15:21:50 +00:00
|
|
|
pub fn new(rpc: &str) -> Self {
|
2022-08-21 16:27:19 +00:00
|
|
|
Rpc { rpc: rpc.to_string() }
|
2022-08-21 15:21:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn get_proof(&self, address: &Address, block: u64) -> Result<Proof> {
|
|
|
|
let client = HttpClientBuilder::default().build(&self.rpc)?;
|
|
|
|
let block_hex = format!("0x{:x}", block);
|
|
|
|
let addr_hex = format!("0x{}", hex::encode(address.as_bytes()));
|
|
|
|
let params = rpc_params!(addr_hex, [""], block_hex);
|
|
|
|
Ok(client.request("eth_getProof", params).await?)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|