From 131b5548bffd4bfeacc43f5429c3fe209959652c Mon Sep 17 00:00:00 2001 From: silverpill <87225021+silverpill@users.noreply.github.com> Date: Thu, 30 May 2024 08:28:28 +0000 Subject: [PATCH 1/5] Make timeout configurable (#131) Co-authored-by: silverpill --- src/lib.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 863ee2a..5e2534e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,6 +77,7 @@ use std::{ num::NonZeroU64, ops::{Deref, RangeInclusive}, sync::Arc, + time::Duration, }; use tracing::*; use uuid::Uuid; @@ -248,6 +249,7 @@ struct RpcClientConfig { #[cfg_attr(docsrs, doc(cfg(feature = "rpc_authentication")))] rpc_auth: RpcAuthentication, proxy_address: Option, + timeout: Option, } /// Builder for generating a configured [`RpcClient`]. @@ -270,6 +272,7 @@ impl RpcClientBuilder { #[cfg(feature = "rpc_authentication")] rpc_auth: RpcAuthentication::None, proxy_address: None, + timeout: None, }, } } @@ -288,17 +291,23 @@ impl RpcClientBuilder { self } + /// Configures default request timeout. + pub fn timeout(mut self, timeout: Duration) -> Self { + self.config.timeout = Some(timeout); + self + } + /// Build and return the fully configured RPC client. pub fn build(self, addr: impl Into) -> anyhow::Result { let config = self.config; - let http_client_builder = reqwest::ClientBuilder::new(); - let http_client = if let Some(proxy_address) = config.proxy_address { - http_client_builder - .proxy(reqwest::Proxy::all(proxy_address)?) - .build()? - } else { - http_client_builder.build()? + let mut http_client_builder = reqwest::ClientBuilder::new(); + if let Some(proxy_address) = config.proxy_address { + http_client_builder = http_client_builder.proxy(reqwest::Proxy::all(proxy_address)?); + }; + if let Some(timeout) = config.timeout { + http_client_builder = http_client_builder.timeout(timeout); }; + let http_client = http_client_builder.build()?; Ok(RpcClient { inner: CallerWrapper(Arc::new(RemoteCaller { http_client, From 4e6e9233cd7dd75d6ac25b11a407dfeeb89e6d8b Mon Sep 17 00:00:00 2001 From: silverpill <87225021+silverpill@users.noreply.github.com> Date: Thu, 30 May 2024 08:37:15 +0000 Subject: [PATCH 2/5] Fix clippy error (#132) Co-authored-by: silverpill Co-authored-by: h4sh3d --- src/models.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/models.rs b/src/models.rs index de58bcf..570d034 100644 --- a/src/models.rs +++ b/src/models.rs @@ -13,7 +13,7 @@ // limitations under the License. // TODO: remove this when clippy error goes away... -#![allow(clippy::incorrect_clone_impl_on_copy_type)] +#![allow(clippy::non_canonical_clone_impl)] use crate::util::*; use chrono::prelude::*; From 6d44eefa8849e1e1e19f16f1a2a12a5bb55ac514 Mon Sep 17 00:00:00 2001 From: Piit Date: Thu, 30 May 2024 10:41:29 +0200 Subject: [PATCH 3/5] added get_block json rpc method (#123) * added get_block json rpc method * fix fmt check errors * fix clippy warnings * fix fmt warnings 2 --------- Co-authored-by: essecara Co-authored-by: h4sh3d --- src/lib.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 5e2534e..f3c3b00 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -63,6 +63,8 @@ pub use self::{models::*, util::*}; use jsonrpc_core::types::{Id, *}; use monero::{ + blockdata::block::Block, + consensus::deserialize, cryptonote::{hash::Hash as CryptoNoteHash, subaddress}, util::{address::PaymentId, amount}, Address, Amount, @@ -409,6 +411,32 @@ impl DaemonJsonRpcClient { .count) } + pub async fn get_block(&self, selector: GetBlockHeaderSelector) -> anyhow::Result { + let (request, params) = match selector { + GetBlockHeaderSelector::Hash(hash) => ( + "get_block", + RpcParams::map( + Some(("hash", serde_json::to_value(HashString(hash)).unwrap())).into_iter(), + ), + ), + GetBlockHeaderSelector::Height(height) => ( + "get_block", + RpcParams::map(Some(("height", height.into())).into_iter()), + ), + GetBlockHeaderSelector::Last => ("get_block", RpcParams::None), + }; + + match self.inner.request::(request, params).await { + Ok(res) => { + let block_str = res["blob"].as_str().unwrap(); + let block_hex = hex::decode(block_str).unwrap(); + let block: Block = deserialize(&block_hex).unwrap(); + Ok(block) + } + Err(e) => Err(anyhow::Error::msg(format!("Can not fetch block: {}", e))), + } + } + /// Look up a block's hash by its height. pub async fn on_get_block_hash(&self, height: u64) -> anyhow::Result { let res = self From dcf5fd96ff09053d59cf5d553f47b67f492c0bab Mon Sep 17 00:00:00 2001 From: silverpill <87225021+silverpill@users.noreply.github.com> Date: Thu, 30 May 2024 08:42:19 +0000 Subject: [PATCH 4/5] Add rustls support (#133) Co-authored-by: silverpill Co-authored-by: h4sh3d --- Cargo.toml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1d46ba6..5fa6bb4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,13 +13,13 @@ description = "RPC client for Monero daemon and wallet" [dependencies] anyhow = "1" chrono = { version = "0.4", default-features = false, features = ["serde"] } -diqwest = { version = "1.1", optional = true } +diqwest = { version = "1.2.1", default-features = false, optional = true } fixed-hash = "0.8" hex = "0.4" http = "0.2" jsonrpc-core = "18" monero = { version = "0.19", features = ["serde"] } -reqwest = { version = "0.11", features = ["json", "socks"] } +reqwest = { version = "0.11", default-features = false, features = ["json", "socks"] } serde = { version = "1", features = ["derive"] } serde_json = "1" tracing = "0.1" @@ -33,7 +33,11 @@ serde_test = "1.0" tokio = { version = "1.12.0", features = ["full"] } [features] +default = ["native-tls"] + rpc_authentication = ["diqwest"] +native-tls = ["reqwest/native-tls", "diqwest/default"] +rustls-tls = ["reqwest/rustls-tls-native-roots", "diqwest/rustls-tls"] [package.metadata.docs.rs] all-features = true From 519878d1413a8e220461852cf24c8f5bca23cc12 Mon Sep 17 00:00:00 2001 From: bytenotbark <158315302+bytenotbark@users.noreply.github.com> Date: Thu, 30 May 2024 01:47:19 -0700 Subject: [PATCH 5/5] Fix WalletClient::get_transfers with Out=true in Category Selector (#127) * Update models.rs Convert GotTransfer::suggested_confirmations_threshold to Option from u64 to enable Wallet.gettransfers(...) with Out: true in the Category Selector * Update all_clients_interaction.rs update test --------- Co-authored-by: h4sh3d --- src/models.rs | 2 +- tests/clients_tests/all_clients_interaction.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/models.rs b/src/models.rs index 570d034..3d98065 100644 --- a/src/models.rs +++ b/src/models.rs @@ -516,7 +516,7 @@ pub struct GotTransfer { /// JSON object containing the major & minor subaddress index. pub subaddr_index: subaddress::Index, /// Estimation of the confirmations needed for the transaction to be included in a block. - pub suggested_confirmations_threshold: u64, + pub suggested_confirmations_threshold: Option, /// POSIX timestamp for when this transfer was first confirmed in a block (or timestamp submission if not mined yet). #[serde(with = "chrono::serde::ts_seconds")] pub timestamp: DateTime, diff --git a/tests/clients_tests/all_clients_interaction.rs b/tests/clients_tests/all_clients_interaction.rs index b7962df..128b6cb 100644 --- a/tests/clients_tests/all_clients_interaction.rs +++ b/tests/clients_tests/all_clients_interaction.rs @@ -445,7 +445,7 @@ pub async fn run() { note: "".to_string(), payment_id: HashString(PaymentId::zero()), subaddr_index: Index { major: 0, minor: 0 }, - suggested_confirmations_threshold: 1, + suggested_confirmations_threshold: Some(1), // this is any date, since it will not be tested against anything timestamp: DateTime::from_naive_utc_and_offset( NaiveDateTime::from_timestamp_opt(0, 0).unwrap(),