Created
February 6, 2022 16:46
-
-
Save 0xrin1/f5a6c6c7457feda7476f94b3ef5fdece to your computer and use it in GitHub Desktop.
invalid type: map, expected a string
This file contains hidden or 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
use ethers::prelude::*; | |
use ethers_providers::Ipc; | |
use std::sync::Arc; | |
use crate::bindings::{PcsFactory, PairCreatedFilter, ERC20}; | |
pub struct Pcs { | |
client: Arc<Provider<Ipc>>, | |
pcs_factory: PcsFactory<Provider<Ipc>>, | |
} | |
impl Pcs { | |
pub async fn new(client: Arc<Provider<Ipc>>) -> anyhow::Result<Pcs> { | |
let address: Address = "0xca143ce32fe78f1f7019d7d551a6402fc5350c73".parse::<Address>()?; | |
let pcs_factory = PcsFactory::new(address, client.clone()); | |
Ok(Self { | |
client, | |
pcs_factory, | |
}) | |
} | |
pub async fn listen(&mut self) -> anyhow::Result<()> { | |
let pcs_factory = self.pcs_factory.clone(); | |
let events = pcs_factory.events(); | |
let mut stream = events.subscribe().await?; | |
while let Some(ev) = stream.next().await { | |
self.handle_event(ev.unwrap()).await?; | |
} | |
Ok(()) | |
} | |
async fn handle_event(&mut self, event: PairCreatedFilter) -> anyhow::Result<()> { | |
println!("event.token_0 {:?}", event.token_0); | |
let token_0 = ERC20::new(event.token_0, self.client.clone()); | |
let token_0_symbol = token_0.symbol(); | |
println!("{:?} token_0_symbol", token_0_symbol.call().await); | |
Ok(()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment