iota-sdk 0.2.0

The IOTA SDK provides developers with a seamless experience to develop on IOTA by providing account abstractions and clients to interact with node APIs.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use crypto::keys::slip10::Chain;
use serde::Deserialize;

#[cfg(feature = "mqtt")]
use crate::client::mqtt::Topic;
use crate::{
    client::{
        api::{
            ClientBlockBuilderOptions as BuildBlockOptions, GetAddressesBuilderOptions as GenerateAddressesOptions,
            PreparedTransactionDataDto,
        },
        node_api::indexer::query_parameters::QueryParameter,
        node_manager::node::NodeAuth,
        secret::SecretManagerDto,
    },
    types::block::{
        address::{dto::Ed25519AddressDto, AliasAddress},
        output::{
            dto::{AliasIdDto, NativeTokenDto, NftIdDto, TokenSchemeDto},
            feature::dto::FeatureDto,
            unlock_condition::dto::UnlockConditionDto,
            AliasId, FoundryId, NftId, OutputId,
        },
        payload::{
            dto::PayloadDto,
            milestone::MilestoneId,
            transaction::{
                dto::{TransactionEssenceDto, TransactionPayloadDto},
                TransactionId,
            },
        },
        signature::dto::Ed25519SignatureDto,
        BlockDto, BlockId,
    },
};

