use { super::*, base64::Engine, hyper::{client::HttpConnector, Body, Client, Method, Request, Uri}, serde_json::{json, Value}, }; pub(crate) struct Fetcher { auth: String, client: Client<HttpConnector>, url: Uri, } #[derive(Deserialize, Debug)] struct JsonResponse<T> { error: Option<JsonError>, id: usize, result: Option<T>, } #[derive(Deserialize, Debug)] struct JsonError { code: i32, message: String, } impl Fetcher { pub(crate) fn new(options: &Options) -> Result<Self> { let client = Client::new(); let url = if options.rpc_url().starts_with("http://") { options.rpc_url() } else { "http://".to_string() + &options.rpc_url() }; let url = Uri::try_from(&url).map_err(|e| anyhow!("Invalid rpc url {url}: {e}"))?; let (user, password) = options.auth()?.get_user_pass()?; let auth = format!("{}:{}", user.unwrap(), password.unwrap()); let auth = format!( "Basic {}", &base64::engine::general_purpose::STANDARD.encode(auth) ); Ok(Fetcher { client, url, auth })
Inscription number 44,982,563
Genesis block 819,059
File type text
File size 1.03 KB
Creation date Nov 30,2023 12:42 pm