pub struct Client { /* private fields */ }Expand description
A gRPC client for the Sui fullnode RPC interface.
All RPCs made through a client and its clones are multiplexed over a single HTTP/2 connection.
§Timeouts and deadlines
No default bounds the total duration of a call. Two opt-in bounds are available:
- A per-call deadline set with [
tonic::Request::set_timeout]. This attaches the standardgrpc-timeoutheader, so a server that supports it enforces the deadline too, and the client enforces it locally end to end: tonic bounds the wait for response headers, and the client’s watchdog (seewith_body_idle_timeout) bounds the response body against the same deadline. - A client-wide response-headers timeout set with
with_response_headers_timeout. This is enforced locally only and its timer stops once response headers arrive, so it bounds every unary call (whose headers are not sent until the handler completes) without cutting off long-lived streams.
Independent of any deadline, the watchdog resets RPCs whose response body
makes no progress for 30 seconds (configurable), so a call on a stalled
connection fails with DeadlineExceeded instead of hanging forever.
Implementations§
Source§impl Client
impl Client
pub async fn get_delegated_stake( &mut self, staked_sui_id: &Address, ) -> Result<DelegatedStake, Status>
pub async fn list_delegated_stake( &mut self, address: &Address, ) -> Result<Vec<DelegatedStake>, Status>
pub async fn calculate_rewards( &mut self, staked_sui_ids: &[Address], ) -> Result<Vec<(Address, u64)>, Status>
pub async fn get_validator_address_by_pool_id( &mut self, pool_ids: &[Address], ) -> Result<Vec<(Address, Address)>, Status>
Source§impl Client
impl Client
Sourcepub async fn select_coins(
&self,
owner_address: &Address,
coin_type: &TypeTag,
amount: u64,
exclude: &[Address],
) -> Result<Vec<Object>, Status>
pub async fn select_coins( &self, owner_address: &Address, coin_type: &TypeTag, amount: u64, exclude: &[Address], ) -> Result<Vec<Object>, Status>
Selects coins of a specific type owned by an address until the total value meets the required amount.
§Arguments
owner_address- The address that owns the coinscoin_type- The TypeTag of coins to selectamount- The minimum total amount neededexclude- Array of addresses to exclude from selection
§Returns
A vector of Object instances representing the selected coins
§Errors
Returns an error if there are insufficient funds to meet the required amount or if there is an RPC error
Sourcepub async fn select_up_to_n_largest_coins(
&self,
owner_address: &Address,
coin_type: &TypeTag,
n: usize,
exclude: &[Address],
) -> Result<Vec<Object>, Status>
pub async fn select_up_to_n_largest_coins( &self, owner_address: &Address, coin_type: &TypeTag, n: usize, exclude: &[Address], ) -> Result<Vec<Object>, Status>
Selects up to N coins of a specific type owned by an address.
§Arguments
owner_address- The address that owns the coinscoin_type- The TypeTag of coins to selectn- The maximum number of coins to selectexclude- Array of addresses to exclude from selection
§Returns
A vector of Object instances representing the selected coins (may be fewer than n if not enough coins are available)
§Errors
Returns an error if there is an RPC error during coin retrieval
Source§impl Client
impl Client
Sourcepub fn list_owned_objects(
&self,
request: impl IntoRequest<ListOwnedObjectsRequest>,
) -> impl Stream<Item = Result<Object, Status>> + 'static
pub fn list_owned_objects( &self, request: impl IntoRequest<ListOwnedObjectsRequest>, ) -> impl Stream<Item = Result<Object, Status>> + 'static
Creates a stream of objects based on the provided request.
The stream handles pagination automatically by using the page_token from responses to fetch subsequent pages. The original request’s page_token is used as the starting point.
§Arguments
request- The initialListOwnedObjectsRequestwith search criteria
§Returns
A stream that yields Result<Object> instances. If any RPC call fails, the
tonic::Status from that request is returned.
Sourcepub fn list_dynamic_fields(
&self,
request: impl IntoRequest<ListDynamicFieldsRequest>,
) -> impl Stream<Item = Result<DynamicField, Status>> + 'static
pub fn list_dynamic_fields( &self, request: impl IntoRequest<ListDynamicFieldsRequest>, ) -> impl Stream<Item = Result<DynamicField, Status>> + 'static
Creates a stream of DynamicFields based on the provided request.
The stream handles pagination automatically by using the page_token from responses to fetch subsequent pages. The original request’s page_token is used as the starting point.
§Arguments
request- The initialListDynamicFieldsRequestwith search criteria
§Returns
A stream that yields Result<DynamicField> instances. If any RPC call fails, the
tonic::Status from that request is returned.
Sourcepub fn list_balances(
&self,
request: impl IntoRequest<ListBalancesRequest>,
) -> impl Stream<Item = Result<Balance, Status>> + 'static
pub fn list_balances( &self, request: impl IntoRequest<ListBalancesRequest>, ) -> impl Stream<Item = Result<Balance, Status>> + 'static
Creates a stream of Balances based on the provided request.
The stream handles pagination automatically by using the page_token from responses to fetch subsequent pages. The original request’s page_token is used as the starting point.
§Arguments
request- The initialListBalancesRequestwith search criteria
§Returns
A stream that yields Result<Balance> instances. If any RPC call fails, the
tonic::Status from that request is returned.
Sourcepub fn list_package_versions(
&self,
request: impl IntoRequest<ListPackageVersionsRequest>,
) -> impl Stream<Item = Result<PackageVersion, Status>> + 'static
pub fn list_package_versions( &self, request: impl IntoRequest<ListPackageVersionsRequest>, ) -> impl Stream<Item = Result<PackageVersion, Status>> + 'static
Creates a stream of PackageVersions based on the provided request.
The stream handles pagination automatically by using the page_token from responses to fetch subsequent pages. The original request’s page_token is used as the starting point.
§Arguments
request- The initialListPackageVersionsRequestwith search criteria
§Returns
A stream that yields Result<PackageVersion> instances. If any RPC call fails, the
tonic::Status from that request is returned.
Source§impl Client
impl Client
Sourcepub async fn execute_transaction_and_wait_for_checkpoint(
&mut self,
request: impl IntoRequest<ExecuteTransactionRequest>,
timeout: Duration,
) -> Result<Response<ExecuteTransactionResponse>, ExecuteAndWaitError>
pub async fn execute_transaction_and_wait_for_checkpoint( &mut self, request: impl IntoRequest<ExecuteTransactionRequest>, timeout: Duration, ) -> Result<Response<ExecuteTransactionResponse>, ExecuteAndWaitError>
Executes a transaction and waits for it to be included in a checkpoint.
This method provides “read your writes” consistency by executing the transaction and waiting for it to appear in a checkpoint, which gauruntees indexes have been updated on this node.
§Arguments
request- The transaction execution request (ExecuteTransactionRequest)timeout- Maximum time to wait for indexing confirmation
§Returns
A Result containing the response if the transaction was executed and checkpoint confirmed,
or an error that may still include the response if execution succeeded but checkpoint
confirmation failed.
§Duplicate submissions
Submitting a transaction that has already been executed is handled
gracefully. While the execution RPC is in flight the ledger is probed
for the transaction, and a transaction that is already in a checkpoint
is returned without waiting for execution to finish. Likewise, if
execution fails but the ledger shows the transaction in a checkpoint
(for example when a resubmission races the original submission), the
execution error is discarded and the committed transaction is
returned. In both cases the response is assembled from
GetTransaction using the request’s read mask, so it carries the same
fields an execution response would, with digest, checkpoint, and
timestamp always populated.
Source§impl Client
impl Client
Sourcepub const MAINNET_FULLNODE: &str = "https://fullnode.mainnet.sui.io"
pub const MAINNET_FULLNODE: &str = "https://fullnode.mainnet.sui.io"
URL for the public-good, Sui Foundation provided fullnodes for mainnet.
Sourcepub const TESTNET_FULLNODE: &str = "https://fullnode.testnet.sui.io"
pub const TESTNET_FULLNODE: &str = "https://fullnode.testnet.sui.io"
URL for the public-good, Sui Foundation provided fullnodes for testnet.
Sourcepub const DEVNET_FULLNODE: &str = "https://fullnode.devnet.sui.io"
pub const DEVNET_FULLNODE: &str = "https://fullnode.devnet.sui.io"
URL for the public-good, Sui Foundation provided fullnodes for devnet.
Sourcepub const MAINNET_ARCHIVE: &str = "https://archive.mainnet.sui.io"
pub const MAINNET_ARCHIVE: &str = "https://archive.mainnet.sui.io"
URL for the public-good, Sui Foundation provided archive for mainnet.
Sourcepub const TESTNET_ARCHIVE: &str = "https://archive.testnet.sui.io"
pub const TESTNET_ARCHIVE: &str = "https://archive.testnet.sui.io"
URL for the public-good, Sui Foundation provided archive for testnet.
Sourcepub fn from_endpoint(endpoint: &Endpoint) -> Self
pub fn from_endpoint(endpoint: &Endpoint) -> Self
Build a client from a fully custom [tonic::transport::Endpoint].
This bypasses every transport default that Client::new applies,
including the HTTP/2 flow-control windows that protect the shared
connection from starvation by stalled streaming responses. Prefer
Client::new plus the with_* configuration methods unless an
endpoint setting is needed that the client does not expose. The
idle-body watchdog (see Client::with_body_idle_timeout) is part of
the client rather than the endpoint and stays enabled.
In particular, do not rely on
http2_adaptive_window
as a substitute for large static windows: with adaptive windowing,
hyper starts the connection window at the 64 KiB HTTP/2 spec default
until bandwidth-delay probing ramps up, so a single stalled stream can
starve the whole connection.
pub fn new<T>(uri: T) -> Result<Self, Status>
Sourcepub fn with_body_idle_timeout(self, timeout: Duration) -> Self
pub fn with_body_idle_timeout(self, timeout: Duration) -> Self
Set the idle timeout for the client’s response-body watchdog. Defaults to 30 seconds.
The watchdog bounds the time between response-body progress events: if
a whole idle period passes without a frame of the response being
delivered to the caller – because the connection is starved or dead,
or because the caller has parked a streaming response without polling
it – the watchdog resets the stream, releasing the HTTP/2
flow-control window it had pinned, and the call observes a
DeadlineExceeded status on its next
poll. This is what turns “an RPC on a starved connection hangs
forever” into a bounded failure, and what keeps an abandoned stream
from starving the shared connection in the first place.
Streams that are legitimately quiet for longer than the timeout (the
fullnode’s checkpoint subscription is not: it emits watermarks every
few seconds) should raise or disable the watchdog for that call with a
BodyIdleTimeout request extension.
Sourcepub fn without_body_idle_timeout(self) -> Self
pub fn without_body_idle_timeout(self) -> Self
Disable the client’s response-body watchdog (see
with_body_idle_timeout).
Without it, an RPC whose response can no longer make progress hangs
indefinitely; only disable the watchdog when every call is bounded by
the caller. It can be re-enabled for individual requests with a
BodyIdleTimeout request extension.
Sourcepub fn with_response_headers_timeout(self, timeout: Duration) -> Self
pub fn with_response_headers_timeout(self, timeout: Duration) -> Self
Set a timeout for the response-headers phase of every RPC made through this client. Disabled by default.
The timer covers a request from dispatch on the connection until
response headers arrive and is dropped once they do, so a client-wide
value does not cut off long-lived streaming responses. Because a
server does not send response headers for a unary call until the
handler completes, this effectively bounds the total duration of
unary calls; the body that follows is bounded by the idle-body
watchdog (see with_body_idle_timeout)
and, when set, the per-call deadline. Connection establishment is
bounded separately by the connect timeout.
This timeout is enforced locally only; it is not communicated to the
server. When a per-call deadline ([tonic::Request::set_timeout]) is
also set, the shorter of the two bounds the headers phase locally, so
a per-call deadline can tighten this bound but never extend it –
size the timeout for the slowest expected RPC. Expiry surfaces as
DeadlineExceeded.
This rebuilds the underlying channel, so it must be called before the client is used or cloned; earlier clones keep the previous configuration.
Sourcepub fn with_initial_stream_window_size(self, size: u32) -> Self
pub fn with_initial_stream_window_size(self, size: u32) -> Self
Set the HTTP/2 per-stream receive window, in bytes.
This bounds how much unread response data a single RPC can buffer
before the server must stop sending on that stream. It also bounds how
much of the shared connection window (see
with_initial_connection_window_size)
one stalled stream can pin. Defaults to 2 MiB.
This rebuilds the underlying channel, so it must be called before the client is used or cloned; earlier clones keep the previous configuration.
Sourcepub fn with_initial_connection_window_size(self, size: u32) -> Self
pub fn with_initial_connection_window_size(self, size: u32) -> Self
Set the HTTP/2 connection-level receive window, in bytes.
This window is shared by every RPC multiplexed over the client’s single HTTP/2 connection, including all clones of the client. Response data that the application has not yet read counts against it, so it determines how many concurrently stalled streaming responses it takes to starve the connection and hang every other RPC on it. Defaults to 64 MiB (~32 stalled streams at the default 2 MiB stream window).
This rebuilds the underlying channel, so it must be called before the client is used or cloned; earlier clones keep the previous configuration.
pub fn with_headers(self, headers: HeadersInterceptor) -> Self
Sourcepub fn request_layer<L, ResBody, E>(self, layer: L) -> Selfwhere
L: Layer<BoxService<Request<Body>, Response<Body>, Box<dyn Error + Send + Sync + 'static>>> + Send + Sync + 'static,
L::Service: Service<Request<Body>, Response = Response<ResBody>, Error = E> + Send + 'static,
<L::Service as Service<Request<Body>>>::Future: Send + 'static,
ResBody: Body<Data = Bytes> + Send + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync + 'static>>,
E: Into<Box<dyn Error + Send + Sync + 'static>> + Send + 'static,
pub fn request_layer<L, ResBody, E>(self, layer: L) -> Selfwhere
L: Layer<BoxService<Request<Body>, Response<Body>, Box<dyn Error + Send + Sync + 'static>>> + Send + Sync + 'static,
L::Service: Service<Request<Body>, Response = Response<ResBody>, Error = E> + Send + 'static,
<L::Service as Service<Request<Body>>>::Future: Send + 'static,
ResBody: Body<Data = Bytes> + Send + 'static,
ResBody::Error: Into<Box<dyn Error + Send + Sync + 'static>>,
E: Into<Box<dyn Error + Send + Sync + 'static>> + Send + 'static,
Provide an optional [Layer] that will be used to wrap all RPC
requests.
This could be helpful in providing global metrics and logging for all outbound requests.
The layer’s service may return any response body that implements
[http_body::Body<Data = bytes::Bytes>] and any error type that
implements Into<Box<dyn Error + Send + Sync>>. Both are mapped
to the internal types automatically.
§Example
Add a layer that logs each request URI:
use sui_rpc::Client;
use tower::ServiceBuilder;
let client = Client::new(Client::MAINNET_FULLNODE)
.unwrap()
.request_layer(ServiceBuilder::new().map_request(|req: http::Request<_>| {
println!("request to {}", req.uri());
req
}));pub fn with_max_decoding_message_size(self, limit: usize) -> Self
pub fn uri(&self) -> &Uri
pub fn ledger_client( &mut self, ) -> LedgerServiceClient<BoxService<Request<Body>, Response<Body>, Status>>
pub fn state_client( &mut self, ) -> StateServiceClient<BoxService<Request<Body>, Response<Body>, Status>>
pub fn execution_client( &mut self, ) -> TransactionExecutionServiceClient<BoxService<Request<Body>, Response<Body>, Status>>
pub fn package_client( &mut self, ) -> MovePackageServiceClient<BoxService<Request<Body>, Response<Body>, Status>>
pub fn signature_verification_client( &mut self, ) -> SignatureVerificationServiceClient<BoxService<Request<Body>, Response<Body>, Status>>
pub fn subscription_client( &mut self, ) -> SubscriptionServiceClient<BoxService<Request<Body>, Response<Body>, Status>>
Sourcepub fn proof_client(
&mut self,
) -> ProofServiceClient<BoxService<Request<Body>, Response<Body>, Status>>
Available on crate feature unstable only.
pub fn proof_client( &mut self, ) -> ProofServiceClient<BoxService<Request<Body>, Response<Body>, Status>>
unstable only.Returns a client for the unstable alpha ProofService, which serves
Object Checkpoint State (OCS) inclusion proofs.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read moreSource§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.