frames_core/provider/
farcaster.rs1use std::sync::Arc;
2
3use ethers::providers::Middleware;
4use ethers::{
5 abi::Abi,
6 contract::Contract,
7 types::{Address, U256},
8};
9
10pub struct FarcasterProvider<T: Middleware + 'static> {
11 pub inner: Arc<T>,
12}
13
14impl<T: Middleware + 'static> FarcasterProvider<T> {
15 pub fn new(provider: T) -> Self {
16 Self { inner: Arc::new(provider) }
17 }
18
19 pub async fn get_custody_address_by_fid(
20 &self,
21 fid: usize,
22 ) -> Result<Option<Address>, Box<dyn std::error::Error>> {
23 let contract_address: Address =
24 "0x00000000Fc6c5F01Fc30151999387Bb99A9f489b".parse().expect("Parse Address Error");
25 let contract_abi: Abi = serde_json::from_str(
26 r#"[{
27 "inputs":[{"internalType":"uint256","name":"fid","type":"uint256"}],
28 "name":"custodyOf",
29 "outputs":[{"internalType":"address","name":"","type":"address"}],
30 "stateMutability":"view","type":"function"
31 }]"#,
32 )?;
33
34 let contract = Contract::new(contract_address, contract_abi, self.inner.clone());
35 match contract.method::<_, Address>("custodyOf", U256::from(fid)).unwrap().call().await {
36 Ok(value) => Ok(Some(value)),
37 Err(e) => Err(Box::new(e)),
38 }
39 }
40}