/// Each public client method.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(tag = "name", content = "data", rename_all = "camelCase")]
pub enum Message {
    /// Build an AliasOutput.
    /// Expected response: [`BuiltOutput`](crate::client::message_interface::Response::BuiltOutput)
    #[allow(missing_docs)]
    BuildAliasOutput {
        // If not provided, minimum storage deposit will be used
        amount: Option<String>,
        #[serde(rename = "nativeTokens")]
        native_tokens: Option<Vec<NativeTokenDto>>,
        #[serde(rename = "aliasId")]
        alias_id: AliasIdDto,
        #[serde(rename = "stateIndex")]
        state_index: Option<u32>,
        #[serde(rename = "stateMetadata")]
        state_metadata: Option<String>,
        #[serde(rename = "foundryCounter")]
        foundry_counter: Option<u32>,
        #[serde(rename = "unlockConditions")]
        unlock_conditions: Vec<UnlockConditionDto>,
        features: Option<Vec<FeatureDto>>,
        #[serde(rename = "immutableFeatures")]
        immutable_features: Option<Vec<FeatureDto>>,
    },
    /// Build a BasicOutput.
    /// Expected response: [`BuiltOutput`](crate::client::message_interface::Response::BuiltOutput)
    #[allow(missing_docs)]
    BuildBasicOutput {
        // If not provided, minimum storage deposit will be used
        amount: Option<String>,
        #[serde(rename = "nativeTokens")]
        native_tokens: Option<Vec<NativeTokenDto>>,
        #[serde(rename = "unlockConditions")]
        unlock_conditions: Vec<UnlockConditionDto>,
        features: Option<Vec<FeatureDto>>,
    },
    /// Build a FoundryOutput.
    /// Expected response: [`BuiltOutput`](crate::client::message_interface::Response::BuiltOutput)
    #[allow(missing_docs)]
    BuildFoundryOutput {
        // If not provided, minimum storage deposit will be used
        amount: Option<String>,
        #[serde(rename = "nativeTokens")]
        native_tokens: Option<Vec<NativeTokenDto>>,
        #[serde(rename = "serialNumber")]
        serial_number: u32,
        #[serde(rename = "tokenScheme")]
        token_scheme: TokenSchemeDto,
        #[serde(rename = "unlockConditions")]
        unlock_conditions: Vec<UnlockConditionDto>,
        features: Option<Vec<FeatureDto>>,
        #[serde(rename = "immutableFeatures")]
        immutable_features: Option<Vec<FeatureDto>>,
    },
    /// Build an NftOutput.
    /// Expected response: [`BuiltOutput`](crate::client::message_interface::Response::BuiltOutput)
    #[allow(missing_docs)]
    BuildNftOutput {
        // If not provided, minimum storage deposit will be used
        amount: Option<String>,
        #[serde(rename = "nativeTokens")]
        native_tokens: Option<Vec<NativeTokenDto>>,
        #[serde(rename = "nftId")]
        nft_id: NftIdDto,
        #[serde(rename = "unlockConditions")]
        unlock_conditions: Vec<UnlockConditionDto>,
        features: Option<Vec<FeatureDto>>,
        #[serde(rename = "immutableFeatures")]
        immutable_features: Option<Vec<FeatureDto>>,
    },
    /// Removes all listeners for the provided topics.
    /// Expected response: [`Ok`](crate::client::message_interface::Response::Ok)
    #[cfg(feature = "mqtt")]
    #[cfg_attr(docsrs, doc(cfg(feature = "mqtt")))]
    ClearListeners {
        /// Topics for which listeners should be removed.
        topics: Vec<Topic>,
    },
    /// Generate addresses.
    GenerateAddresses {
        /// Create secret manager from json
        #[serde(rename = "secretManager")]
        secret_manager: SecretManagerDto,
        /// Addresses generation options
        options: GenerateAddressesOptions,
    },
    /// Build and post a block
    BuildAndPostBlock {
        /// Secret manager
        #[serde(rename = "secretManager")]
        secret_manager: Option<SecretManagerDto>,
        /// Options
        options: Option<BuildBlockOptions>,
    },
    /// Get a node candidate from the healthy node pool.
    GetNode,
    /// Gets the network related information such as network_id and min_pow_score
    GetNetworkInfo,
    /// Gets the network id of the node we're connecting to.
    GetNetworkId,
    /// Returns the bech32_hrp
    GetBech32Hrp,
    /// Returns the min pow score
    GetMinPowScore,
    /// Returns the tips interval
    GetTipsInterval,
    /// Returns the protocol parameters
    GetProtocolParameters,
    /// Returns if local pow should be used or not
    GetLocalPow,
    /// Get fallback to local proof of work timeout
    GetFallbackToLocalPow,
    /// Returns the unhealthy nodes.
    #[cfg(not(target_family = "wasm"))]
    UnhealthyNodes,
    /// Get the ledger status
    /// Expected response: [`LedgerNanoStatus`](crate::client::message_interface::Response::LedgerNanoStatus)
    #[cfg(feature = "ledger_nano")]
    #[cfg_attr(docsrs, doc(cfg(feature = "ledger_nano")))]
    GetLedgerNanoStatus {
        /// To use a Ledger Speculos simulator, pass `true` to `is_simulator`; `false` otherwise.
        #[serde(rename = "isSimulator")]
        is_simulator: bool,
    },
    /// Prepare a transaction for signing
    PrepareTransaction {
        /// Secret manager
        #[serde(rename = "secretManager")]
        secret_manager: Option<SecretManagerDto>,
        /// Options
        options: Option<BuildBlockOptions>,
    },
    /// Sign a transaction
    SignTransaction {
        /// Secret manager
        #[serde(rename = "secretManager")]
        secret_manager: SecretManagerDto,
        /// Prepared transaction data
        #[serde(rename = "preparedTransactionData")]
        prepared_transaction_data: PreparedTransactionDataDto,
    },
    /// Create a single Signature Unlock.
    SignatureUnlock {
        /// Secret manager
        #[serde(rename = "secretManager")]
        secret_manager: SecretManagerDto,
        /// Transaction Essence Hash
        #[serde(rename = "transactionEssenceHash")]
        transaction_essence_hash: Vec<u8>,
        /// Chain to sign the essence hash with
        chain: Chain,
    },
    /// Signs a message with an Ed25519 private key.
    SignEd25519 {
        /// Secret manager
        #[serde(rename = "secretManager")]
        secret_manager: SecretManagerDto,
        /// The message to sign, hex encoded String
        message: String,
        /// Chain to sign the essence hash with
        chain: Chain,
    },
    /// Verifies the Ed25519Signature for a message against an Ed25519Address.
    VerifyEd25519Signature {
        /// The Ed25519 Signature
        signature: Ed25519SignatureDto,
        /// The signed message, hex encoded String
        message: String,
        /// The hex encoded Ed25519 address
        address: Ed25519AddressDto,
    },
    /// Store a mnemonic in the Stronghold vault
    #[cfg(feature = "stronghold")]
    #[cfg_attr(docsrs, doc(cfg(feature = "stronghold")))]
    StoreMnemonic {
        /// Stronghold secret manager
        #[serde(rename = "secretManager")]
        secret_manager: SecretManagerDto,
        /// Mnemonic
        mnemonic: String,
    },
    /// Build a block containing the specified payload and post it to the network.
    PostBlockPayload {
        /// The payload to send
        #[serde(rename = "payload")]
        payload_dto: PayloadDto,
    },
    //////////////////////////////////////////////////////////////////////
    // Node core API
    //////////////////////////////////////////////////////////////////////
    /// Get health
    GetHealth {
        /// Url
        url: String,
    },
    /// Get node info
    GetNodeInfo {
        /// Url
        url: String,
        /// Node authentication
        auth: Option<NodeAuth>,
    },
    /// Returns the node information together with the url of the used node
    GetInfo,
    /// Get peers
    GetPeers,
    /// Get tips
    GetTips,
    /// Post block (JSON)
    PostBlock {
        /// Block
        block: BlockDto,
    },
    /// Post block (raw)
    PostBlockRaw {
        /// Block
        #[serde(rename = "blockBytes")]
        block_bytes: Vec<u8>,
    },
    /// Get block
    GetBlock {
        /// Block ID
        #[serde(rename = "blockId")]
        block_id: BlockId,
    },
    /// Get block metadata with block_id
    GetBlockMetadata {
        /// Block ID
        #[serde(rename = "blockId")]
        block_id: BlockId,
    },
    /// Get block raw
    GetBlockRaw {
        /// Block ID
        #[serde(rename = "blockId")]
        block_id: BlockId,
    },
    /// Get output
    GetOutput {
        /// Output ID
        #[serde(rename = "outputId")]
        output_id: OutputId,
    },
    /// Get output metadata
    GetOutputMetadata {
        /// Output ID
        #[serde(rename = "outputId")]
        output_id: OutputId,
    },
    /// Get the milestone by the given milestone id.
    GetMilestoneById {
        /// Milestone ID
        #[serde(rename = "milestoneId")]
        milestone_id: MilestoneId,
    },
    /// Get the raw milestone by the given milestone id.
    GetMilestoneByIdRaw {
        /// Milestone ID
        #[serde(rename = "milestoneId")]
        milestone_id: MilestoneId,
    },
    /// Get the milestone by the given index.
    GetMilestoneByIndex {
        /// Milestone Index
        index: u32,
    },
    /// Get the raw milestone by the given index.
    GetMilestoneByIndexRaw {
        /// Milestone Index
        index: u32,
    },
    /// Get the UTXO changes by the given milestone id.
    GetUtxoChangesById {
        /// Milestone ID
        #[serde(rename = "milestoneId")]
        milestone_id: MilestoneId,
    },
    /// Get the UTXO changes by the given milestone index.
    GetUtxoChangesByIndex {
        /// Milestone Index
        index: u32,
    },
    /// Get all receipts.
    GetReceipts,
    /// Get the receipts by the given milestone index.
    GetReceiptsMigratedAt {
        /// Milestone index
        #[serde(rename = "milestoneIndex")]
        milestone_index: u32,
    },
    /// Get the treasury output.
    GetTreasury,
    /// Returns the included block of the transaction.
    GetIncludedBlock {
        /// Transaction ID
        #[serde(rename = "transactionId")]
        transaction_id: TransactionId,
    },
    /// Returns the included block metadata of the transaction.
    GetIncludedBlockMetadata {
        /// Transaction ID
        #[serde(rename = "transactionId")]
        transaction_id: TransactionId,
    },

