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 Mar 8, 2024
2 parents 79f1f6c + ffb6fc2 commit 603b4a9
Show file tree
Hide file tree
Showing 221 changed files with 4,837 additions and 4,967 deletions.
7 changes: 4 additions & 3 deletions .github/actions/private-tangle/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ runs:
- name: Wait for tangle to start
shell: bash
run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/v2.2.4/wait-for | sh -s -- -t 120 http://localhost:8050/health -- echo "Tangle is up"
- name: Wait for faucet to start
shell: bash
run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/v2.2.4/wait-for | sh -s -- -t 120 http://localhost:8088/health -- echo "Faucet is up"
# TODO https://github.com/iotaledger/iota-sdk/issues/2154
# - name: Wait for faucet to start
# shell: bash
# run: wget -qO- https://raw.githubusercontent.com/eficode/wait-for/v2.2.4/wait-for | sh -s -- -t 120 http://localhost:8088/health -- echo "Faucet is up"
42 changes: 2 additions & 40 deletions bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ pub enum ClientMethod {
},
/// Returns general information about the node together with its URL.
GetNodeInfo,
/// Returns network metrics.
GetNetworkMetrics,
/// Check the readiness of the node to issue a new block, the reference mana cost based on the rate setter and
/// current network congestion, and the block issuance credits of the requested account.
#[serde(rename_all = "camelCase")]
Expand Down Expand Up @@ -432,49 +434,9 @@ pub enum ClientMethod {
//////////////////////////////////////////////////////////////////////
// Utils
//////////////////////////////////////////////////////////////////////
/// Transforms a hex encoded address to a bech32 encoded address
#[serde(rename_all = "camelCase")]
HexToBech32 {
/// Hex encoded bech32 address
hex: String,
/// Human readable part
bech32_hrp: Option<Hrp>,
},
/// Converts an address to its bech32 representation
#[serde(rename_all = "camelCase")]
AddressToBech32 { address: Address, bech32_hrp: Option<Hrp> },
/// Transforms an account id to a bech32 encoded address
#[serde(rename_all = "camelCase")]
AccountIdToBech32 {
/// Account ID
account_id: AccountId,
/// Human readable part
bech32_hrp: Option<Hrp>,
},
/// Transforms an anchor id to a bech32 encoded address
#[serde(rename_all = "camelCase")]
AnchorIdToBech32 {
/// Anchor ID
anchor_id: AnchorId,
/// Human readable part
bech32_hrp: Option<Hrp>,
},
/// Transforms an nft id to a bech32 encoded address
#[serde(rename_all = "camelCase")]
NftIdToBech32 {
/// Nft ID
nft_id: NftId,
/// Human readable part
bech32_hrp: Option<Hrp>,
},
/// Transforms a hex encoded public key to a bech32 encoded address
#[serde(rename_all = "camelCase")]
HexPublicKeyToBech32Address {
/// Hex encoded public key
hex: String,
/// Human readable part
bech32_hrp: Option<Hrp>,
},
/// Calculate the minimum required amount for an output.
/// Expected response:
/// [`Amount`](crate::Response::Amount)
Expand Down
2 changes: 1 addition & 1 deletion bindings/core/src/method/secret_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use crate::OmittedDebug;
#[serde(tag = "name", content = "data", rename_all = "camelCase")]
#[non_exhaustive]
pub enum SecretManagerMethod {
/// Generate Ed25519 addresses.
/// Generate multiple Ed25519 addresses at once.
GenerateEd25519Addresses {
/// Addresses generation options
options: GetAddressesOptions,
Expand Down
50 changes: 6 additions & 44 deletions bindings/core/src/method/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use iota_sdk::{
client::secret::types::InputSigningData,
types::block::{
address::{Address, Bech32Address, Hrp},
output::{AccountId, AnchorId, NftId, Output, OutputId, StorageScoreParameters},
output::{AccountId, Output, OutputId, StorageScoreParameters},
payload::signed_transaction::{
dto::{SignedTransactionPayloadDto, TransactionDto},
TransactionId,
Expand All @@ -19,7 +19,7 @@ use iota_sdk::{
unlock::Unlock,
BlockDto,
},
utils::serde::{option_mana_rewards, string},
utils::serde::{option_mana_rewards, prefix_hex_bytes, string},
};
use serde::{Deserialize, Serialize};

Expand All @@ -31,46 +31,12 @@ use crate::OmittedDebug;
#[serde(tag = "name", content = "data", rename_all = "camelCase")]
#[non_exhaustive]
pub enum UtilsMethod {
/// Transforms bech32 to hex
Bech32ToHex {
bech32: Bech32Address,
},
/// Transforms a hex encoded address to a bech32 encoded address
#[serde(rename_all = "camelCase")]
HexToBech32 {
hex: String,
bech32_hrp: Hrp,
},
/// Converts an address to its bech32 representation
#[serde(rename_all = "camelCase")]
AddressToBech32 {
address: Address,
bech32_hrp: Hrp,
},
/// Transforms an account id to a bech32 encoded address
#[serde(rename_all = "camelCase")]
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,
},
/// Transforms an nft id to a bech32 encoded address
#[serde(rename_all = "camelCase")]
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,
},
/// Returns a valid Address parsed from a String.
ParseBech32Address {
address: Bech32Address,
Expand All @@ -96,10 +62,11 @@ pub enum UtilsMethod {
TransactionId {
payload: SignedTransactionPayloadDto,
},
/// Computes the account ID
/// Computes the Blake2b256 hash of the provided hex encoded bytes.
#[serde(rename_all = "camelCase")]
ComputeAccountId {
output_id: OutputId,
Blake2b256Hash {
#[serde(with = "prefix_hex_bytes")]
bytes: Vec<u8>,
},
/// Computes the Foundry ID
#[serde(rename_all = "camelCase")]
Expand All @@ -108,11 +75,6 @@ pub enum UtilsMethod {
serial_number: u32,
token_scheme_type: u8,
},
/// Computes the NFT ID
#[serde(rename_all = "camelCase")]
ComputeNftId {
output_id: OutputId,
},
/// Computes the output ID from transaction id and output index
ComputeOutputId {
id: TransactionId,
Expand Down
58 changes: 7 additions & 51 deletions bindings/core/src/method/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::path::PathBuf;

use crypto::keys::bip44::Bip44;
use derivative::Derivative;
use iota_sdk::utils::serde::string;
use iota_sdk::client::api::options::TransactionOptions;
#[cfg(feature = "events")]
use iota_sdk::wallet::events::types::{WalletEvent, WalletEventType};
// #[cfg(feature = "participation")]
Expand All @@ -17,19 +17,18 @@ use iota_sdk::wallet::events::types::{WalletEvent, WalletEventType};
// };
use iota_sdk::{
client::{
api::{input_selection::Burn, PreparedTransactionDataDto, SignedTransactionDataDto},
api::{transaction_builder::Burn, PreparedTransactionDataDto, SignedTransactionDataDto},
node_manager::node::NodeAuth,
secret::GenerateAddressOptions,
},
types::block::{
address::{Bech32Address, Hrp},
address::Hrp,
output::{AccountId, DelegationId, Output, OutputId, TokenId},
payload::signed_transaction::TransactionId,
},
wallet::{
BeginStakingParams, ClientOptions, ConsolidationParams, CreateAccountParams, CreateDelegationParams,
CreateNativeTokenParams, FilterOptions, MintNftParams, OutputParams, OutputsToClaim, SendManaParams,
SendNativeTokenParams, SendNftParams, SendParams, SyncOptions, TransactionOptions,
SendNativeTokenParams, SendNftParams, SendParams, SyncOptions,
},
U256,
};
Expand Down Expand Up @@ -119,10 +118,6 @@ pub enum WalletMethod {
/// Expected response: [`OutputIds`](crate::Response::OutputIds)
#[serde(rename_all = "camelCase")]
ClaimableOutputs { outputs_to_claim: OutputsToClaim },
/// Claim outputs.
/// Expected response: [`SentTransaction`](crate::Response::SentTransaction)
#[serde(rename_all = "camelCase")]
ClaimOutputs { output_ids_to_claim: Vec<OutputId> },
// /// Removes a previously registered participation event from local storage.
// /// Expected response: [`Ok`](crate::Response::Ok)
// #[cfg(feature = "participation")]
Expand Down Expand Up @@ -308,7 +303,7 @@ pub enum WalletMethod {
#[serde(default)]
transaction_options: Option<TransactionOptions>,
},
/// Prepare to send base coins.
/// Prepare to send base coins to multiple addresses, or with additional parameters.
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
PrepareSend {
params: Vec<SendParams>,
Expand Down Expand Up @@ -385,9 +380,9 @@ pub enum WalletMethod {
// #[cfg_attr(docsrs, doc(cfg(feature = "participation")))]
// #[serde(rename_all = "camelCase")]
// PrepareStopParticipating { event_id: ParticipationEventId },
/// Prepare transaction.
/// Prepare to send outputs.
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
PrepareTransaction {
PrepareSendOutputs {
outputs: Vec<Output>,
#[serde(default)]
options: Option<TransactionOptions>,
Expand Down Expand Up @@ -421,29 +416,6 @@ pub enum WalletMethod {
/// Maximum attempts
max_attempts: Option<u64>,
},
/// Send base coins.
/// Expected response: [`SentTransaction`](crate::Response::SentTransaction)
Send {
#[serde(with = "string")]
amount: u64,
address: Bech32Address,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Send base coins to multiple addresses, or with additional parameters.
/// Expected response: [`SentTransaction`](crate::Response::SentTransaction)
SendWithParams {
params: Vec<SendParams>,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Send outputs in a transaction.
/// Expected response: [`SentTransaction`](crate::Response::SentTransaction)
SendOutputs {
outputs: Vec<Output>,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Set the alias of the wallet.
/// Expected response: [`Ok`](crate::Response::Ok)
SetAlias { alias: String },
Expand Down Expand Up @@ -483,27 +455,11 @@ pub enum WalletMethod {
/// Expected response: [`OutputsData`](crate::Response::OutputsData)
#[serde(rename_all = "camelCase")]
UnspentOutputs { filter_options: Option<FilterOptions> },

/// Emits an event for testing if the event system is working
/// Expected response: [`Ok`](crate::Response::Ok)
#[cfg(feature = "events")]
#[cfg_attr(docsrs, doc(cfg(feature = "events")))]
EmitTestEvent { event: WalletEvent },

// TODO: reconsider whether to have the following methods on the wallet
/// Generate an address without storing it
/// Expected response: [`Bech32Address`](crate::Response::Bech32Address)
#[serde(rename_all = "camelCase")]
GenerateEd25519Address {
/// Account index
account_index: u32,
/// Account index
address_index: u32,
/// Options
options: Option<GenerateAddressOptions>,
/// Bech32 HRP
bech32_hrp: Option<Hrp>,
},
/// Get the ledger nano status
/// Expected response: [`LedgerNanoStatus`](crate::Response::LedgerNanoStatus)
#[cfg(feature = "ledger_nano")]
Expand Down
16 changes: 1 addition & 15 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ pub(crate) async fn call_client_method_internal(
ClientMethod::GetHealth { url } => Response::Bool(client.get_health(&url).await?),
ClientMethod::GetInfo { url, auth } => Response::Info(Client::get_info(&url, auth).await?),
ClientMethod::GetNodeInfo => Response::NodeInfo(client.get_node_info().await?),
ClientMethod::GetNetworkMetrics => Response::NetworkMetrics(client.get_network_metrics().await?),
ClientMethod::GetRoutes => Response::Routes(client.get_routes().await?),
ClientMethod::GetAccountCongestion { account_id, work_score } => {
Response::Congestion(client.get_account_congestion(&account_id, work_score).await?)
Expand Down Expand Up @@ -306,24 +307,9 @@ pub(crate) async fn call_client_method_internal(
ClientMethod::FindInputs { addresses, amount } => {
Response::Inputs(client.find_inputs(addresses, amount).await?)
}
ClientMethod::HexToBech32 { hex, bech32_hrp } => {
Response::Bech32Address(client.hex_to_bech32(&hex, bech32_hrp).await?)
}
ClientMethod::AddressToBech32 { address, bech32_hrp } => {
Response::Bech32Address(client.address_to_bech32(address, bech32_hrp).await?)
}
ClientMethod::AccountIdToBech32 { account_id, bech32_hrp } => {
Response::Bech32Address(client.account_id_to_bech32(account_id, bech32_hrp).await?)
}
ClientMethod::AnchorIdToBech32 { anchor_id, bech32_hrp } => {
Response::Bech32Address(client.anchor_id_to_bech32(anchor_id, bech32_hrp).await?)
}
ClientMethod::NftIdToBech32 { nft_id, bech32_hrp } => {
Response::Bech32Address(client.nft_id_to_bech32(nft_id, bech32_hrp).await?)
}
ClientMethod::HexPublicKeyToBech32Address { hex, bech32_hrp } => {
Response::Bech32Address(client.hex_public_key_to_bech32_address(&hex, bech32_hrp).await?)
}
ClientMethod::ComputeMinimumOutputAmount { output } => {
let storage_score_params = client.get_storage_score_parameters().await?;

Expand Down
28 changes: 9 additions & 19 deletions bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// Copyright 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use crypto::keys::bip39::Mnemonic;
use crypto::{
hashes::{blake2b::Blake2b256, Digest},
keys::bip39::Mnemonic,
};
use iota_sdk::{
client::{hex_public_key_to_bech32_address, hex_to_bech32, verify_mnemonic, Client},
client::{verify_mnemonic, Client},
types::{
block::{
address::{AccountAddress, Address, ToBech32Ext},
input::UtxoInput,
output::{AccountId, FoundryId, MinimumOutputAmount, NftId, Output, OutputId, TokenId},
output::{FoundryId, MinimumOutputAmount, Output, OutputId, TokenId},
payload::{signed_transaction::Transaction, SignedTransactionPayload},
semantic::SemanticValidationContext,
signature::SignatureError,
Expand All @@ -24,19 +27,7 @@ use crate::{method::UtilsMethod, response::Response};
/// Call a utils method.
pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response, crate::Error> {
let response = match method {
UtilsMethod::Bech32ToHex { bech32 } => Response::Bech32ToHex(Client::bech32_to_hex(bech32)?),
UtilsMethod::HexToBech32 { hex, bech32_hrp } => Response::Bech32Address(hex_to_bech32(&hex, bech32_hrp)?),
UtilsMethod::AddressToBech32 { address, bech32_hrp } => Response::Bech32Address(address.to_bech32(bech32_hrp)),
UtilsMethod::AccountIdToBech32 { account_id, bech32_hrp } => {
Response::Bech32Address(account_id.to_bech32(bech32_hrp))
}
UtilsMethod::AnchorIdToBech32 { anchor_id, bech32_hrp } => {
Response::Bech32Address(anchor_id.to_bech32(bech32_hrp))
}
UtilsMethod::NftIdToBech32 { nft_id, bech32_hrp } => Response::Bech32Address(nft_id.to_bech32(bech32_hrp)),
UtilsMethod::HexPublicKeyToBech32Address { hex, bech32_hrp } => {
Response::Bech32Address(hex_public_key_to_bech32_address(&hex, bech32_hrp)?)
}
UtilsMethod::ParseBech32Address { address } => Response::ParsedBech32Address(address.into_inner()),
UtilsMethod::IsAddressValid { address } => Response::Bool(Address::is_valid_bech32(&address)),
UtilsMethod::GenerateMnemonic => Response::GeneratedMnemonic(Client::generate_mnemonic()?.to_string()),
Expand All @@ -55,7 +46,7 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
let payload = SignedTransactionPayload::try_from_dto(payload)?;
Response::TransactionId(payload.transaction().id())
}
UtilsMethod::ComputeAccountId { output_id } => Response::AccountId(AccountId::from(&output_id)),
UtilsMethod::Blake2b256Hash { bytes } => Response::Hash(prefix_hex::encode(Blake2b256::digest(bytes).to_vec())),
UtilsMethod::ComputeFoundryId {
account_id,
serial_number,
Expand All @@ -65,7 +56,6 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
serial_number,
token_scheme_type,
)),
UtilsMethod::ComputeNftId { output_id } => Response::NftId(NftId::from(&output_id)),
UtilsMethod::ComputeOutputId { id, index } => Response::OutputId(OutputId::new(id, index)),
UtilsMethod::ComputeTokenId {
account_id,
Expand Down Expand Up @@ -133,8 +123,8 @@ pub(crate) fn call_utils_method_internal(method: UtilsMethod) -> Result<Response
&transaction,
&inputs,
unlocks.as_deref(),
mana_rewards,
protocol_parameters,
mana_rewards.as_ref(),
&protocol_parameters,
);
context.validate()?;

Expand Down
Loading

0 comments on commit 603b4a9

Please sign in to comment.