Struct iota_sdk::client::core::Client

source ·
pub struct Client { /* private fields */ }
Available on crate feature client only.
Expand description

An IOTA node client.

Implementations§

source§

impl Client

source

pub async fn consolidate_funds( &self, secret_manager: &SecretManager, options: GetAddressesOptions ) -> Result<Bech32Address>

Function to consolidate all funds and native tokens from a range of addresses to the address with the lowest index in that range. Returns the address to which the funds got consolidated, if any were available

source§

impl Client

source

pub async fn inputs_from_transaction_id( &self, transaction_id: &TransactionId ) -> Result<Vec<OutputWithMetadata>>

Get the inputs of a transaction for the given transaction id.

source

pub fn build_block(&self) -> ClientBlockBuilder<'_>

Get a builder that can be used to construct a block in parts.

source

pub async fn find_blocks(&self, block_ids: &[BlockId]) -> Result<Vec<Block>>

Find all blocks by provided block IDs.

source

pub async fn retry(&self, block_id: &BlockId) -> Result<(BlockId, Block)>

Retries (promotes or reattaches) a block for provided block id. Block should only be retried only if they are valid and haven’t been confirmed for a while.

source

pub async fn retry_until_included( &self, block_id: &BlockId, interval: Option<u64>, max_attempts: Option<u64> ) -> Result<Vec<(BlockId, Block)>>

Retries (promotes or reattaches) a block for provided block id until it’s included (referenced by a milestone). Default interval is 5 seconds and max attempts is 40. Returns the included block at first position and additional reattached blocks

source

pub async fn find_inputs( &self, addresses: Vec<Bech32Address>, amount: u64 ) -> Result<Vec<UtxoInput>>

Function to find inputs from addresses for a provided amount (useful for offline signing), ignoring outputs with additional unlock conditions

source

pub async fn reattach(&self, block_id: &BlockId) -> Result<(BlockId, Block)>

Reattaches blocks for provided block id. Blocks can be reattached only if they are valid and haven’t been confirmed for a while.

source

pub async fn reattach_unchecked( &self, block_id: &BlockId ) -> Result<(BlockId, Block)>

Reattach a block without checking if it should be reattached

source

pub async fn promote(&self, block_id: &BlockId) -> Result<(BlockId, Block)>

Promotes a block. The method should validate if a promotion is necessary through get_block. If not, the method should error out and should not allow unnecessary promotions.

source

pub async fn promote_unchecked( &self, block_id: &BlockId ) -> Result<(BlockId, Block)>

Promote a block without checking if it should be promoted

source

pub async fn get_time_checked(&self) -> Result<u32>

Returns the local time checked with the timestamp of the latest milestone, if the difference is larger than 5 minutes an error is returned to prevent locking outputs by accident for a wrong time.

source§

impl Client

source

pub fn builder() -> ClientBuilder

Create the builder to instantiate the IOTA Client.

source§

impl Client

source

pub async fn get_node_info( url: &str, auth: Option<NodeAuth> ) -> Result<InfoResponse>

GET /api/core/v2/info endpoint

source§

impl Client

source

pub async fn get_outputs( &self, output_ids: &[OutputId] ) -> Result<Vec<OutputWithMetadata>>

Request outputs by their output ID in parallel

source

pub async fn get_outputs_ignore_errors( &self, output_ids: &[OutputId] ) -> Result<Vec<OutputWithMetadata>>

Request outputs by their output ID in parallel, ignoring failed requests Useful to get data about spent outputs, that might not be pruned yet

source

pub async fn get_outputs_metadata_ignore_errors( &self, output_ids: &[OutputId] ) -> Result<Vec<OutputMetadata>>

Requests metadata for outputs by their output ID in parallel, ignoring failed requests

source§

impl Client

source

pub fn subscriber(&self) -> MqttManager<'_>

Available on crate feature mqtt only.

Returns a handle to the MQTT topics manager.

source