    //////////////////////////////////////////////////////////////////////
    // Node indexer API
    //////////////////////////////////////////////////////////////////////
    /// Fetch basic output IDs
    BasicOutputIds {
        /// Query parameters for output requests
        #[serde(rename = "queryParameters")]
        query_parameters: Vec<QueryParameter>,
    },
    /// Fetch alias output IDs
    AliasOutputIds {
        /// Query parameters for output requests
        #[serde(rename = "queryParameters")]
        query_parameters: Vec<QueryParameter>,
    },
    /// Fetch alias output ID
    AliasOutputId {
        /// Alias id
        #[serde(rename = "aliasId")]
        alias_id: AliasId,
    },
    /// Fetch NFT output IDs
    NftOutputIds {
        /// Query parameters for output requests
        #[serde(rename = "queryParameters")]
        query_parameters: Vec<QueryParameter>,
    },
    /// Fetch NFT output ID
    NftOutputId {
        /// NFT ID
        #[serde(rename = "nftId")]
        nft_id: NftId,
    },
    /// Fetch foundry Output IDs
    FoundryOutputIds {
        /// Query parameters for output requests
        #[serde(rename = "queryParameters")]
        query_parameters: Vec<QueryParameter>,
    },
    /// Fetch foundry Output ID
    FoundryOutputId {
        /// Foundry ID
        #[serde(rename = "foundryId")]
        foundry_id: FoundryId,
    },

