Skip to content

Commit

Permalink
Merge branch '2.0' into ledger-nano-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Feb 8, 2024
2 parents 41898ea + d9d50f3 commit a018ac3
Show file tree
Hide file tree
Showing 40 changed files with 857 additions and 79 deletions.
48 changes: 43 additions & 5 deletions bindings/core/src/method/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::path::PathBuf;

use crypto::keys::bip44::Bip44;
use derivative::Derivative;
use iota_sdk::utils::serde::string;
#[cfg(feature = "events")]
use iota_sdk::wallet::events::types::{WalletEvent, WalletEventType};
// #[cfg(feature = "participation")]
Expand All @@ -22,13 +23,13 @@ use iota_sdk::{
},
types::block::{
address::{Bech32Address, Hrp},
output::{DelegationId, Output, OutputId, TokenId},
output::{AccountId, DelegationId, Output, OutputId, TokenId},
payload::signed_transaction::TransactionId,
},
wallet::{
ClientOptions, ConsolidationParams, CreateAccountParams, CreateDelegationParams, CreateNativeTokenParams,
FilterOptions, MintNftParams, OutputParams, OutputsToClaim, SendNativeTokenParams, SendNftParams, SendParams,
SyncOptions, TransactionOptions,
BeginStakingParams, ClientOptions, ConsolidationParams, CreateAccountParams, CreateDelegationParams,
CreateNativeTokenParams, FilterOptions, MintNftParams, OutputParams, OutputsToClaim, SendNativeTokenParams,
SendNftParams, SendParams, SyncOptions, TransactionOptions,
},
U256,
};
Expand Down Expand Up @@ -224,6 +225,7 @@ pub enum WalletMethod {
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
PrepareBurn {
burn: Burn,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Claim outputs.
Expand All @@ -237,13 +239,15 @@ pub enum WalletMethod {
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
PrepareCreateAccountOutput {
params: Option<CreateAccountParams>,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Prepare to create a native token.
/// Expected response:
/// [`PreparedCreateNativeTokenTransaction`](crate::Response::PreparedCreateNativeTokenTransaction)
PrepareCreateNativeToken {
params: CreateNativeTokenParams,
#[serde(default)]
options: Option<TransactionOptions>,
},
// /// Reduces a wallet's "voting power" by a given amount.
Expand Down Expand Up @@ -275,6 +279,7 @@ pub enum WalletMethod {
token_id: TokenId,
/// To be melted amount
melt_amount: U256,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Prepare to mint additional native tokens.
Expand All @@ -285,44 +290,51 @@ pub enum WalletMethod {
token_id: TokenId,
/// To be minted amount
mint_amount: U256,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Prepare to mint NFTs.
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
PrepareMintNfts {
params: Vec<MintNftParams>,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Prepare an output.
/// Expected response: [`Output`](crate::Response::Output)
#[serde(rename_all = "camelCase")]
PrepareOutput {
params: Box<OutputParams>,
#[serde(default)]
transaction_options: Option<TransactionOptions>,
},
/// Prepare to send base coins.
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
PrepareSend {
params: Vec<SendParams>,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Prepare to send native tokens.
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
PrepareSendNativeTokens {
params: Vec<SendNativeTokenParams>,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Prepare to Send nft.
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
PrepareSendNft {
params: Vec<SendNftParams>,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Prepare to create a delegation.
/// Expected response:
/// [`PreparedCreateDelegationTransaction`](crate::Response::PreparedCreateDelegationTransaction)
PrepareCreateDelegation {
params: CreateDelegationParams,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Prepare to delay a delegation's claiming.
Expand All @@ -332,6 +344,28 @@ pub enum WalletMethod {
delegation_id: DelegationId,
reclaim_excess: bool,
},
/// Prepare to begin staking.
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
PrepareBeginStaking {
params: BeginStakingParams,
#[serde(default)]
options: Option<TransactionOptions>,
},
/// Prepare to extend staking.
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
#[serde(rename_all = "camelCase")]
PrepareExtendStaking {
account_id: AccountId,
additional_epochs: u32,
},
/// Prepare to end staking.
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
#[serde(rename_all = "camelCase")]
PrepareEndStaking { account_id: AccountId },
/// Announce candidacy for an account.
/// Expected response: [`BlockId`](crate::Response::BlockId)
#[serde(rename_all = "camelCase")]
AnnounceCandidacy { account_id: AccountId },
// /// Stop participating for an event.
// /// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
// #[cfg(feature = "participation")]
Expand All @@ -342,6 +376,7 @@ pub enum WalletMethod {
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
PrepareTransaction {
outputs: Vec<Output>,
#[serde(default)]
options: Option<TransactionOptions>,
},
// /// Vote for a participation event.
Expand Down Expand Up @@ -377,21 +412,24 @@ pub enum WalletMethod {
/// Send base coins.
/// Expected response: [`SentTransaction`](crate::Response::SentTransaction)
Send {
#[serde(with = "iota_sdk::utils::serde::string")]
#[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.
Expand Down
18 changes: 18 additions & 0 deletions bindings/core/src/method_handler/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,24 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
.await?;
Response::PreparedTransaction(data)
}
WalletMethod::PrepareBeginStaking { params, options } => {
let data = wallet.prepare_begin_staking(params, options).await?;
Response::PreparedTransaction(data)
}
WalletMethod::PrepareExtendStaking {
account_id,
additional_epochs,
} => {
let data = wallet.prepare_extend_staking(account_id, additional_epochs).await?;
Response::PreparedTransaction(data)
}
WalletMethod::PrepareEndStaking { account_id } => {
let data = wallet.prepare_end_staking(account_id).await?;
Response::PreparedTransaction(data)
}
WalletMethod::AnnounceCandidacy { account_id } => {
Response::BlockId(wallet.announce_candidacy(account_id).await?)
}
// #[cfg(feature = "participation")]
// WalletMethod::PrepareStopParticipating { event_id } => {
// let data = wallet.prepare_stop_participating(event_id).await?;
Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/lib/types/block/output/feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from './block-issuer-key';
import { u256, u64 } from '../../utils/type-aliases';
import { EpochIndex } from '../../block/slot';
import { INativeToken } from '../../models/native-token';
import { NativeToken } from '../../models/native-token';
import { HexEncodedString } from '../../utils/hex-encoding';

/**
Expand Down Expand Up @@ -132,7 +132,7 @@ class NativeTokenFeature extends Feature {
* Creates a new `NativeTokenFeature`.
* @param nativeToken The native token stored with the feature.
*/
constructor(nativeToken: INativeToken) {
constructor(nativeToken: NativeToken) {
super(FeatureType.NativeToken);
this.id = nativeToken.id;
this.amount = nativeToken.amount;
Expand All @@ -141,7 +141,7 @@ class NativeTokenFeature extends Feature {
/**
* Returns the native token contained in this feature.
*/
public asNativeToken(): INativeToken {
public asNativeToken(): NativeToken {
return {
id: this.id,
amount: this.amount,
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/lib/types/block/output/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { HexEncodedString, NumericString, u64 } from '../../utils';
import { TokenScheme, TokenSchemeDiscriminator } from './token-scheme';
import { AccountId, NftId, AnchorId, DelegationId } from '../id';
import { EpochIndex } from '../../block/slot';
import { INativeToken } from '../../models/native-token';
import { NativeToken } from '../../models/native-token';

export type OutputId = HexEncodedString;

Expand Down Expand Up @@ -127,7 +127,7 @@ abstract class CommonOutput extends Output {
/**
* The native token held by the output.
*/
getNativeToken(): INativeToken | undefined {
getNativeToken(): NativeToken | undefined {
if (!this.features) {
return undefined;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import {
UnlockCondition,
Feature,
INativeToken,
NativeToken,
NumericString,
u64,
} from '../..';
Expand All @@ -20,7 +20,7 @@ export interface BasicOutputBuilderParams {
/**
* The native tokens to be held by the output.
*/
nativeTokens?: INativeToken[];
nativeTokens?: NativeToken[];
/**
* The unlock conditions for the output.
*/
Expand Down
2 changes: 1 addition & 1 deletion bindings/nodejs/lib/types/models/native-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { hexToBigInt } from '../utils/hex-encoding';
/**
* Native token.
*/
export class INativeToken {
export class NativeToken {
/**
* Identifier of the native token.
*/
Expand Down
8 changes: 8 additions & 0 deletions bindings/nodejs/lib/types/wallet/bridge/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {
__AnnounceCandidacyMethod__,
__PrepareBurnMethod__,
__PrepareClaimOutputsMethod__,
__ClaimOutputsMethod__,
Expand Down Expand Up @@ -27,6 +28,9 @@ import type {
__PrepareSendMethod__,
__PrepareCreateDelegationMethod__,
__PrepareDelayDelegationClaimingMethod__,
__PrepareBeginStakingMethod__,
__PrepareExtendStakingMethod__,
__PrepareEndStakingMethod__,
__PrepareTransactionMethod__,
__RegisterParticipationEventsMethod__,
__ReissueTransactionUntilIncludedMethod__,
Expand Down Expand Up @@ -71,6 +75,7 @@ import type {
} from './wallet';

export type __WalletMethod__ =
| __AnnounceCandidacyMethod__
| __PrepareBurnMethod__
| __ClaimOutputsMethod__
| __PrepareClaimOutputsMethod__
Expand Down Expand Up @@ -104,6 +109,9 @@ export type __WalletMethod__ =
| __PrepareSendMethod__
| __PrepareCreateDelegationMethod__
| __PrepareDelayDelegationClaimingMethod__
| __PrepareBeginStakingMethod__
| __PrepareExtendStakingMethod__
| __PrepareEndStakingMethod__
| __PrepareTransactionMethod__
| __RegisterParticipationEventsMethod__
| __ReissueTransactionUntilIncludedMethod__
Expand Down
32 changes: 32 additions & 0 deletions bindings/nodejs/lib/types/wallet/bridge/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import type {
TransactionOptions,
MintNftParams,
CreateDelegationParams,
BeginStakingParams,
} from '../transaction-options';
import type {
ParticipationEventId,
Expand All @@ -29,6 +30,7 @@ import type {
} from '../participation';
import type { ConsolidationParams } from '../consolidation-params';
import {
AccountId,
DelegationId,
HexEncodedAmount,
NumericString,
Expand All @@ -42,6 +44,13 @@ export type __AccountsMethod__ = {
name: 'accounts';
};

export type __AnnounceCandidacyMethod__ = {
name: 'announceCandidacy';
data: {
accountId: AccountId;
};
};

export type __BackupMethod__ = {
name: 'backup';
data: {
Expand Down Expand Up @@ -193,6 +202,29 @@ export type __PrepareDelayDelegationClaimingMethod__ = {
};
};

export type __PrepareBeginStakingMethod__ = {
name: 'prepareBeginStaking';
data: {
params: BeginStakingParams;
options?: TransactionOptions;
};
};

export type __PrepareExtendStakingMethod__ = {
name: 'prepareExtendStaking';
data: {
accountId: AccountId;
additionalEpochs: number;
};
};

export type __PrepareEndStakingMethod__ = {
name: 'prepareEndStaking';
data: {
accountId: AccountId;
};
};

export type __DeregisterParticipationEventMethod__ = {
name: 'deregisterParticipationEvent';
data: {
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/lib/types/wallet/output-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { SlotIndex } from '../block/slot';
import { INativeToken } from '../models';
import { NativeToken } from '../models';
import { u64 } from '../utils';
import { HexEncodedString } from '../utils/hex-encoding';

Expand Down Expand Up @@ -39,7 +39,7 @@ export interface Features {
/** An Issuer feature to include. */
issuer?: string;
/** Native Token to include. */
nativeToken?: INativeToken;
nativeToken?: NativeToken;
}

/** Time unlocks to include in the output. */
Expand Down
Loading

0 comments on commit a018ac3

Please sign in to comment.