Skip to content

Commit

Permalink
Merge branch '2.0' of https://github.com/iotaledger/iota-sdk into 500…
Browse files Browse the repository at this point in the history
…-error-patch
  • Loading branch information
marc2332 committed Feb 26, 2024
2 parents 31f20f1 + 56b19d4 commit ddb3652
Show file tree
Hide file tree
Showing 167 changed files with 3,088 additions and 1,958 deletions.
353 changes: 154 additions & 199 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions bindings/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ publish = false
[dependencies]
iota-sdk = { path = "../../sdk", default-features = false, features = [
"wallet",
"protocol_parameters_samples",
"tls",
] }

Expand All @@ -23,12 +24,14 @@ iota-crypto = { version = "0.23.1", default-features = false, features = [
"bip44",
] }
log = { version = "0.4.20", default-features = false }
packable = { version = "0.10.1", default-features = false }
packable = { version = "0.11.0", default-features = false, features = [
"primitive-types",
] }
prefix-hex = { version = "0.7.1", default-features = false }
primitive-types = { version = "0.12.2", default-features = false }
serde = { version = "1.0.196", default-features = false }
serde_json = { version = "1.0.113", default-features = false }
strum = { version = "0.25.0", default-features = false, features = ["derive"] }
strum = { version = "0.26.1", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.56", default-features = false }
tokio = { version = "1.35.1", default-features = false }
url = { version = "2.4.1", default-features = false, features = ["serde"] }
Expand Down
77 changes: 59 additions & 18 deletions bindings/core/src/method/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,47 @@ use crate::OmittedDebug;
#[non_exhaustive]
pub enum UtilsMethod {
/// Transforms bech32 to hex
Bech32ToHex { bech32: Bech32Address },
Bech32ToHex {
bech32: Bech32Address,
},
/// Transforms a hex encoded address to a bech32 encoded address
#[serde(rename_all = "camelCase")]
HexToBech32 { hex: String, bech32_hrp: Hrp },
HexToBech32 {
hex: String,
bech32_hrp: Hrp,
},
/// Transforms an account id to a bech32 encoded address
#[serde(rename_all = "camelCase")]
AccountIdToBech32 { account_id: AccountId, bech32_hrp: Hrp },
AccountIdToBech32 {
account_id: AccountId,
bech32_hrp: Hrp,
},
/// Transforms an anchor id to a bech32 encoded address
#[serde(rename_all = "camelCase")]
AnchorIdToBech32 { anchor_id: AnchorId, bech32_hrp: Hrp },
AnchorIdToBech32 {
anchor_id: AnchorId,
bech32_hrp: Hrp,
},
/// Transforms an nft id to a bech32 encoded address
#[serde(rename_all = "camelCase")]
NftIdToBech32 { nft_id: NftId, bech32_hrp: Hrp },
NftIdToBech32 {
nft_id: NftId,
bech32_hrp: Hrp,
},
/// Transforms a hex encoded public key to a bech32 encoded address
#[serde(rename_all = "camelCase")]
HexPublicKeyToBech32Address { hex: String, bech32_hrp: Hrp },
HexPublicKeyToBech32Address {
hex: String,
bech32_hrp: Hrp,
},
/// Returns a valid Address parsed from a String.
ParseBech32Address { address: Bech32Address },
ParseBech32Address {
address: Bech32Address,
},
/// Checks if a String is a valid bech32 encoded address.
IsAddressValid { address: String },
IsAddressValid {
address: String,
},
/// Generates a new mnemonic.
GenerateMnemonic,
/// Returns a hex encoded seed for a mnemonic.
Expand All @@ -66,10 +87,14 @@ pub enum UtilsMethod {
protocol_parameters: ProtocolParameters,
},
/// Returns the transaction ID (Blake2b256 hash of the provided transaction payload)
TransactionId { payload: SignedTransactionPayloadDto },
TransactionId {
payload: SignedTransactionPayloadDto,
},
/// Computes the account ID
#[serde(rename_all = "camelCase")]
ComputeAccountId { output_id: OutputId },
ComputeAccountId {
output_id: OutputId,
},
/// Computes the Foundry ID
#[serde(rename_all = "camelCase")]
ComputeFoundryId {
Expand All @@ -79,9 +104,14 @@ pub enum UtilsMethod {
},
/// Computes the NFT ID
#[serde(rename_all = "camelCase")]
ComputeNftId { output_id: OutputId },
ComputeNftId {
output_id: OutputId,
},
/// Computes the output ID from transaction id and output index
ComputeOutputId { id: TransactionId, index: u16 },
ComputeOutputId {
id: TransactionId,
index: u16,
},
/// Computes a tokenId from the accountId, serial number and token scheme type.
#[serde(rename_all = "camelCase")]
ComputeTokenId {
Expand All @@ -91,9 +121,13 @@ pub enum UtilsMethod {
},
/// Computes the hash of the given protocol parameters.
#[serde(rename_all = "camelCase")]
ProtocolParametersHash { protocol_parameters: ProtocolParameters },
ProtocolParametersHash {
protocol_parameters: ProtocolParameters,
},
/// Computes the signing hash of a transaction.
TransactionSigningHash { transaction: TransactionDto },
TransactionSigningHash {
transaction: TransactionDto,
},
/// Computes the minimum required amount of an output.
#[serde(rename_all = "camelCase")]
ComputeMinimumOutputAmount {
Expand All @@ -120,13 +154,18 @@ pub enum UtilsMethod {
},
/// Creates a UTXOInput from outputId.
#[serde(rename_all = "camelCase")]
OutputIdToUtxoInput { output_id: OutputId },
OutputIdToUtxoInput {
output_id: OutputId,
},
/// Computes the slot commitment id from a slot commitment.
#[serde(rename_all = "camelCase")]
ComputeSlotCommitmentId { slot_commitment: SlotCommitment },
ComputeSlotCommitmentId {
slot_commitment: SlotCommitment,
},
/// Returns the hex representation of the serialized output bytes.
#[serde(rename_all = "camelCase")]
OutputHexBytes { output: Output },
OutputHexBytes {
output: Output,
},
/// Verifies the semantic of a transaction.
/// Expected response: [`TransactionFailureReason`](crate::Response::TransactionFailureReason)
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -178,4 +217,6 @@ pub enum UtilsMethod {
/// Block
block: BlockDto,
},
IotaMainnetProtocolParameters,
ShimmerMainnetProtocolParameters,
}
8 changes: 7 additions & 1 deletion bindings/core/src/method/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,17 @@ pub enum WalletMethod {
PrepareExtendStaking {
account_id: AccountId,
additional_epochs: u32,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Prepare to end staking.
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
#[serde(rename_all = "camelCase")]
PrepareEndStaking { account_id: AccountId },
PrepareEndStaking {
account_id: AccountId,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Announce candidacy for an account.
/// Expected response: [`BlockId`](crate::Response::BlockId)
#[serde(rename_all = "camelCase")]
Expand Down
6 changes: 6 additions & 0 deletions bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
let block = Block::try_from_dto(block)?;
Response::Raw(block.pack_to_vec())
}
UtilsMethod::IotaMainnetProtocolParameters => {
Response::ProtocolParameters(iota_sdk::types::block::protocol::iota_mainnet_protocol_parameters().clone())
}
UtilsMethod::ShimmerMainnetProtocolParameters => Response::ProtocolParameters(
iota_sdk::types::block::protocol::shimmer_mainnet_protocol_parameters().clone(),
),
};

Ok(response)
Expand Down
9 changes: 6 additions & 3 deletions bindings/core/src/method_handler/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,15 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
WalletMethod::PrepareExtendStaking {
account_id,
additional_epochs,
options,
} => {
let data = wallet.prepare_extend_staking(account_id, additional_epochs).await?;
let data = wallet
.prepare_extend_staking(account_id, additional_epochs, options)
.await?;
Response::PreparedTransaction(data)
}
WalletMethod::PrepareEndStaking { account_id } => {
let data = wallet.prepare_end_staking(account_id).await?;
WalletMethod::PrepareEndStaking { account_id, options } => {
let data = wallet.prepare_end_staking(account_id, options).await?;
Response::PreparedTransaction(data)
}
WalletMethod::AnnounceCandidacy { account_id } => {
Expand Down
14 changes: 12 additions & 2 deletions bindings/core/tests/combined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ async fn create_wallet() -> Result<()> {

let wallet = WalletOptions::default()
.with_storage_path(storage_path.to_string())
.with_client_options(ClientBuilder::new().from_json(client_options).unwrap())
.with_client_options(
ClientBuilder::new()
.from_json(client_options)
.unwrap()
.with_protocol_parameters(iota_sdk::types::block::protocol::iota_mainnet_protocol_parameters().clone()),
)
.with_bip_path(Bip44::new(SHIMMER_COIN_TYPE))
.with_secret_manager(serde_json::from_str::<SecretManagerDto>(secret_manager).unwrap())
.build()
Expand Down Expand Up @@ -79,7 +84,12 @@ async fn client_from_wallet() -> Result<()> {

let wallet = WalletOptions::default()
.with_storage_path(storage_path.to_string())
.with_client_options(ClientBuilder::new().from_json(client_options).unwrap())
.with_client_options(
ClientBuilder::new()
.from_json(client_options)
.unwrap()
.with_protocol_parameters(iota_sdk::types::block::protocol::iota_mainnet_protocol_parameters().clone()),
)
.with_bip_path(Bip44::new(SHIMMER_COIN_TYPE))
.with_secret_manager(serde_json::from_str::<SecretManagerDto>(secret_manager).unwrap())
.build()
Expand Down
7 changes: 5 additions & 2 deletions bindings/nodejs/lib/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ import {

import { plainToInstance } from 'class-transformer';
import { ManaRewardsResponse } from '../types/models/api/mana-rewards-response';
import { ValidatorsResponse } from '../types/models/api/validators-response';
import {
ValidatorResponse,
ValidatorsResponse,
} from '../types/models/api/validators-response';

/** The Client to interact with nodes. */
export class Client {
Expand Down Expand Up @@ -176,7 +179,7 @@ export class Client {
/**
* Return information about a validator.
*/
async getValidator(accountId: AccountId): Promise<ValidatorsResponse> {
async getValidator(accountId: AccountId): Promise<ValidatorResponse> {
const response = await this.methodHandler.callMethod({
name: 'getValidator',
data: {
Expand Down
5 changes: 3 additions & 2 deletions bindings/nodejs/lib/types/client/client-options.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2021-2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
import type { IMqttBrokerOptions, INetworkInfo, INode } from './network';
import { ProtocolParameters } from '../models';
import type { IMqttBrokerOptions, INode } from './network';

/** Options for the client builder */
export interface IClientOptions {
Expand All @@ -21,7 +22,7 @@ export interface IClientOptions {
/** % of nodes that have to return the same response so it gets accepted */
quorumThreshold?: number;
/** Data related to the used network */
networkInfo?: INetworkInfo;
protocolParameters?: ProtocolParameters;
/** Options for the MQTT broker */
brokerOptions?: IMqttBrokerOptions;
/** Timeout for API requests */
Expand Down
6 changes: 5 additions & 1 deletion bindings/nodejs/lib/types/utils/bridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import type {
__OutputManaWithDecay__,
__VerifyTransactionSyntax__,
__BlockBytes__,
__IotaMainnetProtocolParameters__,
__ShimmerMainnetProtocolParameters__,
} from './utils';

export type __UtilsMethods__ =
Expand Down Expand Up @@ -67,4 +69,6 @@ export type __UtilsMethods__ =
| __GenerateManaWithDecay__
| __OutputManaWithDecay__
| __VerifyTransactionSyntax__
| __BlockBytes__;
| __BlockBytes__
| __IotaMainnetProtocolParameters__
| __ShimmerMainnetProtocolParameters__;
8 changes: 8 additions & 0 deletions bindings/nodejs/lib/types/utils/bridge/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,11 @@ export interface __BlockBytes__ {
block: Block;
};
}

export interface __IotaMainnetProtocolParameters__ {
name: 'iotaMainnetProtocolParameters';
}

export interface __ShimmerMainnetProtocolParameters__ {
name: 'shimmerMainnetProtocolParameters';
}
5 changes: 5 additions & 0 deletions bindings/nodejs/lib/types/wallet/transaction-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export interface TransactionOptions {
allowMicroAmount?: boolean;
/** Whether to allow the selection of additional inputs for this transaction. */
allowAdditionalInputSelection?: boolean;
/**
* Whether to allow allotting automatically calculated mana from the issuer account.
* If this flag is disabled, additional inputs will be selected to cover the amount.
*/
allowAllottingFromAccountMana?: boolean;
/** Transaction capabilities. */
capabilities?: HexEncodedString;
/** Mana allotments for the transaction. */
Expand Down
14 changes: 14 additions & 0 deletions bindings/nodejs/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,4 +687,18 @@ export class Utils {
});
return new Uint8Array(blockBytes);
}

static iotaMainnetProtocolParameters(): ProtocolParameters {
const params = callUtilsMethod({
name: 'iotaMainnetProtocolParameters',
});
return params;
}

static shimmerMainnetProtocolParameters(): ProtocolParameters {
const params = callUtilsMethod({
name: 'shimmerMainnetProtocolParameters',
});
return params;
}
}
Loading

0 comments on commit ddb3652

Please sign in to comment.