    //////////////////////////////////////////////////////////////////////
    // High level API
    //////////////////////////////////////////////////////////////////////
    /// Fetch OutputWithMetadataResponse from provided OutputIds (requests are sent in parallel)
    GetOutputs {
        /// Output IDs
        #[serde(rename = "outputIds")]
        output_ids: Vec<OutputId>,
    },
    /// Try to get OutputWithMetadataResponse from provided OutputIds (requests are sent in parallel and errors are
    /// ignored, can be useful for spent outputs)
    TryGetOutputs {
        /// Output IDs
        #[serde(rename = "outputIds")]
        output_ids: Vec<OutputId>,
    },
    /// Find all blocks by provided block IDs.
    FindBlocks {
        /// BlockIDs
        #[serde(rename = "blockIds")]
        block_ids: Vec<BlockId>,
    },
    /// 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.
    Retry {
        /// Block ID
        #[serde(rename = "blockId")]
        block_id: BlockId,
    },
    /// 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
    RetryUntilIncluded {
        /// Block ID
        #[serde(rename = "blockId")]
        block_id: BlockId,
        /// Interval
        interval: Option<u64>,
        /// Maximum attempts
        #[serde(rename = "maxAttempts")]
        max_attempts: Option<u64>,
    },
    /// Function to consolidate all funds 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
    ConsolidateFunds {
        /// Secret manager
        #[serde(rename = "secretManager")]
        secret_manager: SecretManagerDto,
        /// Addresses generation options
        #[serde(rename = "generateAddressesOptions")]
        generate_addresses_options: GenerateAddressesOptions,
    },
    /// Function to find inputs from addresses for a provided amount (useful for offline signing)
    FindInputs {
        /// Addresses
        addresses: Vec<String>,
        /// Amount
        amount: u64,
    },
    /// Find all outputs based on the requests criteria. This method will try to query multiple nodes if
    /// the request amount exceeds individual node limit.
    FindOutputs {
        /// Output IDs
        #[serde(rename = "outputIds")]
        output_ids: Vec<OutputId>,
        /// Addresses
        addresses: Vec<String>,
    },
    /// Reattaches blocks for provided block id. Blocks can be reattached only if they are valid and haven't been
    /// confirmed for a while.
    Reattach {
        /// Block ID
        #[serde(rename = "blockId")]
        block_id: BlockId,
    },
    /// Reattach a block without checking if it should be reattached
    ReattachUnchecked {
        /// Block ID
        #[serde(rename = "blockId")]
        block_id: BlockId,
    },
    /// 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.
    Promote {
        /// Block ID
        #[serde(rename = "blockId")]
        block_id: BlockId,
    },
    /// Promote a block without checking if it should be promoted
    PromoteUnchecked {
        /// Block ID
        #[serde(rename = "blockId")]
        block_id: BlockId,
    },

