Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native token refactoring #1364

Merged
merged 63 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
ce83b85
Add NativeTokenFeature
thibault-martinez Oct 1, 2023
2ae1ac1
Remove NativeTokens from Account
thibault-martinez Oct 1, 2023
2230942
Remove Native Token from NFT
thibault-martinez Oct 1, 2023
374d5a2
Fix warnings
thibault-martinez Oct 1, 2023
3e34c24
Add rand_native_token_feature
thibault-martinez Oct 1, 2023
4c3e879
Add to ALLOWED_FEATURES
thibault-martinez Oct 1, 2023
c3df687
Remove native tokens from Basic/Foundry
thibault-martinez Oct 1, 2023
67cb9e9
Fix semantic validation
thibault-martinez Oct 1, 2023
f93094b
Fix balance
thibault-martinez Oct 1, 2023
3e9aca1
Fix prepare_output
thibault-martinez Oct 1, 2023
387d91d
Change feature order
thibault-martinez Oct 2, 2023
283cd49
Some fixes
thibault-martinez Oct 2, 2023
4e3db0a
Some more changes
thibault-martinez Oct 2, 2023
2aaf0a5
Lift transaction max native token count
thibault-martinez Oct 2, 2023
3666fdd
Some bindings changes
thibault-martinez Oct 2, 2023
1e68d87
Merge branch '2.0' into native-token-feature
thibault-martinez Oct 2, 2023
d094379
Merge branch '2.0' into native-token-feature
thibault-martinez Oct 4, 2023
8e196b5
Merge branch '2.0' into native-token-feature
thibault-martinez Oct 5, 2023
16ca78e
Merge branch '2.0' into native-token-feature
thibault-martinez Oct 16, 2023
cc54f8a
Fix
thibault-martinez Oct 16, 2023
7bba80d
Some fixes
thibault-martinez Oct 16, 2023
faf1d3f
Merge branch '2.0' into native-token-feature
thibault-martinez Oct 19, 2023
1c7e242
Merge branch '2.0' into native-token-feature
thibault-martinez Oct 20, 2023
5411ddd
Merge branch '2.0' into native-token-feature
thibault-martinez Oct 24, 2023
9d5ebd3
Merge branch '2.0' into native-token-feature
thibault-martinez Oct 26, 2023
6e2356f
Merge branch '2.0' into native-token-feature
thibault-martinez Oct 30, 2023
7b239dd
Merge branch '2.0' into native-token-feature
thibault-martinez Oct 30, 2023
f458797
Merge branch '2.0' into native-token-feature
thibault-martinez Nov 16, 2023
0b24cec
Some fixes
thibault-martinez Nov 16, 2023
c1e988c
Fix balance
thibault-martinez Nov 16, 2023
b896a6c
Some more fixes
thibault-martinez Nov 16, 2023
0d454be
Comment ISA not supporting multiple remainders
thibault-martinez Nov 16, 2023
9d88e53
Comment unsupported native tokens in output consolidation
thibault-martinez Nov 16, 2023
7665cd6
Comment unsupported native tokens in output claiming
thibault-martinez Nov 16, 2023
fbd2fe3
More fixes
thibault-martinez Nov 16, 2023
ef44552
Fix CLI
thibault-martinez Nov 16, 2023
7b9298a
More changes - help :(
thibault-martinez Nov 16, 2023
fcbf7c9
Cleanup
thibault-martinez Nov 16, 2023
2e8db57
Fix bindings core
thibault-martinez Nov 16, 2023
edf76b0
Fix more tests
thibault-martinez Nov 16, 2023
b7ba5eb
moar
thibault-martinez Nov 16, 2023
3c47984
Disable some test files
thibault-martinez Nov 16, 2023
a8c9110
Fix last tests
thibault-martinez Nov 16, 2023
3dc57ea
Revert failed merged
thibault-martinez Nov 16, 2023
16b3971
Merge branch '2.0' into native-token-feature
thibault-martinez Nov 17, 2023
3d568c7
Remove StorageScore for NativeToken
thibault-martinez Nov 17, 2023
775565e
Revert rename
thibault-martinez Nov 17, 2023
96d4ddd
Bindings nits
thibault-martinez Nov 17, 2023
c713100
Add NativeTokenFeatureDto
thibault-martinez Nov 17, 2023
8ca7c91
Semantic nits
thibault-martinez Nov 17, 2023
d837504
Remove print
thibault-martinez Nov 17, 2023
6614eb3
Remove TODOs
thibault-martinez Nov 17, 2023
21fc7f3
Nit
thibault-martinez Nov 17, 2023
7cef116
Change Assets in bindings
thibault-martinez Nov 17, 2023
afdc589
#[serde(rename = "id")]
thibault-martinez Nov 17, 2023
03b31df
Update sdk/src/wallet/operations/transaction/prepare_transaction.rs
thibault-martinez Nov 17, 2023
2ceae42
Merge branch '2.0' into native-token-feature
thibault-martinez Nov 17, 2023
bccbee2
Merge branch '2.0' into native-token-feature
thibault-martinez Nov 17, 2023
8b2fa23
Merge branch '2.0' into native-token-feature
thibault-martinez Nov 17, 2023
abdd9bc
Merge branch '2.0' into native-token-feature
thibault-martinez Nov 17, 2023
ad96d8e
Merge branch '2.0' into native-token-feature
thibault-martinez Nov 20, 2023
1581b6f
Merge branch '2.0' into native-token-feature
thibault-martinez Nov 20, 2023
33e7151
Merge branch '2.0' into native-token-feature
thibault-martinez Nov 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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},
BlockId, IssuerId, SignedBlockDto,
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][];
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
/**
* 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,
Thoralf-M marked this conversation as resolved.
Show resolved Hide resolved
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
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 @@ -1318,7 +1318,7 @@ export class Wallet {
* @returns The transaction.
*/
async sendNativeTokens(
params: SendNativeTokensParams[],
params: SendNativeTokenParams[],
transactionOptions?: TransactionOptions,
): Promise<TransactionWithMetadata> {
return (
Expand All @@ -1335,7 +1335,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
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
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_tokens: 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_tokens: NativeToken
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
return_address: Optional[str] = None
expiration: Optional[int] = None

Expand Down
6 changes: 3 additions & 3 deletions bindings/python/iota_sdk/wallet/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from iota_sdk.types.output import BasicOutput, NftOutput, Output, deserialize_output
from iota_sdk.types.output_params import OutputParams
from iota_sdk.types.transaction_data import PreparedTransactionData, SignedTransactionData
from iota_sdk.types.send_params import CreateAccountOutputParams, CreateNativeTokenParams, MintNftParams, SendNativeTokensParams, SendNftParams, SendParams
from iota_sdk.types.send_params import CreateAccountOutputParams, CreateNativeTokenParams, MintNftParams, SendNativeTokenParams, SendNftParams, SendParams
from iota_sdk.types.transaction_with_metadata import TransactionWithMetadata
from iota_sdk.types.transaction_options import TransactionOptions
from iota_sdk.types.consolidation_params import ConsolidationParams
Expand Down Expand Up @@ -502,14 +502,14 @@ def send_with_params(
))

def send_native_tokens(
self, params: List[SendNativeTokensParams], options: Optional[TransactionOptions] = None) -> TransactionWithMetadata:
self, params: List[SendNativeTokenParams], options: Optional[TransactionOptions] = None) -> TransactionWithMetadata:
"""Send native tokens.
"""
return self.prepare_send_native_tokens(params, options).send()

