Skip to content

Commit

Permalink
Native token refactoring (#1364)
Browse files Browse the repository at this point in the history
* Add NativeTokenFeature

* Remove NativeTokens from Account

* Remove Native Token from NFT

* Fix warnings

* Add rand_native_token_feature

* Add to ALLOWED_FEATURES

* Remove native tokens from Basic/Foundry

* Fix semantic validation

* Fix balance

* Fix prepare_output

* Change feature order

* Some fixes

* Some more changes

* Lift transaction max native token count

* Some bindings changes

* Fix

* Some fixes

* Some fixes

* Fix balance

* Some more fixes

* Comment ISA not supporting multiple remainders

* Comment unsupported native tokens in output consolidation

* Comment unsupported native tokens in output claiming

* More fixes

* Fix CLI

* More changes - help :(

* Cleanup

* Fix bindings core

* Fix more tests

* moar

* Disable some test files

* Fix last tests

* Revert failed merged

* Remove StorageScore for NativeToken

* Revert rename

* Bindings nits

* Add NativeTokenFeatureDto

* Semantic nits

* Remove print

* Remove TODOs

* Nit

* Change Assets in bindings

* #[serde(rename = "id")]

* Update sdk/src/wallet/operations/transaction/prepare_transaction.rs

Co-authored-by: Thoralf-M <[email protected]>

---------

Co-authored-by: Thoralf-M <[email protected]>
  • Loading branch information
thibault-martinez and Thoralf-M authored Nov 20, 2023
1 parent 5e9add1 commit 51d6e8e
Show file tree
Hide file tree
Showing 68 changed files with 549 additions and 1,186 deletions.
6 changes: 1 addition & 5 deletions bindings/core/src/method/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use iota_sdk::{
address::{Bech32Address, Hrp},
output::{
dto::OutputDto, feature::Feature, unlock_condition::dto::UnlockConditionDto, AccountId, AnchorId,
DelegationId, FoundryId, NativeToken, NftId, OutputId, TokenScheme,
DelegationId, FoundryId, NftId, OutputId, TokenScheme,
},
payload::{dto::PayloadDto, signed_transaction::TransactionId},
BlockDto, BlockId, IssuerId,
Expand All @@ -43,7 +43,6 @@ pub enum ClientMethod {
// TODO: Determine if `default` is wanted here
#[serde(default, with = "string")]
mana: u64,
native_tokens: Option<Vec<NativeToken>>,
account_id: AccountId,
foundry_counter: Option<u32>,
unlock_conditions: Vec<UnlockConditionDto>,
Expand All @@ -61,7 +60,6 @@ pub enum ClientMethod {
// TODO: Determine if `default` is wanted here
#[serde(default, with = "string")]
mana: u64,
native_tokens: Option<Vec<NativeToken>>,
unlock_conditions: Vec<UnlockConditionDto>,
features: Option<Vec<Feature>>,
},
Expand All @@ -73,7 +71,6 @@ pub enum ClientMethod {
// If not provided, minimum amount will be used
#[serde(default, with = "option_string")]
amount: Option<u64>,
native_tokens: Option<Vec<NativeToken>>,
serial_number: u32,
token_scheme: TokenScheme,
unlock_conditions: Vec<UnlockConditionDto>,
Expand All @@ -91,7 +88,6 @@ pub enum ClientMethod {
// TODO: Determine if `default` is wanted here
#[serde(default, with = "string")]
mana: u64,
native_tokens: Option<Vec<NativeToken>>,
nft_id: NftId,
unlock_conditions: Vec<UnlockConditionDto>,
features: Option<Vec<Feature>>,
Expand Down
4 changes: 2 additions & 2 deletions bindings/core/src/method/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use iota_sdk::{
},
wallet::{
ClientOptions, ConsolidationParams, CreateAccountParams, CreateNativeTokenParams, FilterOptions, MintNftParams,
OutputParams, OutputsToClaim, SendNativeTokensParams, SendNftParams, SendParams, SyncOptions,
OutputParams, OutputsToClaim, SendNativeTokenParams, SendNftParams, SendParams, SyncOptions,
TransactionOptions,
},
U256,
Expand Down Expand Up @@ -295,7 +295,7 @@ pub enum WalletMethod {
/// Prepare to send native tokens.
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
PrepareSendNativeTokens {
params: Vec<SendNativeTokensParams>,
params: Vec<SendNativeTokenParams>,
options: Option<TransactionOptions>,
},
/// Prepare to Send nft.
Expand Down
8 changes: 0 additions & 8 deletions bindings/core/src/method_handler/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
ClientMethod::BuildAccountOutput {
amount,
mana,
native_tokens,
account_id,
foundry_counter,
unlock_conditions,
Expand All @@ -73,7 +72,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
OutputBuilderAmount::MinimumAmount(client.get_storage_score_parameters().await?)
},
mana,
native_tokens,
&account_id,
foundry_counter,
unlock_conditions,
Expand All @@ -86,7 +84,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
ClientMethod::BuildBasicOutput {
amount,
mana,
native_tokens,
unlock_conditions,
features,
} => {
Expand All @@ -97,7 +94,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
OutputBuilderAmount::MinimumAmount(client.get_storage_score_parameters().await?)
},
mana,
native_tokens,
unlock_conditions,
features,
)?);
Expand All @@ -106,7 +102,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
}
ClientMethod::BuildFoundryOutput {
amount,
native_tokens,
serial_number,
token_scheme,
unlock_conditions,
Expand All @@ -119,7 +114,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
} else {
OutputBuilderAmount::MinimumAmount(client.get_storage_score_parameters().await?)
},
native_tokens,
serial_number,
token_scheme,
unlock_conditions,
Expand All @@ -132,7 +126,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
ClientMethod::BuildNftOutput {
amount,
mana,
native_tokens,
nft_id,
unlock_conditions,
features,
Expand All @@ -145,7 +138,6 @@ pub(crate) async fn call_client_method_internal(client: &Client, method: ClientM
OutputBuilderAmount::MinimumAmount(client.get_storage_score_parameters().await?)
},
mana,
native_tokens,
&nft_id,
unlock_conditions,
features,
Expand Down
10 changes: 5 additions & 5 deletions bindings/nodejs/examples/how_tos/native_tokens/send.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

import { SendNativeTokensParams } from '@iota/sdk';
import { SendNativeTokenParams } from '@iota/sdk';

import { getUnlockedWallet } from '../../wallet/common';

// The native token amount to send.
const SEND_NATIVE_TOKEN_AMOUNT = BigInt(10);
// The address to send the tokens to
// The address to send the token to
const RECV_ADDRESS =
'rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu';

// In this example we will send native tokens.
// In this example we will send a native token.
//
// Make sure that `STRONGHOLD_SNAPSHOT_PATH` and `WALLET_DB_PATH` already exist by
// running the `how_tos/accounts_and_addresses/create-wallet` example!
Expand All @@ -32,10 +32,10 @@ async function run() {
)?.tokenId;

if (tokenId != null) {
const outputs: SendNativeTokensParams[] = [
const outputs: SendNativeTokenParams[] = [
{
address: RECV_ADDRESS,
nativeTokens: [[tokenId, SEND_NATIVE_TOKEN_AMOUNT]],
nativeToken: [tokenId, SEND_NATIVE_TOKEN_AMOUNT],
},
];

Expand Down
8 changes: 4 additions & 4 deletions bindings/nodejs/lib/types/wallet/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ export interface SendParams {
expiration?: SlotIndex;
}

/** Address with native tokens */
export interface SendNativeTokensParams {
/** Address with native token */
export interface SendNativeTokenParams {
/** The Bech32 address. */
address: Bech32Address;
/** The Native Tokens to send. */
nativeTokens: [TokenId, u256][];
/** The Native Token to send. */
nativeToken: [TokenId, u256];
/**
* Bech32 encoded address, to which the storage deposit will be returned.
* Default will use the address of the wallet.
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/lib/types/wallet/bridge/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import type {
SendParams,
SendNativeTokensParams,
SendNativeTokenParams,
SendNftParams,
GenerateAddressOptions,
} from '../address';
Expand Down Expand Up @@ -258,7 +258,7 @@ export type __SendWithParamsMethod__ = {
export type __PrepareSendNativeTokensMethod__ = {
name: 'prepareSendNativeTokens';
data: {
params: SendNativeTokensParams[];
params: SendNativeTokenParams[];
options?: TransactionOptions;
};
};
Expand Down
4 changes: 2 additions & 2 deletions bindings/nodejs/lib/types/wallet/bridge/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
} from '../../client';
import type {
SendParams,
SendNativeTokensParams,
SendNativeTokenParams,
SendNftParams,
} from '../address';
import type { OutputParams } from '../output-params';
Expand Down Expand Up @@ -337,7 +337,7 @@ export type __SendWithParamsMethod__ = {
export type __PrepareSendNativeTokensMethod__ = {
name: 'prepareSendNativeTokens';
data: {
params: SendNativeTokensParams[];
params: SendNativeTokenParams[];
options?: TransactionOptions;
};
};
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 @@ -24,8 +24,6 @@ export interface OutputParams {

/** Assets to include in the output. */
export interface Assets {
/** Native Token assets to include. */
nativeTokens?: INativeToken[];
/** The NFT to include. */
nftId?: HexEncodedString;
}
Expand All @@ -40,6 +38,8 @@ export interface Features {
sender?: string;
/** An Issuer feature to include. */
issuer?: string;
/** Native Token to include. */
nativeToken?: INativeToken;
}

/** Time unlocks to include in the output. */
Expand Down
6 changes: 3 additions & 3 deletions bindings/nodejs/lib/wallet/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
Balance,
SyncOptions,
SendParams,
SendNativeTokensParams,
SendNativeTokenParams,
SendNftParams,
AccountOutputParams,
FilterOptions,
Expand Down Expand Up @@ -1325,7 +1325,7 @@ export class Wallet {
* @returns The transaction.
*/
async sendNativeTokens(
params: SendNativeTokensParams[],
params: SendNativeTokenParams[],
transactionOptions?: TransactionOptions,
): Promise<TransactionWithMetadata> {
return (
Expand All @@ -1342,7 +1342,7 @@ export class Wallet {
* @returns The prepared transaction.
*/
async prepareSendNativeTokens(
params: SendNativeTokensParams[],
params: SendNativeTokenParams[],
transactionOptions?: TransactionOptions,
): Promise<PreparedTransaction> {
const response = await this.methodHandler.callMethod({
Expand Down
24 changes: 1 addition & 23 deletions bindings/nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions bindings/nodejs/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2201,9 +2201,9 @@ fs.realpath@^1.0.0:
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==

fsevents@^2.3.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.3.tgz#cac6407785d03675a2a5e1a5305c697b347d90d6"
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==
version "2.3.2"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==

fstream@^1.0.0, fstream@~1.0.10:
version "1.0.12"
Expand Down
8 changes: 4 additions & 4 deletions bindings/python/examples/how_tos/native_tokens/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from dotenv import load_dotenv

from iota_sdk import SendNativeTokensParams, Wallet
from iota_sdk import SendNativeTokenParams, Wallet

load_dotenv()

Expand All @@ -24,12 +24,12 @@

wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"])

outputs = [SendNativeTokensParams(
outputs = [SendNativeTokenParams(
"rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu",
[(
(
token.token_id,
hex(10)
)],
),
)]

transaction = account.send_native_tokens(outputs, None)
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/iota_sdk/types/output_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
class Assets():
"""Assets for OutputParams.
"""
native_tokens: Optional[List[NativeToken]] = None
nft_id: Optional[HexStr] = None


Expand All @@ -28,6 +27,7 @@ class Features():
metadata: Optional[HexStr] = None
issuer: Optional[str] = None
sender: Optional[str] = None
native_token: Optional[NativeToken] = None


@json
Expand Down
12 changes: 6 additions & 6 deletions bindings/python/iota_sdk/types/send_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ class SendParams():

@json
@dataclass
class SendNativeTokensParams():
"""Parameters for sending native tokens
class SendNativeTokenParams():
"""Parameters for sending a native token
Attributes:
address: The address to send to.
native_tokens: The native tokens to send.
return_address: The address to return the native tokens to if not claimed.
expiration: The expiration timestamp until native tokens can be claimed.
native_token: The native token to send.
return_address: The address to return the native token to if not claimed.
expiration: The expiration timestamp until the native token can be claimed.
"""
address: str
native_tokens: List[NativeToken]
native_token: NativeToken
return_address: Optional[str] = None
expiration: Optional[int] = None

Expand Down
Loading

0 comments on commit 51d6e8e

Please sign in to comment.