pub async fn subscribe<C: Fn(&TopicEvent) + Send + Sync + 'static>( &self, topics: impl IntoIterator<Item = Topic> + Send, callback: C ) -> Result<(), Error>

Available on crate feature mqtt only.

Subscribe to MQTT events with a callback.

source

pub async fn unsubscribe( &self, topics: impl IntoIterator<Item = Topic> + Send ) -> Result<(), Error>

Available on crate feature mqtt only.

Unsubscribe from MQTT events.

source§

impl Client

source

pub async fn update_node_manager(&self, node_manager: NodeManager) -> Result<()>

source§

impl Client

source

pub fn bech32_to_hex(bech32: impl ConvertTo<Bech32Address>) -> Result<String>

Transforms bech32 to hex

source

pub fn generate_mnemonic() -> Result<Mnemonic>

Generates a new mnemonic.

source

pub fn mnemonic_to_seed(mnemonic: impl Borrow<MnemonicRef>) -> Result<Seed>

Returns a seed for a mnemonic.

source

pub fn mnemonic_to_hex_seed( mnemonic: impl Borrow<MnemonicRef> ) -> Result<String>

Returns a hex encoded seed for a mnemonic.

source

pub fn tag_to_utf8(payload: &TaggedDataPayload) -> Result<String>

UTF-8 encodes the tag of a given TaggedDataPayload.

source

pub fn data_to_utf8(payload: &TaggedDataPayload) -> Result<String>

UTF-8 encodes the data of a given TaggedDataPayload.

source

pub fn tagged_data_to_utf8( payload: &TaggedDataPayload ) -> Result<(String, String)>

UTF-8 encodes both the tag and data of a given TaggedDataPayload.

Methods from Deref<Target = ClientInner>§

source

pub async fn finish_block_builder( &self, parents: Option<Parents>, payload: Option<Payload> ) -> Result<Block>

Finishes the block with local PoW if needed. Without local PoW, it will finish the block with a 0 nonce.

source

pub async fn finish_pow( &self, parents: Option<Parents>, payload: Option<Payload> ) -> Result<Block>

Calls the appropriate PoW function depending whether the compilation is for wasm or not.

source

pub async fn get_network_info(&self) -> Result<NetworkInfo>

Gets the network related information such as network_id and min_pow_score and if it’s the default one, sync it first and set the NetworkInfo.

source

pub async fn get_protocol_parameters(&self) -> Result<ProtocolParameters>

Gets the protocol parameters of the node we’re connecting to.

source

pub async fn get_protocol_version(&self) -> Result<u8>

Gets the protocol version of the node we’re connecting to.

source

pub async fn get_network_name(&self) -> Result<String>

Gets the network name of the node we’re connecting to.

source

pub async fn get_network_id(&self) -> Result<u64>

Gets the network id of the node we’re connecting to.

source

pub async fn get_bech32_hrp(&self) -> Result<Hrp>

Gets the bech32 HRP of the node we’re connecting to.

source

pub async fn get_min_pow_score(&self) -> Result<u32>

Gets the minimum pow score of the node we’re connecting to.

source

pub async fn get_below_max_depth(&self) -> Result<u8>

Gets the below maximum depth of the node we’re connecting to.

source

pub async fn get_rent_structure(&self) -> Result<RentStructure>

Gets the rent structure of the node we’re connecting to.

source

pub async fn get_token_supply(&self) -> Result<u64>

Gets the token supply of the node we’re connecting to.

source

pub async fn get_tips_interval(&self) -> u64

returns the tips interval

source

pub async fn get_local_pow(&self) -> bool

returns if local pow should be used or not

source

pub async fn get_fallback_to_local_pow(&self) -> bool

returns the fallback_to_local_pow

source

pub async fn bech32_hrp_matches(&self, bech32_hrp: &Hrp) -> Result<()>

Validates if a bech32 HRP matches the one from the connected network.

source

pub async fn resize_request_pool(&self, new_size: usize)

Resize the client’s request pool

source

