Skip to content

Commit

Permalink
Merge branch '2.0' into fix/missing-CommitmentContextInput
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M committed Mar 11, 2024
2 parents 769eeeb + c6b4d2f commit 6b812e1
Show file tree
Hide file tree
Showing 146 changed files with 1,281 additions and 1,941 deletions.
9 changes: 4 additions & 5 deletions .github/actions/private-tangle/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ runs:
uses: actions/checkout@v3
with:
repository: iotaledger/iota-core
# TODO: remove ref when inx plugins are updated to the latest commit
ref: 25995c84ccc4f4cd9041881035f338acca513b0a
path: iota-core

- name: Prepare files for start and stop
Expand Down Expand Up @@ -40,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"
34 changes: 2 additions & 32 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,41 +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>,
},
/// 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
30 changes: 1 addition & 29 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 @@ -31,40 +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,
},
/// Returns a valid Address parsed from a String.
ParseBech32Address {
address: Bech32Address,
Expand Down
21 changes: 2 additions & 19 deletions bindings/core/src/method/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use std::path::PathBuf;

use crypto::keys::bip44::Bip44;
use derivative::Derivative;
use iota_sdk::client::api::options::TransactionOptions;
#[cfg(feature = "events")]
use iota_sdk::wallet::events::types::{WalletEvent, WalletEventType};
use iota_sdk::{client::api::options::TransactionOptions, utils::serde::string};
// #[cfg(feature = "participation")]
// use iota_sdk::{
// client::node_manager::node::Node,
Expand All @@ -19,10 +19,9 @@ use iota_sdk::{
client::{
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,
},
Expand Down Expand Up @@ -456,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
13 changes: 1 addition & 12 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,21 +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::ComputeMinimumOutputAmount { output } => {
let storage_score_params = client.get_storage_score_parameters().await?;

Expand Down
12 changes: 1 addition & 11 deletions bindings/core/src/method_handler/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crypto::{
keys::bip39::Mnemonic,
};
use iota_sdk::{
client::{hex_to_bech32, verify_mnemonic, Client},
client::{verify_mnemonic, Client},
types::{
block::{
address::{AccountAddress, Address, ToBech32Ext},
Expand All @@ -27,17 +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::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 Down
22 changes: 1 addition & 21 deletions bindings/core/src/method_handler/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use std::time::Duration;
use crypto::signatures::ed25519::PublicKey;
use iota_sdk::{
client::api::{PreparedTransactionData, SignedTransactionData, SignedTransactionDataDto},
types::{
block::{address::ToBech32Ext, output::feature::BlockIssuerKeySource},
TryFromDto,
},
types::{block::output::feature::BlockIssuerKeySource, TryFromDto},
wallet::{types::TransactionWithMetadataDto, Wallet},
};

Expand Down Expand Up @@ -73,23 +70,6 @@ pub(crate) async fn call_wallet_method_internal(
let ledger_nano_status = wallet.get_ledger_nano_status().await?;
Response::LedgerNanoStatus(ledger_nano_status)
}
WalletMethod::GenerateEd25519Address {
account_index,
address_index,
options,
bech32_hrp,
} => {
let address = wallet
.generate_ed25519_address(account_index, address_index, options)
.await?;

let bech32_hrp = match bech32_hrp {
Some(bech32_hrp) => bech32_hrp,
None => *wallet.address().await.hrp(),
};

Response::Bech32Address(address.to_bech32(bech32_hrp))
}
#[cfg(feature = "stronghold")]
WalletMethod::SetStrongholdPassword { password } => {
wallet.set_stronghold_password(password).await?;
Expand Down
21 changes: 6 additions & 15 deletions bindings/core/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use iota_sdk::{
api::{
core::{
BlockMetadataResponse, BlockWithMetadataResponse, CommitteeResponse, CongestionResponse, InfoResponse,
IssuanceBlockHeaderResponse, ManaRewardsResponse, OutputResponse, OutputWithMetadataResponse,
RoutesResponse, TransactionMetadataResponse, UtxoChangesFullResponse, UtxoChangesResponse,
ValidatorResponse, ValidatorsResponse,
IssuanceBlockHeaderResponse, ManaRewardsResponse, NetworkMetricsResponse, OutputResponse,
OutputWithMetadataResponse, RoutesResponse, TransactionMetadataResponse, UtxoChangesFullResponse,
UtxoChangesResponse, ValidatorResponse, ValidatorsResponse,
},
plugins::indexer::OutputIdsResponse,
},
Expand Down Expand Up @@ -102,6 +102,9 @@ pub enum Response {
/// - [`GetNodeInfo`](crate::method::ClientMethod::GetNodeInfo)
NodeInfo(NodeInfoResponse),
/// Response for:
/// - [`GetNetworkMetrics`](crate::method::ClientMethod::GetNetworkMetrics)
NetworkMetrics(NetworkMetricsResponse),
/// Response for:
/// - [`GetRoutes`](crate::method::ClientMethod::GetRoutes)
Routes(RoutesResponse),
/// Response for:
Expand Down Expand Up @@ -198,9 +201,6 @@ pub enum Response {
/// [`OutputIdToUtxoInput`](crate::method::UtilsMethod::OutputIdToUtxoInput)
Input(UtxoInput),
/// Response for:
/// - [`Bech32ToHex`](crate::method::UtilsMethod::Bech32ToHex)
Bech32ToHex(String),
/// Response for:
/// - [`ParseBech32Address`](crate::method::UtilsMethod::ParseBech32Address)
ParsedBech32Address(Address),
/// Response for:
Expand All @@ -219,8 +219,6 @@ pub enum Response {
/// - [`Blake2b256Hash`](crate::method::UtilsMethod::Blake2b256Hash)
/// - [`TransactionSigningHash`](crate::method::UtilsMethod::TransactionSigningHash)
Hash(String),
/// Response for [`Bech32ToHex`](crate::method::UtilsMethod::Bech32ToHex)
HexAddress(String),
/// Response for [`OutputHexBytes`](crate::method::UtilsMethod::OutputHexBytes)
HexBytes(String),
/// Response for [`CallPluginRoute`](crate::method::ClientMethod::CallPluginRoute)
Expand All @@ -240,13 +238,6 @@ pub enum Response {
/// Response for:
/// - [`AddressToBech32`](crate::method::ClientMethod::AddressToBech32)
/// - [`AddressToBech32`](crate::method::UtilsMethod::AddressToBech32)
/// - [`AccountIdToBech32`](crate::method::ClientMethod::AccountIdToBech32)
/// - [`AccountIdToBech32`](crate::method::UtilsMethod::AccountIdToBech32)
/// - [`AnchorIdToBech32`](crate::method::ClientMethod::AnchorIdToBech32)
/// - [`AnchorIdToBech32`](crate::method::UtilsMethod::AnchorIdToBech32)
/// - [`NftIdToBech32`](crate::method::ClientMethod::NftIdToBech32)
/// - [`NftIdToBech32`](crate::method::UtilsMethod::NftIdToBech32)
/// - [`HexToBech32`](crate::method::ClientMethod::HexToBech32)
/// - [`ImplicitAccountCreationAddress`](crate::method::WalletMethod::ImplicitAccountCreationAddress)
Bech32Address(Bech32Address),
/// - [`Faucet`](crate::method::ClientMethod::RequestFundsFromFaucet)
Expand Down
2 changes: 1 addition & 1 deletion bindings/core/tests/serialize_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn custom_error_serialization() {
"type": "wallet",
"error": {
"type": "bipPathMismatch",
"error": "BIP44 mismatch: Some(Bip44 { coin_type: 4219, account: 0, change: 0, address_index: 0 }), existing bip path is: None"
"error": "bip path mismatch: Some(Bip44 { coin_type: 4219, account: 0, change: 0, address_index: 0 }), existing bip path is: None"
}
})
);
Expand Down
10 changes: 5 additions & 5 deletions bindings/core/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ async fn utils() -> Result<(), Box<dyn std::error::Error>> {

let bech32_address =
Bech32Address::try_from_str("rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy")?;
let method = UtilsMethod::Bech32ToHex {
bech32: bech32_address.clone(),
let method = UtilsMethod::ParseBech32Address {
address: bech32_address.clone(),
};

let response = call_utils_method(method);
match response {
Response::Bech32ToHex(hex) => {
match call_utils_method(UtilsMethod::HexToBech32 {
hex,
Response::ParsedBech32Address(address) => {
match call_utils_method(UtilsMethod::AddressToBech32 {
address,
bech32_hrp: Hrp::from_str_unchecked("rms"),
}) {
Response::Bech32Address(address_bech32) => {
Expand Down
Loading

0 comments on commit 6b812e1

Please sign in to comment.