Skip to content

Commit

Permalink
Merge branch '2.0' into cli/improve-init-parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex6323 authored Mar 20, 2024
2 parents 94b1ce2 + b4fca53 commit 424c737
Show file tree
Hide file tree
Showing 32 changed files with 357 additions and 383 deletions.
2 changes: 1 addition & 1 deletion bindings/nodejs/examples/how_tos/native_tokens/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async function run() {
const params: CreateNativeTokenParams = {
circulatingSupply: CIRCULATING_SUPPLY,
maximumSupply: MAXIMUM_SUPPLY,
foundryMetadata: metadata.asHex(),
foundryMetadata: metadata.asFeature(),
};

const prepared = await wallet.prepareCreateNativeToken(params);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import {
MetadataFeature,
MintNftParams,
NftId,
NftOutput,
Expand Down Expand Up @@ -48,9 +49,11 @@ async function run() {
// Issue the minting transaction and wait for its inclusion
console.log(`Sending NFT minting transaction...`);
const params: MintNftParams = {
immutableMetadata: utf8ToHex(
'This NFT will be the issuer from the awesome NFT collection',
),
immutableMetadata: new MetadataFeature({
data: utf8ToHex(
'This NFT will be the issuer from the awesome NFT collection',
),
}),
};
const transaction = await wallet.mintNfts([params]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async function run() {
// Create the metadata with another index for each
for (let index = 0; index < NFT_COLLECTION_SIZE; index++) {
const params: MintNftParams = {
immutableMetadata: getImmutableMetadata(index).asHex(),
immutableMetadata: getImmutableMetadata(index).asFeature(),
// The NFT address from the NFT we minted in mint_issuer_nft example
issuer,
};
Expand Down
5 changes: 3 additions & 2 deletions bindings/nodejs/examples/how_tos/nfts/mint_nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Utils,
Wallet,
Irc27Metadata,
MetadataFeature,
} from '@iota/sdk';
require('dotenv').config({ path: '.env' });

Expand Down Expand Up @@ -64,10 +65,10 @@ async function run() {
const params: MintNftParams = {
address: NFT1_OWNER_ADDRESS, // Remove or change to senderAddress to send to self
sender: senderAddress,
metadata: NFT1_METADATA,
metadata: new MetadataFeature({ data: NFT1_METADATA }),
tag: NFT1_TAG,
issuer: senderAddress,
immutableMetadata: metadata.asHex(),
immutableMetadata: metadata.asFeature(),
};
let transaction = await wallet.mintNfts([params]);
console.log(`Transaction sent: ${transaction.transactionId}`);
Expand Down
13 changes: 7 additions & 6 deletions bindings/nodejs/lib/types/wallet/transaction-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
AccountId,
Address,
Bech32Address,
MetadataFeature,
OutputId,
} from '../block';
import { TaggedDataPayload } from '../block/payload/tagged';
Expand Down Expand Up @@ -62,8 +63,8 @@ export interface CreateNativeTokenParams {
circulatingSupply: u256;
/** Hex encoded number */
maximumSupply: u256;
/** Hex encoded bytes */
foundryMetadata?: HexEncodedString;
/** The metadata feature for the foundry output */
foundryMetadata?: MetadataFeature;
}

/** Options for minting NFTs. */
Expand All @@ -74,14 +75,14 @@ export interface MintNftParams {
address?: Bech32Address;
/** Bech32 encoded sender address **/
sender?: Bech32Address;
/** Hex encoded bytes */
metadata?: HexEncodedString;
/** Metadata feature */
metadata?: MetadataFeature;
/** Hex encoded bytes */
tag?: HexEncodedString;
/** Bech32 encoded issuer address **/
issuer?: Bech32Address;
/** Hex encoded bytes */
immutableMetadata?: HexEncodedString;
/** Immutable metadata feature */
immutableMetadata?: MetadataFeature;
}

/** Options for the account output creation */
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/how_tos/native_tokens/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
params = CreateNativeTokenParams(
100,
100,
metadata.as_hex(),
metadata.as_feature(),
)

prepared_transaction = wallet.prepare_create_native_token(params, None)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from dotenv import load_dotenv
from iota_sdk import MintNftParams, Utils, Wallet, WalletOptions, utf8_to_hex
from iota_sdk import MintNftParams, Utils, Wallet, WalletOptions, utf8_to_hex, MetadataFeature

load_dotenv()

Expand All @@ -20,8 +20,8 @@
# Issue the minting transaction and wait for its inclusion
print('Sending NFT minting transaction...')
params = MintNftParams(
immutable_metadata=utf8_to_hex(
"This NFT will be the issuer from the awesome NFT collection"),
immutable_metadata=MetadataFeature({'data': utf8_to_hex(
"This NFT will be the issuer from the awesome NFT collection")}),
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys

from dotenv import load_dotenv
from iota_sdk import HexStr, MintNftParams, NFTAddress, Utils, Wallet, WalletOptions, Irc27Metadata
from iota_sdk import HexStr, MintNftParams, NFTAddress, Utils, Wallet, WalletOptions, Irc27Metadata, MetadataFeature

load_dotenv()

Expand Down Expand Up @@ -32,7 +32,7 @@
issuer = Utils.address_to_bech32(NFTAddress(issuer_nft_id), bech32_hrp)


def get_immutable_metadata(index: int) -> str:
def get_immutable_metadata(index: int) -> MetadataFeature:
"""Returns the immutable metadata for the NFT with the given index"""
return Irc27Metadata(
"video/mp4",
Expand All @@ -41,7 +41,7 @@ def get_immutable_metadata(index: int) -> str:
description="The Shimmer OG NFT was handed out 1337 times by the IOTA Foundation to celebrate the official launch of the Shimmer Network.",
issuerName="IOTA Foundation",
collectionName="Shimmer OG",
).as_hex()
).as_feature()


# Create the metadata with another index for each
Expand Down
5 changes: 3 additions & 2 deletions bindings/python/examples/how_tos/nfts/mint_nft.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from dotenv import load_dotenv
from iota_sdk import MintNftParams, Wallet, WalletOptions, utf8_to_hex
from iota_sdk import MintNftParams, Wallet, WalletOptions, utf8_to_hex, MetadataFeature

# This example uses secrets in environment variables for simplicity which
# should not be done in production.
Expand All @@ -22,7 +22,8 @@
wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"])

outputs = [MintNftParams(
immutable_metadata=utf8_to_hex("some immutable nft metadata"),
immutable_metadata=MetadataFeature(
{'data': utf8_to_hex("some immutable nft metadata")}),
)]

transaction = wallet.mint_nfts(outputs)
Expand Down
11 changes: 6 additions & 5 deletions bindings/python/iota_sdk/types/send_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from dataclasses_json import config
from iota_sdk.types.address import AccountAddress
from iota_sdk.types.common import hex_str_decoder, HexStr, json
from iota_sdk.types.feature import MetadataFeature
from iota_sdk.types.native_token import NativeToken
from iota_sdk.types.output_params import ReturnStrategy

Expand Down Expand Up @@ -81,7 +82,7 @@ class CreateNativeTokenParams:
encoder=hex,
decoder=hex_str_decoder,
))
foundry_metadata: Optional[str] = None
foundry_metadata: Optional[MetadataFeature] = None
account_id: Optional[str] = None


Expand Down Expand Up @@ -134,10 +135,10 @@ class MintNftParams:
"""
address: Optional[str] = None
sender: Optional[str] = None
metadata: Optional[str] = None
metadata: Optional[MetadataFeature] = None
tag: Optional[str] = None
issuer: Optional[str] = None
immutable_metadata: Optional[str] = None
immutable_metadata: Optional[MetadataFeature] = None


@json
Expand All @@ -151,8 +152,8 @@ class CreateAccountOutputParams:
metadata: Account metadata.
"""
address: str
immutable_metadata: Optional[str] = None
metadata: Optional[str] = None
immutable_metadata: Optional[MetadataFeature] = None
metadata: Optional[MetadataFeature] = None


@json
Expand Down
41 changes: 19 additions & 22 deletions cli/src/wallet_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,25 +601,24 @@ pub async fn claimable_outputs_command(wallet: &Wallet) -> Result<(), Error> {
println_log_info!(" + {} {}", native_token.amount(), native_token.token_id());
}

if let Some(unlock_conditions) = output.unlock_conditions() {
let deposit_return = unlock_conditions
.storage_deposit_return()
.map(|deposit_return| deposit_return.amount())
.unwrap_or(0);
let amount = output.amount() - deposit_return;
println_log_info!(" - base coin amount: {}", amount);

if let Some(expiration) = unlock_conditions.expiration() {
let slot_index = wallet.client().get_slot_index().await?;

if *expiration.slot_index() > *slot_index {
println_log_info!(" - expires in {} slot indices", *expiration.slot_index() - *slot_index);
} else {
println_log_info!(
" - expired {} slot indices ago",
*slot_index - *expiration.slot_index()
);
}
let deposit_return = output
.unlock_conditions()
.storage_deposit_return()
.map(|deposit_return| deposit_return.amount())
.unwrap_or(0);
let amount = output.amount() - deposit_return;
println_log_info!(" - base coin amount: {}", amount);

if let Some(expiration) = output.unlock_conditions().expiration() {
let slot_index = wallet.client().get_slot_index().await?;

if *expiration.slot_index() > *slot_index {
println_log_info!(" - expires in {} slot indices", *expiration.slot_index() - *slot_index);
} else {
println_log_info!(
" - expired {} slot indices ago",
*slot_index - *expiration.slot_index()
);
}
}
}
Expand Down Expand Up @@ -1342,11 +1341,9 @@ async fn print_wallet_address(wallet: &Wallet) -> Result<(), Error> {
Output::Delegation(delegation) => delegations.push(delegation.delegation_id_non_null(&output_id)),
Output::Anchor(anchor) => anchors.push(anchor.anchor_id_non_null(&output_id)),
}
let unlock_conditions = output_data
let sdr_amount = output_data
.output
.unlock_conditions()
.expect("output must have unlock conditions");
let sdr_amount = unlock_conditions
.storage_deposit_return()
.map(|sdr| sdr.amount())
.unwrap_or(0);
Expand Down
17 changes: 7 additions & 10 deletions sdk/examples/wallet/17_check_unlock_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.add_unlock_condition(AddressUnlockCondition::new(wallet_address.clone()))
.finish_output()?;

let controlled_by_account = if let [UnlockCondition::Address(address_unlock_condition)] = output
.unlock_conditions()
.expect("output needs to have unlock conditions")
.as_ref()
{
// Check that the address in the unlock condition belongs to the wallet
wallet_address.inner() == address_unlock_condition.address()
} else {
false
};
let controlled_by_account =
if let [UnlockCondition::Address(address_unlock_condition)] = output.unlock_conditions().as_ref() {
// Check that the address in the unlock condition belongs to the wallet
wallet_address.inner() == address_unlock_condition.address()
} else {
false
};

println!(
"The output has only an address unlock condition and the address is from the account: {controlled_by_account:?}"
Expand Down
9 changes: 1 addition & 8 deletions sdk/examples/wallet/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
//! ```

use iota_sdk::{
client::{
api::GetAddressesOptions,
constants::SHIMMER_COIN_TYPE,
secret::{mnemonic::MnemonicSecretManager, SecretManager},
},
client::{constants::SHIMMER_COIN_TYPE, secret::mnemonic::MnemonicSecretManager},
crypto::keys::bip44::Bip44,
wallet::{ClientOptions, Wallet},
};
Expand All @@ -39,9 +35,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

// Restore a wallet
let client_options = ClientOptions::new().with_node(&std::env::var("NODE_URL").unwrap())?;
let secret_manager = SecretManager::Mnemonic(MnemonicSecretManager::try_from_mnemonic(
std::env::var("MNEMONIC").unwrap(),
)?);

let secret_manager = MnemonicSecretManager::try_from_mnemonic(std::env::var("MNEMONIC").unwrap())?;

Expand Down
5 changes: 1 addition & 4 deletions sdk/examples/wallet/offline_signing/1_prepare_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
//! ```

use iota_sdk::{
client::{
api::PreparedTransactionDataDto, constants::SHIMMER_COIN_TYPE, secret::SecretManager,
stronghold::StrongholdAdapter,
},
client::{api::PreparedTransactionDataDto, constants::SHIMMER_COIN_TYPE, secret::SecretManager},
crypto::keys::bip44::Bip44,
types::block::address::Bech32Address,
wallet::{ClientOptions, SendParams, Wallet},
Expand Down
8 changes: 2 additions & 6 deletions sdk/examples/wallet/spammer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,10 @@ use iota_sdk::{
client::{
constants::SHIMMER_COIN_TYPE,
request_funds_from_faucet,
secret::{mnemonic::MnemonicSecretManager, SecretManage, SecretManager},
secret::{mnemonic::MnemonicSecretManager, SecretManager},
},
crypto::keys::bip44::Bip44,
types::block::{
address::{Address, Bech32Address, Hrp},
output::BasicOutput,
payload::signed_transaction::TransactionId,
},
types::block::{address::Bech32Address, output::BasicOutput, payload::signed_transaction::TransactionId},
wallet::{ClientOptions, FilterOptions, SendParams, Wallet},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ impl TransactionBuilder {
if input
.output
.unlock_conditions()
.map_or(false, |u| u.iter().any(|u| u.is_timelock() || u.is_expiration()))
.iter()
.any(|u| u.is_timelock() || u.is_expiration())
{
log::debug!("Adding commitment context input for timelocked or expiring output");
needs_commitment_context = true;
Expand Down
Loading

0 comments on commit 424c737

Please sign in to comment.