From 0155bf2fd501c4833fbbdee70384bfb2726b1eb1 Mon Sep 17 00:00:00 2001 From: Chloe Martin Date: Tue, 3 Sep 2024 09:51:14 -0400 Subject: [PATCH 1/6] Refactor RPC apis --- crates/iota-core/src/authority.rs | 17 ++++++++ .../src/apis/transaction_builder_api.rs | 5 ++- crates/iota-indexer/src/indexer_reader.rs | 4 +- .../src/transaction_builder_api.rs | 32 +++++++++----- .../src/generate_json_rpc_spec.rs | 11 +++-- crates/iota-sdk/src/apis.rs | 28 ++++++------ crates/iota-sdk/src/lib.rs | 43 +++++++------------ crates/iota-transaction-builder/src/lib.rs | 33 ++++++++++++-- 8 files changed, 108 insertions(+), 65 deletions(-) diff --git a/crates/iota-core/src/authority.rs b/crates/iota-core/src/authority.rs index 9fd37e26eed..ec3fc37fb64 100644 --- a/crates/iota-core/src/authority.rs +++ b/crates/iota-core/src/authority.rs @@ -794,6 +794,23 @@ pub struct AuthorityState { pub overload_info: AuthorityOverloadInfo, } +impl core::fmt::Debug for AuthorityState { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("AuthorityState") + .field("name", &self.name) + .field("db_checkpoint_config", &self.db_checkpoint_config) + .field( + "expensive_safety_check_config", + &self.expensive_safety_check_config, + ) + .field("transaction_deny_config", &self.transaction_deny_config) + .field("certificate_deny_config", &self.certificate_deny_config) + .field("debug_dump_config", &self.debug_dump_config) + .field("authority_overload_config", &self.authority_overload_config) + .finish() + } +} + /// The authority state encapsulates all state, drives execution, and ensures /// safety. /// diff --git a/crates/iota-indexer/src/apis/transaction_builder_api.rs b/crates/iota-indexer/src/apis/transaction_builder_api.rs index 7fb62fed9a9..f558e3b6942 100644 --- a/crates/iota-indexer/src/apis/transaction_builder_api.rs +++ b/crates/iota-indexer/src/apis/transaction_builder_api.rs @@ -15,14 +15,15 @@ use move_core_types::language_storage::StructTag; use super::governance_api::GovernanceReadApi; use crate::indexer_reader::IndexerReader; +#[derive(Clone, Debug)] pub(crate) struct TransactionBuilderApi { inner: IndexerReader, } impl TransactionBuilderApi { #[allow(clippy::new_ret_no_self)] - pub fn new(inner: IndexerReader) -> IotaTransactionBuilderApi { - IotaTransactionBuilderApi::new_with_data_reader(std::sync::Arc::new(Self { inner })) + pub fn new(inner: IndexerReader) -> IotaTransactionBuilderApi { + IotaTransactionBuilderApi::new_with_data_reader(Self { inner }) } } diff --git a/crates/iota-indexer/src/indexer_reader.rs b/crates/iota-indexer/src/indexer_reader.rs index a38cb56aa2d..33ed6775120 100644 --- a/crates/iota-indexer/src/indexer_reader.rs +++ b/crates/iota-indexer/src/indexer_reader.rs @@ -58,7 +58,7 @@ pub const TX_SEQUENCE_NUMBER_STR: &str = "tx_sequence_number"; pub const TRANSACTION_DIGEST_STR: &str = "transaction_digest"; pub const EVENT_SEQUENCE_NUMBER_STR: &str = "event_sequence_number"; -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct IndexerReader { pool: crate::db::PgConnectionPool, package_cache: PackageCache, @@ -1619,7 +1619,7 @@ impl IndexerReader { } } -#[derive(Clone, Default)] +#[derive(Debug, Clone, Default)] struct PackageCache { inner: Arc>>, } diff --git a/crates/iota-json-rpc/src/transaction_builder_api.rs b/crates/iota-json-rpc/src/transaction_builder_api.rs index 2c034f7d2f3..017dfa00a64 100644 --- a/crates/iota-json-rpc/src/transaction_builder_api.rs +++ b/crates/iota-json-rpc/src/transaction_builder_api.rs @@ -23,22 +23,27 @@ use iota_types::{ use jsonrpsee::{core::RpcResult, RpcModule}; use move_core_types::language_storage::StructTag; -use crate::{authority_state::StateRead, IotaRpcModule}; +use crate::IotaRpcModule; -pub struct TransactionBuilderApi(TransactionBuilder); +#[derive(Clone, Debug)] +pub struct TransactionBuilderApi(TransactionBuilder); -impl TransactionBuilderApi { +impl TransactionBuilderApi { pub fn new(state: Arc) -> Self { - let reader = Arc::new(AuthorityStateDataReader::new(state)); - Self(TransactionBuilder::new(reader)) + Self(TransactionBuilder::new(AuthorityStateDataReader::new( + state, + ))) } +} - pub fn new_with_data_reader(data_reader: Arc) -> Self { +impl TransactionBuilderApi { + pub fn new_with_data_reader(data_reader: R) -> Self { Self(TransactionBuilder::new(data_reader)) } } -pub struct AuthorityStateDataReader(Arc); +#[derive(Clone, Debug)] +pub struct AuthorityStateDataReader(Arc); impl AuthorityStateDataReader { pub fn new(state: Arc) -> Self { @@ -56,11 +61,12 @@ impl DataReader for AuthorityStateDataReader { Ok(self .0 // DataReader is used internally, don't need a limit - .get_owner_objects( + .get_owner_objects_iterator( address, None, Some(IotaObjectDataFilter::StructType(object_type)), - )?) + )? + .collect()) } async fn get_object_with_options( @@ -79,7 +85,9 @@ impl DataReader for AuthorityStateDataReader { } #[async_trait] -impl TransactionBuilderServer for TransactionBuilderApi { +impl TransactionBuilderServer + for TransactionBuilderApi +{ async fn transfer_object( &self, signer: IotaAddress, @@ -366,7 +374,9 @@ impl TransactionBuilderServer for TransactionBuilderApi { } } -impl IotaRpcModule for TransactionBuilderApi { +impl IotaRpcModule + for TransactionBuilderApi +{ fn rpc(self) -> RpcModule { self.into_rpc() } diff --git a/crates/iota-open-rpc/src/generate_json_rpc_spec.rs b/crates/iota-open-rpc/src/generate_json_rpc_spec.rs index e8a5f245308..76854c9c567 100644 --- a/crates/iota-open-rpc/src/generate_json_rpc_spec.rs +++ b/crates/iota-open-rpc/src/generate_json_rpc_spec.rs @@ -9,9 +9,12 @@ use clap::{Parser, ValueEnum}; // use iota_json_rpc::api::ExtendedApiOpenRpc; use iota_json_rpc::coin_api::CoinReadApi; use iota_json_rpc::{ - governance_api::GovernanceReadApi, iota_rpc_doc, read_api::ReadApi, - transaction_builder_api::TransactionBuilderApi, - transaction_execution_api::TransactionExecutionApi, IotaRpcModule, + governance_api::GovernanceReadApi, + iota_rpc_doc, + read_api::ReadApi, + transaction_builder_api::{AuthorityStateDataReader, TransactionBuilderApi}, + transaction_execution_api::TransactionExecutionApi, + IotaRpcModule, }; use iota_json_rpc_api::{IndexerApiOpenRpc, MoveUtilsOpenRpc}; use pretty_assertions::assert_str_eq; @@ -51,7 +54,7 @@ async fn main() { open_rpc.add_module(CoinReadApi::rpc_doc_module()); open_rpc.add_module(IndexerApiOpenRpc::module_doc()); open_rpc.add_module(TransactionExecutionApi::rpc_doc_module()); - open_rpc.add_module(TransactionBuilderApi::rpc_doc_module()); + open_rpc.add_module(TransactionBuilderApi::::rpc_doc_module()); open_rpc.add_module(GovernanceReadApi::rpc_doc_module()); // temporarily remove api ref content for indexer methods // open_rpc.add_module(ExtendedApiOpenRpc::module_doc()); diff --git a/crates/iota-sdk/src/apis.rs b/crates/iota-sdk/src/apis.rs index 1341e666033..13d96795de4 100644 --- a/crates/iota-sdk/src/apis.rs +++ b/crates/iota-sdk/src/apis.rs @@ -2,7 +2,7 @@ // Modifications Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use std::{collections::BTreeMap, future, sync::Arc, time::Instant}; +use std::{collections::BTreeMap, future, time::Instant}; use fastcrypto::encoding::Base64; use futures::{stream, StreamExt}; @@ -43,13 +43,13 @@ const WAIT_FOR_LOCAL_EXECUTION_RETRY_COUNT: u8 = 3; /// The main read API structure with functions for retrieving data about /// different objects and transactions -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct ReadApi { - api: Arc, + api: RpcClient, } impl ReadApi { - pub(crate) fn new(api: Arc) -> Self { + pub(crate) fn new(api: RpcClient) -> Self { Self { api } } /// Return a paginated response with the objects owned by the given address, @@ -756,11 +756,11 @@ impl ReadApi { /// Iota network regarding the coins owned by an address. #[derive(Debug, Clone)] pub struct CoinReadApi { - api: Arc, + api: RpcClient, } impl CoinReadApi { - pub(crate) fn new(api: Arc) -> Self { + pub(crate) fn new(api: RpcClient) -> Self { Self { api } } @@ -1055,13 +1055,13 @@ impl CoinReadApi { /// Event API provides the functionality to fetch, query, or subscribe to events /// on the Iota network. -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct EventApi { - api: Arc, + api: RpcClient, } impl EventApi { - pub(crate) fn new(api: Arc) -> Self { + pub(crate) fn new(api: RpcClient) -> Self { Self { api } } @@ -1169,13 +1169,13 @@ impl EventApi { /// Quorum API that provides functionality to execute a transaction block and /// submit it to the fullnode(s). -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct QuorumDriverApi { - api: Arc, + api: RpcClient, } impl QuorumDriverApi { - pub(crate) fn new(api: Arc) -> Self { + pub(crate) fn new(api: RpcClient) -> Self { Self { api } } @@ -1232,11 +1232,11 @@ impl QuorumDriverApi { /// Governance API provides the staking functionality. #[derive(Debug, Clone)] pub struct GovernanceApi { - api: Arc, + api: RpcClient, } impl GovernanceApi { - pub(crate) fn new(api: Arc) -> Self { + pub(crate) fn new(api: RpcClient) -> Self { Self { api } } diff --git a/crates/iota-sdk/src/lib.rs b/crates/iota-sdk/src/lib.rs index 8ddd592929b..74a753394e1 100644 --- a/crates/iota-sdk/src/lib.rs +++ b/crates/iota-sdk/src/lib.rs @@ -73,11 +73,7 @@ //! For detailed examples, please check the APIs docs and the examples folder //! in the [main repository](https://github.com/iotaledger/iota/tree/main/crates/iota-sdk/examples). -use std::{ - fmt::{Debug, Formatter}, - sync::Arc, - time::Duration, -}; +use std::{fmt::Debug, sync::Arc, time::Duration}; use async_trait::async_trait; pub use iota_json as json; @@ -232,7 +228,7 @@ impl IotaClientBuilder { builder = builder.enable_ws_ping(PingConfig::new().ping_interval(duration)) } - Some(builder.build(url).await?) + Some(Arc::new(builder.build(url).await?)) } else { None }; @@ -243,11 +239,10 @@ impl IotaClientBuilder { .request_timeout(self.request_timeout) .build(http)?; - let info = Self::get_server_info(&http, &ws).await?; + let info = Self::get_server_info(&http, ws.as_deref()).await?; - let rpc = RpcClient { http, ws, info }; - let api = Arc::new(rpc); - let read_api = Arc::new(ReadApi::new(api.clone())); + let api = RpcClient { http, ws, info }; + let read_api = ReadApi::new(api.clone()); let quorum_driver_api = QuorumDriverApi::new(api.clone()); let event_api = EventApi::new(api.clone()); let transaction_builder = TransactionBuilder::new(read_api.clone()); @@ -337,7 +332,7 @@ impl IotaClientBuilder { /// Fails with an error if it cannot call the RPC discover. async fn get_server_info( http: &HttpClient, - ws: &Option, + ws: Option<&WsClient>, ) -> Result { let rpc_spec: Value = http.request("rpc.discover", rpc_params![]).await?; let version = rpc_spec @@ -412,35 +407,27 @@ impl IotaClientBuilder { /// Ok(()) /// } /// ``` -#[derive(Clone)] +#[derive(Clone, Debug)] pub struct IotaClient { - api: Arc, - transaction_builder: TransactionBuilder, - read_api: Arc, + api: RpcClient, + transaction_builder: TransactionBuilder, + read_api: ReadApi, coin_read_api: CoinReadApi, event_api: EventApi, quorum_driver_api: QuorumDriverApi, governance_api: GovernanceApi, } +#[derive(Clone, Debug)] pub(crate) struct RpcClient { http: HttpClient, - ws: Option, + ws: Option>, info: ServerInfo, } -impl Debug for RpcClient { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - write!( - f, - "RPC client. Http: {:?}, Websocket: {:?}", - self.http, self.ws - ) - } -} - /// ServerInfo contains all the useful information regarding the API version, /// the available RPC calls, and subscriptions. +#[derive(Clone, Debug)] struct ServerInfo { rpc_methods: Vec, subscriptions: Vec, @@ -509,7 +496,7 @@ impl IotaClient { } /// Returns a reference to the transaction builder API. - pub fn transaction_builder(&self) -> &TransactionBuilder { + pub fn transaction_builder(&self) -> &TransactionBuilder { &self.transaction_builder } @@ -520,7 +507,7 @@ impl IotaClient { /// Returns a reference to the underlying WebSocket client, if any. pub fn ws(&self) -> Option<&WsClient> { - self.api.ws.as_ref() + self.api.ws.as_deref() } } diff --git a/crates/iota-transaction-builder/src/lib.rs b/crates/iota-transaction-builder/src/lib.rs index 79fc2877113..5ecdb41b816 100644 --- a/crates/iota-transaction-builder/src/lib.rs +++ b/crates/iota-transaction-builder/src/lib.rs @@ -60,11 +60,36 @@ pub trait DataReader { async fn get_reference_gas_price(&self) -> Result; } -#[derive(Clone)] -pub struct TransactionBuilder(Arc); +#[async_trait] +impl DataReader for Arc { + async fn get_owned_objects( + &self, + address: IotaAddress, + object_type: StructTag, + ) -> Result, anyhow::Error> { + self.as_ref().get_owned_objects(address, object_type).await + } + + async fn get_object_with_options( + &self, + object_id: ObjectID, + options: IotaObjectDataOptions, + ) -> Result { + self.as_ref() + .get_object_with_options(object_id, options) + .await + } + + async fn get_reference_gas_price(&self) -> Result { + self.as_ref().get_reference_gas_price().await + } +} + +#[derive(Clone, Debug)] +pub struct TransactionBuilder(R); -impl TransactionBuilder { - pub fn new(data_reader: Arc) -> Self { +impl TransactionBuilder { + pub fn new(data_reader: R) -> Self { Self(data_reader) } From 715f26785d21e8870fdab484bf1b5e5479429edf Mon Sep 17 00:00:00 2001 From: Chloe Martin Date: Wed, 4 Sep 2024 10:15:02 -0400 Subject: [PATCH 2/6] cleanup --- .../src/transaction_builder_api.rs | 17 +++++++---------- crates/iota-sdk/src/lib.rs | 10 +++++++++- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/crates/iota-json-rpc/src/transaction_builder_api.rs b/crates/iota-json-rpc/src/transaction_builder_api.rs index 017dfa00a64..aa0c738177d 100644 --- a/crates/iota-json-rpc/src/transaction_builder_api.rs +++ b/crates/iota-json-rpc/src/transaction_builder_api.rs @@ -23,7 +23,7 @@ use iota_types::{ use jsonrpsee::{core::RpcResult, RpcModule}; use move_core_types::language_storage::StructTag; -use crate::IotaRpcModule; +use crate::{authority_state::StateRead, IotaRpcModule}; #[derive(Clone, Debug)] pub struct TransactionBuilderApi(TransactionBuilder); @@ -58,15 +58,12 @@ impl DataReader for AuthorityStateDataReader { address: IotaAddress, object_type: StructTag, ) -> Result, anyhow::Error> { - Ok(self - .0 - // DataReader is used internally, don't need a limit - .get_owner_objects_iterator( - address, - None, - Some(IotaObjectDataFilter::StructType(object_type)), - )? - .collect()) + Ok(StateRead::get_owner_objects( + self.0.as_ref(), + address, + None, + Some(IotaObjectDataFilter::StructType(object_type)), + )?) } async fn get_object_with_options( diff --git a/crates/iota-sdk/src/lib.rs b/crates/iota-sdk/src/lib.rs index eb9f4437561..0d8cefe5fcc 100644 --- a/crates/iota-sdk/src/lib.rs +++ b/crates/iota-sdk/src/lib.rs @@ -407,7 +407,7 @@ impl IotaClientBuilder { /// Ok(()) /// } /// ``` -#[derive(Clone, Debug)] +#[derive(Clone)] pub struct IotaClient { api: RpcClient, transaction_builder: TransactionBuilder, @@ -418,6 +418,14 @@ pub struct IotaClient { governance_api: GovernanceApi, } +impl core::fmt::Debug for IotaClient { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("IotaClient") + .field("api", &self.api) + .finish() + } +} + #[derive(Clone, Debug)] pub(crate) struct RpcClient { http: HttpClient, From 6ca561c46ef94c7d1e7a6d4b2d6d1d3873a29d17 Mon Sep 17 00:00:00 2001 From: Chloe Martin Date: Thu, 5 Sep 2024 10:02:49 -0400 Subject: [PATCH 3/6] Re-wrap RpcClient --- crates/iota-sdk/src/apis/coin_read.rs | 6 +++--- crates/iota-sdk/src/apis/event.rs | 6 +++--- crates/iota-sdk/src/apis/governance.rs | 6 +++--- crates/iota-sdk/src/apis/quorum_driver.rs | 6 +++--- crates/iota-sdk/src/apis/read.rs | 6 +++--- crates/iota-sdk/src/lib.rs | 16 +++++++++------- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/crates/iota-sdk/src/apis/coin_read.rs b/crates/iota-sdk/src/apis/coin_read.rs index afc3f9987a2..9d2fb4d21d5 100644 --- a/crates/iota-sdk/src/apis/coin_read.rs +++ b/crates/iota-sdk/src/apis/coin_read.rs @@ -15,18 +15,18 @@ use iota_types::{ use crate::{ error::{Error, IotaRpcResult}, - RpcClient, + SharedRpcClient, }; /// Coin Read API provides the functionality needed to get information from the /// Iota network regarding the coins owned by an address. #[derive(Debug, Clone)] pub struct CoinReadApi { - api: RpcClient, + api: SharedRpcClient, } impl CoinReadApi { - pub(crate) fn new(api: RpcClient) -> Self { + pub(crate) fn new(api: SharedRpcClient) -> Self { Self { api } } diff --git a/crates/iota-sdk/src/apis/event.rs b/crates/iota-sdk/src/apis/event.rs index 015dab805b7..f829e873757 100644 --- a/crates/iota-sdk/src/apis/event.rs +++ b/crates/iota-sdk/src/apis/event.rs @@ -11,18 +11,18 @@ use jsonrpsee::core::client::Subscription; use crate::{ error::{Error, IotaRpcResult}, - RpcClient, + SharedRpcClient, }; /// Event API provides the functionality to fetch, query, or subscribe to events /// on the Iota network. #[derive(Clone, Debug)] pub struct EventApi { - api: RpcClient, + api: SharedRpcClient, } impl EventApi { - pub(crate) fn new(api: RpcClient) -> Self { + pub(crate) fn new(api: SharedRpcClient) -> Self { Self { api } } diff --git a/crates/iota-sdk/src/apis/governance.rs b/crates/iota-sdk/src/apis/governance.rs index d5b80dcf688..24cfe36694a 100644 --- a/crates/iota-sdk/src/apis/governance.rs +++ b/crates/iota-sdk/src/apis/governance.rs @@ -9,16 +9,16 @@ use iota_types::{ iota_system_state::iota_system_state_summary::IotaSystemStateSummary, }; -use crate::{error::IotaRpcResult, RpcClient}; +use crate::{error::IotaRpcResult, SharedRpcClient}; /// Governance API provides the staking functionality. #[derive(Debug, Clone)] pub struct GovernanceApi { - api: RpcClient, + api: SharedRpcClient, } impl GovernanceApi { - pub(crate) fn new(api: RpcClient) -> Self { + pub(crate) fn new(api: SharedRpcClient) -> Self { Self { api } } diff --git a/crates/iota-sdk/src/apis/quorum_driver.rs b/crates/iota-sdk/src/apis/quorum_driver.rs index 285496a0c80..751fb7cac5d 100644 --- a/crates/iota-sdk/src/apis/quorum_driver.rs +++ b/crates/iota-sdk/src/apis/quorum_driver.rs @@ -10,7 +10,7 @@ use iota_types::{quorum_driver_types::ExecuteTransactionRequestType, transaction use crate::{ error::{Error, IotaRpcResult}, - RpcClient, + SharedRpcClient, }; const WAIT_FOR_LOCAL_EXECUTION_RETRY_COUNT: u8 = 3; @@ -19,11 +19,11 @@ const WAIT_FOR_LOCAL_EXECUTION_RETRY_COUNT: u8 = 3; /// submit it to the fullnode(s). #[derive(Clone, Debug)] pub struct QuorumDriverApi { - api: RpcClient, + api: SharedRpcClient, } impl QuorumDriverApi { - pub(crate) fn new(api: RpcClient) -> Self { + pub(crate) fn new(api: SharedRpcClient) -> Self { Self { api } } diff --git a/crates/iota-sdk/src/apis/read.rs b/crates/iota-sdk/src/apis/read.rs index a07c64fd39d..1a7bd4cfe1e 100644 --- a/crates/iota-sdk/src/apis/read.rs +++ b/crates/iota-sdk/src/apis/read.rs @@ -30,18 +30,18 @@ use jsonrpsee::core::client::Subscription; use crate::{ error::{Error, IotaRpcResult}, - RpcClient, + SharedRpcClient, }; /// The main read API structure with functions for retrieving data about /// different objects and transactions #[derive(Clone, Debug)] pub struct ReadApi { - api: RpcClient, + api: SharedRpcClient, } impl ReadApi { - pub(crate) fn new(api: RpcClient) -> Self { + pub(crate) fn new(api: SharedRpcClient) -> Self { Self { api } } diff --git a/crates/iota-sdk/src/lib.rs b/crates/iota-sdk/src/lib.rs index 0d8cefe5fcc..651ce85fd37 100644 --- a/crates/iota-sdk/src/lib.rs +++ b/crates/iota-sdk/src/lib.rs @@ -228,7 +228,7 @@ impl IotaClientBuilder { builder = builder.enable_ws_ping(PingConfig::new().ping_interval(duration)) } - Some(Arc::new(builder.build(url).await?)) + Some(builder.build(url).await?) } else { None }; @@ -239,9 +239,9 @@ impl IotaClientBuilder { .request_timeout(self.request_timeout) .build(http)?; - let info = Self::get_server_info(&http, ws.as_deref()).await?; + let info = Self::get_server_info(&http, ws.as_ref()).await?; - let api = RpcClient { http, ws, info }; + let api = Arc::new(RpcClient { http, ws, info }); let read_api = ReadApi::new(api.clone()); let quorum_driver_api = QuorumDriverApi::new(api.clone()); let event_api = EventApi::new(api.clone()); @@ -409,7 +409,7 @@ impl IotaClientBuilder { /// ``` #[derive(Clone)] pub struct IotaClient { - api: RpcClient, + api: SharedRpcClient, transaction_builder: TransactionBuilder, read_api: ReadApi, coin_read_api: CoinReadApi, @@ -426,10 +426,12 @@ impl core::fmt::Debug for IotaClient { } } -#[derive(Clone, Debug)] +pub(crate) type SharedRpcClient = Arc; + +#[derive(Debug)] pub(crate) struct RpcClient { http: HttpClient, - ws: Option>, + ws: Option, info: ServerInfo, } @@ -515,7 +517,7 @@ impl IotaClient { /// Returns a reference to the underlying WebSocket client, if any. pub fn ws(&self) -> Option<&WsClient> { - self.api.ws.as_deref() + self.api.ws.as_ref() } } From 2aabe19472d27a893303bbfa487df423c554af77 Mon Sep 17 00:00:00 2001 From: Chloe Martin Date: Fri, 1 Nov 2024 10:54:05 -0400 Subject: [PATCH 4/6] remove commented code --- crates/iota-open-rpc/src/generate_json_rpc_spec.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/iota-open-rpc/src/generate_json_rpc_spec.rs b/crates/iota-open-rpc/src/generate_json_rpc_spec.rs index 61b9385d729..38f5433a9ba 100644 --- a/crates/iota-open-rpc/src/generate_json_rpc_spec.rs +++ b/crates/iota-open-rpc/src/generate_json_rpc_spec.rs @@ -19,9 +19,6 @@ use pretty_assertions::assert_str_eq; use crate::examples::RpcExampleProvider; -// temporarily remove api ref content for indexer methods -// use iota_json_rpc::api::ExtendedApiOpenRpc; - mod examples; #[derive(Debug, Parser, Clone, Copy, ValueEnum)] From 81f89b1ed383c6c7d256016e816e0d4d29b72b90 Mon Sep 17 00:00:00 2001 From: Chloe Martin Date: Mon, 9 Dec 2024 15:02:36 -0500 Subject: [PATCH 5/6] simplify --- crates/iota-sdk/src/apis/coin_read.rs | 8 ++++---- crates/iota-sdk/src/apis/event.rs | 8 +++++--- crates/iota-sdk/src/apis/governance.rs | 8 +++++--- crates/iota-sdk/src/apis/quorum_driver.rs | 11 +++++++---- crates/iota-sdk/src/apis/read.rs | 8 ++++---- crates/iota-sdk/src/lib.rs | 4 +--- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/crates/iota-sdk/src/apis/coin_read.rs b/crates/iota-sdk/src/apis/coin_read.rs index d9512885901..71c1e088693 100644 --- a/crates/iota-sdk/src/apis/coin_read.rs +++ b/crates/iota-sdk/src/apis/coin_read.rs @@ -2,7 +2,7 @@ // Modifications Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use std::future; +use std::{future, sync::Arc}; use futures::{StreamExt, stream}; use futures_core::Stream; @@ -14,7 +14,7 @@ use iota_types::{ }; use crate::{ - SharedRpcClient, + RpcClient, error::{Error, IotaRpcResult}, }; @@ -22,11 +22,11 @@ use crate::{ /// Iota network regarding the coins owned by an address. #[derive(Debug, Clone)] pub struct CoinReadApi { - api: SharedRpcClient, + api: Arc, } impl CoinReadApi { - pub(crate) fn new(api: SharedRpcClient) -> Self { + pub(crate) fn new(api: Arc) -> Self { Self { api } } diff --git a/crates/iota-sdk/src/apis/event.rs b/crates/iota-sdk/src/apis/event.rs index a0b49b2faa0..0ef28d3c791 100644 --- a/crates/iota-sdk/src/apis/event.rs +++ b/crates/iota-sdk/src/apis/event.rs @@ -2,6 +2,8 @@ // Modifications Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +use std::sync::Arc; + use futures::{StreamExt, stream}; use futures_core::Stream; use iota_json_rpc_api::{IndexerApiClient, ReadApiClient}; @@ -10,7 +12,7 @@ use iota_types::{base_types::TransactionDigest, event::EventID}; use jsonrpsee::core::client::Subscription; use crate::{ - SharedRpcClient, + RpcClient, error::{Error, IotaRpcResult}, }; @@ -18,11 +20,11 @@ use crate::{ /// on the Iota network. #[derive(Clone, Debug)] pub struct EventApi { - api: SharedRpcClient, + api: Arc, } impl EventApi { - pub(crate) fn new(api: SharedRpcClient) -> Self { + pub(crate) fn new(api: Arc) -> Self { Self { api } } diff --git a/crates/iota-sdk/src/apis/governance.rs b/crates/iota-sdk/src/apis/governance.rs index 3792ded8c8d..98c3fefca25 100644 --- a/crates/iota-sdk/src/apis/governance.rs +++ b/crates/iota-sdk/src/apis/governance.rs @@ -2,6 +2,8 @@ // Modifications Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 +use std::sync::Arc; + use iota_json_rpc_api::GovernanceReadApiClient; use iota_json_rpc_types::{DelegatedStake, IotaCommittee}; use iota_types::{ @@ -9,16 +11,16 @@ use iota_types::{ iota_system_state::iota_system_state_summary::IotaSystemStateSummary, }; -use crate::{SharedRpcClient, error::IotaRpcResult}; +use crate::{RpcClient, error::IotaRpcResult}; /// Defines methods to get committee and staking info. #[derive(Debug, Clone)] pub struct GovernanceApi { - api: SharedRpcClient, + api: Arc, } impl GovernanceApi { - pub(crate) fn new(api: SharedRpcClient) -> Self { + pub(crate) fn new(api: Arc) -> Self { Self { api } } diff --git a/crates/iota-sdk/src/apis/quorum_driver.rs b/crates/iota-sdk/src/apis/quorum_driver.rs index 83a5126d5a6..c3c2b3f7344 100644 --- a/crates/iota-sdk/src/apis/quorum_driver.rs +++ b/crates/iota-sdk/src/apis/quorum_driver.rs @@ -2,14 +2,17 @@ // Modifications Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use std::time::{Duration, Instant}; +use std::{ + sync::Arc, + time::{Duration, Instant}, +}; use iota_json_rpc_api::{ReadApiClient, WriteApiClient}; use iota_json_rpc_types::{IotaTransactionBlockResponse, IotaTransactionBlockResponseOptions}; use iota_types::{quorum_driver_types::ExecuteTransactionRequestType, transaction::Transaction}; use crate::{ - SharedRpcClient, + RpcClient, error::{Error, IotaRpcResult}, }; @@ -20,11 +23,11 @@ const WAIT_FOR_LOCAL_EXECUTION_INTERVAL: Duration = Duration::from_secs(2); /// Defines methods to execute transaction blocks and submit them to fullnodes. #[derive(Clone, Debug)] pub struct QuorumDriverApi { - api: SharedRpcClient, + api: Arc, } impl QuorumDriverApi { - pub(crate) fn new(api: SharedRpcClient) -> Self { + pub(crate) fn new(api: Arc) -> Self { Self { api } } diff --git a/crates/iota-sdk/src/apis/read.rs b/crates/iota-sdk/src/apis/read.rs index a2a3ece6a4c..8521e958aec 100644 --- a/crates/iota-sdk/src/apis/read.rs +++ b/crates/iota-sdk/src/apis/read.rs @@ -2,7 +2,7 @@ // Modifications Copyright (c) 2024 IOTA Stiftung // SPDX-License-Identifier: Apache-2.0 -use std::collections::BTreeMap; +use std::{collections::BTreeMap, sync::Arc}; use fastcrypto::encoding::Base64; use futures::{StreamExt, stream}; @@ -28,18 +28,18 @@ use iota_types::{ use jsonrpsee::core::client::Subscription; use crate::{ - SharedRpcClient, + RpcClient, error::{Error, IotaRpcResult}, }; /// Defines methods for retrieving data about objects and transactions. #[derive(Clone, Debug)] pub struct ReadApi { - api: SharedRpcClient, + api: Arc, } impl ReadApi { - pub(crate) fn new(api: SharedRpcClient) -> Self { + pub(crate) fn new(api: Arc) -> Self { Self { api } } diff --git a/crates/iota-sdk/src/lib.rs b/crates/iota-sdk/src/lib.rs index 2bcf74821e5..dfa47fcedaa 100644 --- a/crates/iota-sdk/src/lib.rs +++ b/crates/iota-sdk/src/lib.rs @@ -431,7 +431,7 @@ impl IotaClientBuilder { /// ``` #[derive(Clone)] pub struct IotaClient { - api: SharedRpcClient, + api: Arc, transaction_builder: TransactionBuilder, read_api: ReadApi, coin_read_api: CoinReadApi, @@ -448,8 +448,6 @@ impl core::fmt::Debug for IotaClient { } } -pub(crate) type SharedRpcClient = Arc; - #[derive(Debug)] pub(crate) struct RpcClient { http: HttpClient, From 35483592b85420046153d2d2061d6af4c10cdcf3 Mon Sep 17 00:00:00 2001 From: Chloe Martin Date: Thu, 19 Dec 2024 10:06:43 -0500 Subject: [PATCH 6/6] clippy --- crates/iota-indexer/src/apis/transaction_builder_api.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/iota-indexer/src/apis/transaction_builder_api.rs b/crates/iota-indexer/src/apis/transaction_builder_api.rs index 73a4c853831..384003620b1 100644 --- a/crates/iota-indexer/src/apis/transaction_builder_api.rs +++ b/crates/iota-indexer/src/apis/transaction_builder_api.rs @@ -37,7 +37,6 @@ impl core::fmt::Debug for TransactionBuilderApi { } impl TransactionBuilderApi { - #[expect(clippy::new_ret_no_self)] pub fn new(inner: IndexerReader) -> IotaTransactionBuilderApi> { IotaTransactionBuilderApi::new_with_data_reader(Self { inner }) }