use reqwest::Url; use arweave::{Error, Address, Winstons, TxHash, winstons_as_numbers}; use serde::{Serialize, Deserialize}; pub struct Client { url: Url, } #[derive(Serialize, Debug)] struct FaucetReq<'a> { beneficiary: &'a Address, #[serde(with = "winstons_as_numbers")] quantity: &'a Winstons, } #[derive(Deserialize, Debug)] struct FaucetRsp { tx_id: TxHash, } impl Client { pub fn new() -> Result { let url = Url::parse(&std::env::var("LOOM_TARGET")?)?; Ok(Client { url }) } pub fn faucet(&self, a: A, q: Q) -> Result where A: AsRef
, Q: AsRef { let client = reqwest::Client::new(); let req = FaucetReq { beneficiary: a.as_ref(), quantity: q.as_ref() }; let mut rsp = client.post(self.url.join("faucet")?).json(&req).send()?; Ok(rsp.json::()?.tx_id) } }