Skip to content

Commit

Permalink
Merge branch '2.0' into feat/better-transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
DaughterOfMars authored Mar 20, 2024
2 parents cacd339 + b4fca53 commit 7caddf4
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 29 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
8 changes: 6 additions & 2 deletions sdk/src/wallet/operations/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl<S: 'static + SecretManage> Wallet<S> {

let mut balance = Balance::default();
let mut total_storage_cost = 0;
let mut locked_amount = 0;
let mut total_native_tokens = NativeTokensBuilder::default();

#[cfg(feature = "participation")]
Expand Down Expand Up @@ -110,6 +111,7 @@ impl<S: 'static + SecretManage> Wallet<S> {
Output::Delegation(delegation) => {
// Add amount
balance.base_coin.total += delegation.amount();
locked_amount += delegation.amount();
// Add mana rewards
reward_outputs.insert(*output_id);
// Add storage deposit
Expand All @@ -124,7 +126,7 @@ impl<S: 'static + SecretManage> Wallet<S> {
_ => {
// If there is only an [AddressUnlockCondition], then we can spend the output at any time
// without restrictions
if let [UnlockCondition::Address(_)] = output.unlock_conditions().as_ref() {
if let [UnlockCondition::Address(address_unlock_cond)] = output.unlock_conditions().as_ref() {
// add nft_id for nft outputs
if let Output::Nft(nft) = &output {
let nft_id = nft.nft_id_non_null(output_id);
Expand All @@ -133,6 +135,9 @@ impl<S: 'static + SecretManage> Wallet<S> {

// Add amount
balance.base_coin.total += output.amount();
if address_unlock_cond.address().is_implicit_account_creation() {
locked_amount += output.amount();
}
// Add decayed mana
balance.mana.total += output.decayed_mana(
&protocol_parameters,
Expand Down Expand Up @@ -253,7 +258,6 @@ impl<S: 'static + SecretManage> Wallet<S> {
// for `available` get locked_outputs, sum outputs amount and subtract from total_amount
log::debug!("[BALANCE] locked outputs: {:#?}", wallet_ledger.locked_outputs);

let mut locked_amount = 0;
let mut locked_mana = DecayedMana::default();
let mut locked_native_tokens = NativeTokensBuilder::default();

Expand Down

0 comments on commit 7caddf4

Please sign in to comment.