def prepare_send_native_tokens(
self,
params: List[SendNativeTokensParams],
params: List[SendNativeTokenParams],
options: Optional[TransactionOptions] = None) -> PreparedTransaction:
"""Send native tokens.
"""
Expand Down
35 changes: 18 additions & 17 deletions cli/src/wallet_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use iota_sdk::{
utils::ConvertTo,
wallet::{
types::{OutputData, TransactionWithMetadata},
ConsolidationParams, CreateNativeTokenParams, MintNftParams, OutputsToClaim, SendNativeTokensParams,
ConsolidationParams, CreateNativeTokenParams, MintNftParams, OutputsToClaim, SendNativeTokenParams,
SendNftParams, SendParams, SyncOptions, TransactionOptions, Wallet,
},
U256,
Expand Down Expand Up @@ -194,7 +194,7 @@ pub enum WalletCommand {
#[arg(long, default_value_t = false)]
allow_micro_amount: bool,
},
/// Send native tokens.
/// Send a native token.
/// This will create an output with an expiration and storage deposit return unlock condition.
SendNativeToken {
/// Address to send the native tokens to, e.g. rms1qztwng6cty8cfm42nzvq099ev7udhrnk0rw8jt8vttf9kpqnxhpsx869vr3.
Expand Down Expand Up @@ -418,14 +418,15 @@ pub async fn claimable_outputs_command(wallet: &Wallet) -> Result<(), Error> {
};
println_log_info!("{output_id:?} ({kind})");

if let Some(native_tokens) = output.native_tokens() {
if !native_tokens.is_empty() {
println_log_info!(" - native token amount:");
native_tokens.iter().for_each(|token| {
println_log_info!(" + {} {}", token.amount(), token.token_id());
});
}
}
// TODO https://github.com/iotaledger/iota-sdk/issues/1633
// if let Some(native_tokens) = output.native_tokens() {
// if !native_tokens.is_empty() {
// println_log_info!(" - native token amount:");
// native_tokens.iter().for_each(|token| {
// println_log_info!(" + {} {}", token.amount(), token.token_id());
// });
// }
// }

if let Some(unlock_conditions) = output.unlock_conditions() {
let deposit_return = unlock_conditions
Expand Down Expand Up @@ -736,21 +737,21 @@ pub async fn send_native_token_command(

let outputs = [BasicOutputBuilder::new_with_minimum_amount(storage_params)
.add_unlock_condition(AddressUnlockCondition::new(address))
.with_native_tokens([NativeToken::new(
.with_native_token(NativeToken::new(
TokenId::from_str(&token_id)?,
U256::from_dec_str(&amount).map_err(|e| Error::Miscellaneous(e.to_string()))?,
)?])
)?)
.finish_output()?];

wallet.send_outputs(outputs, None).await?
} else {
// Send native tokens with storage deposit return and expiration
let outputs = [SendNativeTokensParams::new(
let outputs = [SendNativeTokenParams::new(
address,
[(
(
TokenId::from_str(&token_id)?,
U256::from_dec_str(&amount).map_err(|e| Error::Miscellaneous(e.to_string()))?,
)],
),
)?];
wallet.send_native_tokens(outputs, None).await?
};
Expand Down Expand Up @@ -952,8 +953,8 @@ async fn print_wallet_address(wallet: &Wallet) -> Result<(), Error> {
.required_and_unlocked_address(slot_index, &output_id)?;

if address.inner() == required_address {
if let Some(nts) = output_data.output.native_tokens() {
native_tokens.add_native_tokens(nts.clone())?;
if let Some(nt) = output_data.output.native_token() {
native_tokens.add_native_token(nt.clone())?;
}
match &output_data.output {
Output::Basic(_) => {}
Expand Down
Loading
Loading