pub async fn get_health(&self, url: &str) -> Result<bool>

Returns the health of the node. GET /health

source

pub async fn get_routes(&self) -> Result<RoutesResponse>

Returns the available API route groups of the node. GET /api/routes

source

pub async fn get_info(&self) -> Result<NodeInfoWrapper>

Returns general information about the node. GET /api/core/v2/info

source

pub async fn get_tips(&self) -> Result<Vec<BlockId>>

Returns tips that are ideal for attaching a block. GET /api/core/v2/tips

source

pub async fn post_block(&self, block: &Block) -> Result<BlockId>

Returns the BlockId of the submitted block. POST JSON to /api/core/v2/blocks

source

pub async fn post_block_raw(&self, block: &Block) -> Result<BlockId>

Returns the BlockId of the submitted block. POST /api/core/v2/blocks

source

pub async fn get_block(&self, block_id: &BlockId) -> Result<Block>

Finds a block by its BlockId. This method returns the given block object. GET /api/core/v2/blocks/{BlockId}

source

pub async fn get_block_raw(&self, block_id: &BlockId) -> Result<Vec<u8>>

Finds a block by its BlockId. This method returns the given block raw data. GET /api/core/v2/blocks/{BlockId}

source

pub async fn get_block_metadata( &self, block_id: &BlockId ) -> Result<BlockMetadataResponse>

Returns the metadata of a block. GET /api/core/v2/blocks/{BlockId}/metadata

source

pub async fn get_output( &self, output_id: &OutputId ) -> Result<OutputWithMetadata>

Finds an output, as JSON, by its OutputId (TransactionId + output_index). GET /api/core/v2/outputs/{outputId}

source

pub async fn get_output_raw(&self, output_id: &OutputId) -> Result<Vec<u8>>

Finds an output, as raw bytes, by its OutputId (TransactionId + output_index). GET /api/core/v2/outputs/{outputId}

source

pub async fn get_output_metadata( &self, output_id: &OutputId ) -> Result<OutputMetadata>

Get the metadata for a given OutputId (TransactionId + output_index). GET /api/core/v2/outputs/{outputId}/metadata

source

pub async fn get_receipts(&self) -> Result<Vec<ReceiptResponse>>

Gets all stored receipts. GET /api/core/v2/receipts

source

pub async fn get_receipts_migrated_at( &self, milestone_index: u32 ) -> Result<Vec<ReceiptResponse>>

Gets the receipts by the given milestone index. GET /api/core/v2/receipts/{migratedAt}

source

pub async fn get_treasury(&self) -> Result<TreasuryResponse>

Gets the current treasury output. The treasury output contains all tokens from the legacy network that have not yet been migrated. GET /api/core/v2/treasury

source

pub async fn get_included_block( &self, transaction_id: &TransactionId ) -> Result<Block>

Returns the block, as object, that was included in the ledger for a given TransactionId. GET /api/core/v2/transactions/{transactionId}/included-block

source

pub async fn get_included_block_raw( &self, transaction_id: &TransactionId ) -> Result<Vec<u8>>

Returns the block, as raw bytes, that was included in the ledger for a given TransactionId. GET /api/core/v2/transactions/{transactionId}/included-block

source

pub async fn get_included_block_metadata( &self, transaction_id: &TransactionId ) -> Result<BlockMetadataResponse>

Returns the metadata of the block that was included in the ledger for a given TransactionId. GET /api/core/v2/transactions/{transactionId}/included-block/metadata

source

pub async fn get_milestone_by_id( &self, milestone_id: &MilestoneId ) -> Result<MilestonePayload>

Gets the milestone by the given milestone id. GET /api/core/v2/milestones/{milestoneId}

source

pub async fn get_milestone_by_id_raw( &self, milestone_id: &MilestoneId ) -> Result<Vec<u8>>

Gets the milestone by the given milestone id. GET /api/core/v2/milestones/{milestoneId}

source

