Initialize reqwest clients with verbose logging

This commit is contained in:
Thomas Eizinger 2021-04-19 10:10:46 +10:00
parent 7e688eb7e8
commit 0970c2bc72
No known key found for this signature in database
GPG key ID: 651AC83A6C6C8B96
6 changed files with 34 additions and 24 deletions

View file

@ -1,3 +1,4 @@
use anyhow::{Context, Result};
use serde::Deserialize;
#[jsonrpc_client::api(version = "2.0")]
@ -17,13 +18,15 @@ pub struct Client {
impl Client {
/// New local host monerod RPC client.
pub fn localhost(port: u16) -> Self {
Self {
inner: reqwest::Client::new(),
pub fn localhost(port: u16) -> Result<Self> {
Ok(Self {
inner: reqwest::ClientBuilder::new()
.connection_verbose(true)
.build()?,
base_url: format!("http://127.0.0.1:{}/json_rpc", port)
.parse()
.expect("url is well formed"),
}
.context("url is well formed")?,
})
}
}

View file

@ -1,4 +1,4 @@
use anyhow::Result;
use anyhow::{Context, Result};
use serde::{de::Error, Deserialize, Deserializer, Serialize};
#[jsonrpc_client::api(version = "2.0")]
@ -43,20 +43,22 @@ pub struct Client {
impl Client {
/// Constructs a monero-wallet-rpc client with localhost endpoint.
pub fn localhost(port: u16) -> Self {
pub fn localhost(port: u16) -> Result<Self> {
Client::new(
format!("http://127.0.0.1:{}/json_rpc", port)
.parse()
.expect("url is well formed"),
.context("url is well formed")?,
)
}
/// Constructs a monero-wallet-rpc client with `url` endpoint.
pub fn new(url: reqwest::Url) -> Self {
Self {
inner: reqwest::Client::new(),
pub fn new(url: reqwest::Url) -> Result<Self> {
Ok(Self {
inner: reqwest::ClientBuilder::new()
.connection_verbose(true)
.build()?,
base_url: url,
}
})
}
/// Transfers `amount` monero from `account_index` to `address`.