    //////////////////////////////////////////////////////////////////////
    // Utils
    //////////////////////////////////////////////////////////////////////
    /// Transforms bech32 to hex
    Bech32ToHex {
        /// Bech32 encoded address
        bech32: String,
    },
    /// Transforms a hex encoded address to a bech32 encoded address
    HexToBech32 {
        /// Hex encoded bech32 address
        hex: String,
        /// Human readable part
        #[serde(rename = "bech32Hrp")]
        bech32_hrp: Option<String>,
    },
    /// Transforms an alias id to a bech32 encoded address
    AliasIdToBech32 {
        /// Alias ID
        #[serde(rename = "aliasId")]
        alias_id: AliasId,
        /// Human readable part
        #[serde(rename = "bech32Hrp")]
        bech32_hrp: Option<String>,
    },
    /// Transforms an nft id to a bech32 encoded address
    NftIdToBech32 {
        /// Nft ID
        #[serde(rename = "nftId")]
        nft_id: NftId,
        /// Human readable part
        #[serde(rename = "bech32Hrp")]
        bech32_hrp: Option<String>,
    },
    /// Transforms a hex encoded public key to a bech32 encoded address
    HexPublicKeyToBech32Address {
        /// Hex encoded public key
        hex: String,
        /// Human readable part
        #[serde(rename = "bech32Hrp")]
        bech32_hrp: Option<String>,
    },
    /// Returns a valid Address parsed from a String.
    ParseBech32Address {
        /// Address
        address: String,
    },
    /// Checks if a String is a valid bech32 encoded address.
    IsAddressValid {
        /// Address
        address: String,
    },
    /// Generates a new mnemonic.
    GenerateMnemonic,
    /// Returns a hex encoded seed for a mnemonic.
    MnemonicToHexSeed {
        /// Mnemonic
        mnemonic: String,
    },
    /// Returns a block ID (Blake2b256 hash of block bytes) from a block
    BlockId {
        /// Block
        block: BlockDto,
    },
    /// Returns the transaction ID (Blake2b256 hash of the provided transaction payload)
    TransactionId {
        /// Transaction Payload
        payload: TransactionPayloadDto,
    },
    /// Computes the alias ID
    ComputeAliasId {
        /// Output ID
        #[serde(rename = "outputId")]
        output_id: OutputId,
    },
    /// Computes the NFT ID
    ComputeNftId {
        /// Output ID
        #[serde(rename = "outputId")]
        output_id: OutputId,
    },
    /// Computes the Foundry ID
    ComputeFoundryId {
        /// Alias address
        #[serde(rename = "aliasAddress")]
        alias_address: AliasAddress,
        /// Serial number
        #[serde(rename = "serialNumber")]
        serial_number: u32,
        /// Token scheme kind
        #[serde(rename = "tokenSchemeKind")]
        token_scheme_kind: u8,
    },
    /// Requests funds for a given address from the faucet.
    Faucet {
        /// Faucet URL
        url: String,
        /// The address for request funds
        address: String,
    },
    /// Compute the hash of a transaction essence.
    HashTransactionEssence {
        /// The transaction essence
        essence: TransactionEssenceDto,
    },
}