pub async fn get_utxo_changes_by_id( &self, milestone_id: &MilestoneId ) -> Result<UtxoChangesResponse>

Gets all UTXO changes of a milestone by its milestone id. GET /api/core/v2/milestones/{milestoneId}/utxo-changes

source

pub async fn get_milestone_by_index( &self, index: u32 ) -> Result<MilestonePayload>

Gets the milestone by the given milestone index. GET /api/core/v2/milestones/{index}

source

pub async fn get_milestone_by_index_raw(&self, index: u32) -> Result<Vec<u8>>

Gets the milestone by the given milestone index. GET /api/core/v2/milestones/{index}

source

pub async fn get_utxo_changes_by_index( &self, index: u32 ) -> Result<UtxoChangesResponse>

Gets all UTXO changes of a milestone by its milestone index. GET /api/core/v2/milestones/by-index/{index}/utxo-changes

source

pub async fn get_peers(&self) -> Result<Vec<PeerResponse>>

GET /api/core/v2/peers

source

pub async fn output_ids( &self, query_parameters: impl Into<Vec<QueryParameter>> + Send ) -> Result<OutputIdsResponse>

Get basic, alias, nft and foundry outputs filtered by the given parameters. GET with query parameter returns all outputIDs that fit these filter criteria. Query parameters: “hasNativeTokens”, “minNativeTokenCount”, “maxNativeTokenCount”, “unlockableByAddress”, “createdBefore”, “createdAfter”, “cursor”, “pageSize”. Returns Err(Node(NotFound) if no results are found. api/indexer/v1/outputs

source

pub async fn basic_output_ids( &self, query_parameters: impl Into<Vec<QueryParameter>> + Send ) -> Result<OutputIdsResponse>

Get basic outputs filtered by the given parameters. GET with query parameter returns all outputIDs that fit these filter criteria. Query parameters: “address”, “hasStorageDepositReturn”, “storageDepositReturnAddress”, “hasExpiration”, “expiresBefore”, “expiresAfter”, “hasTimelock”, “timelockedBefore”, “timelockedAfter”, “sender”, “tag”, “createdBefore” and “createdAfter”. Returns Err(Node(NotFound) if no results are found. api/indexer/v1/outputs/basic

source

pub async fn alias_output_ids( &self, query_parameters: impl Into<Vec<QueryParameter>> + Send ) -> Result<OutputIdsResponse>

Get alias outputs filtered by the given parameters. GET with query parameter returns all outputIDs that fit these filter criteria. Query parameters: “stateController”, “governor”, “issuer”, “sender”, “createdBefore”, “createdAfter” Returns Err(Node(NotFound) if no results are found. api/indexer/v1/outputs/alias

source

pub async fn alias_output_id(&self, alias_id: AliasId) -> Result<OutputId>

Get alias output by its aliasID. api/indexer/v1/outputs/alias/:{AliasId}

source

pub async fn foundry_output_ids( &self, query_parameters: impl Into<Vec<QueryParameter>> + Send ) -> Result<OutputIdsResponse>

Get foundry outputs filtered by the given parameters. GET with query parameter returns all outputIDs that fit these filter criteria. Query parameters: “address”, “createdBefore”, “createdAfter” Returns Err(Node(NotFound) if no results are found. api/indexer/v1/outputs/foundry

source

pub async fn foundry_output_id(&self, foundry_id: FoundryId) -> Result<OutputId>

Get foundry output by its foundryID. api/indexer/v1/outputs/foundry/:{FoundryID}

source

pub async fn nft_output_ids( &self, query_parameters: impl Into<Vec<QueryParameter>> + Send ) -> Result<OutputIdsResponse>

Get NFT outputs filtered by the given parameters. Query parameters: “address”, “hasStorageDepositReturn”, “storageDepositReturnAddress”, “hasExpiration”, “expiresBefore”, “expiresAfter”, “hasTimelock”, “timelockedBefore”, “timelockedAfter”, “issuer”, “sender”, “tag”, “createdBefore”, “createdAfter” Returns Err(Node(NotFound) if no results are found. api/indexer/v1/outputs/nft

source

pub async fn nft_output_id(&self, nft_id: NftId) -> Result<OutputId>

Get NFT output by its nftID. api/indexer/v1/outputs/nft/:{NftId}

source

pub async fn get_output_ids( &self, route: &str, query_parameters: QueryParameters, need_quorum: bool, prefer_permanode: bool ) -> Result<OutputIdsResponse>

Get all output ids for a provided URL route and query parameters. If a QueryParameter::Cursor(_) is provided, only a single page will be queried.

source

pub async fn mqtt_event_receiver(&self) -> WatchReceiver<MqttEvent>

Available on crate feature mqtt only.

Returns the mqtt event receiver.

source

pub async fn events( &self, event_type: Option<ParticipationEventType> ) -> Result<EventsResponse>

Available on crate feature participation only.

RouteParticipationEvents is the route to list all events, returning their ID, the event name and status.

source

pub async fn event( &self, event_id: &ParticipationEventId ) -> Result<ParticipationEventData>

Available on crate feature participation only.

RouteParticipationEvent is the route to access a single participation by its ID.

source

pub async fn event_status( &self, event_id: &ParticipationEventId, milestone_index: Option<u32> ) -> Result<ParticipationEventStatus>

Available on crate feature participation only.

RouteParticipationEventStatus is the route to access the status of a single participation by its ID.

source

pub async fn output_status( &self, output_id: &OutputId ) -> Result<OutputStatusResponse>

Available on crate feature participation only.

RouteOutputStatus is the route to get the vote status for a given output ID.

source

pub async fn address_staking_status( &self, bech32_address: impl ConvertTo<Bech32Address> ) -> Result<AddressStakingStatus>

Available on crate feature participation only.

RouteAddressBech32Status is the route to get the staking rewards for the given bech32 address.

source

pub async fn address_participation_output_ids( &self, bech32_address: impl ConvertTo<Bech32Address> ) -> Result<AddressOutputsResponse>

Available on crate feature participation only.

RouteAddressBech32Outputs is the route to get the outputs for the given bech32 address.

source

pub async fn call_plugin_route<T>( &self, base_plugin_path: &str, method: &str, endpoint: &str, query_params: Vec<String>, request_object: Option<String> ) -> Result<T>

Extension method which provides request methods for plugins.

source

pub async fn get_node(&self) -> Result<Node>

Get a node candidate from the healthy node pool.

source

pub async fn unhealthy_nodes(&self) -> HashSet<Node>

returns the unhealthy nodes.

source

pub async fn hex_to_bech32( &self, hex: &str, bech32_hrp: Option<impl ConvertTo<Hrp>> ) -> Result<Bech32Address>

Transforms a hex encoded address to a bech32 encoded address

source

pub async fn alias_id_to_bech32( &self, alias_id: AliasId, bech32_hrp: Option<impl ConvertTo<Hrp>> ) -> Result<Bech32Address>

Transforms an alias id to a bech32 encoded address

source

pub async fn nft_id_to_bech32( &self, nft_id: NftId, bech32_hrp: Option<impl ConvertTo<Hrp>> ) -> Result<Bech32Address>

Transforms an nft id to a bech32 encoded address

source

pub async fn hex_public_key_to_bech32_address( &self, hex: &str, bech32_hrp: Option<impl ConvertTo<Hrp>> ) -> Result<Bech32Address>

Transforms a hex encoded public key to a bech32 encoded address

Trait Implementations§

source§

impl Clone for Client

source§

fn clone(&self) -> Client

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Client

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Deref for Client

§

type Target = ClientInner

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Client

§

impl Send for Client

§

impl Sync for Client

§

impl Unpin for Client

§

impl !UnwindSafe for Client

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> ConvertTo<T> for T
where T: Send,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> Any for T
where T: Any,

source§

impl<T> CloneAny for T
where T: Any + Clone,