Skip to main content

farcaster_rs/users/
get_custody_address.rs

1use crate::constants::merkle::API_ROOT;
2use crate::types::user::custody_address::CustodyAddressRoot;
3use crate::Farcaster;
4use std::error::Error;
5
6impl Farcaster {
7    /// Get a custody address by FID
8    pub async fn get_custody_address_by_fid(
9        &self,
10        fid: i64,
11    ) -> Result<CustodyAddressRoot, Box<dyn Error>> {
12        let url = format!("{}/v2/custody-address?fid={}", API_ROOT, fid);
13
14        let custody_address_reqwest = &self.reqwest_get(&url).await?;
15
16        let custody_address: CustodyAddressRoot = serde_json::from_str(&custody_address_reqwest)?;
17
18        Ok(custody_address)
19    }
20
21    /// Get a custody address by FID
22    pub async fn get_custody_address_by_username(
23        &self,
24        username: &str,
25    ) -> Result<CustodyAddressRoot, Box<dyn Error>> {
26        let url = format!("{}/v2/custody-address?fname={}", API_ROOT, username);
27
28        let custody_address_reqwest = &self.reqwest_get(&url).await?;
29
30        let custody_address: CustodyAddressRoot = serde_json::from_str(&custody_address_reqwest)?;
31
32        Ok(custody_address)
33    }
34
35    /// Get a custody address by FID
36    pub async fn get_custody_address_by_address(
37        &self,
38        address: &str,
39    ) -> Result<CustodyAddressRoot, Box<dyn Error>> {
40        let fid = &self.get_user_by_address(address).await?;
41
42        let url = format!("{}/v2/custody-address?fid={}", API_ROOT, fid.fid);
43
44        let custody_address_reqwest = &self.reqwest_get(&url).await?;
45
46        let custody_address: CustodyAddressRoot = serde_json::from_str(&custody_address_reqwest)?;
47
48        Ok(custody_address)
49    }
50}