Skip to content

Commit

Permalink
Merge branch '1.1' into nodejs-send-wrapper-methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Thoralf-M authored Aug 30, 2023
2 parents 83c0681 + 1be824f commit d2e2474
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bindings/core/src/method/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub enum AccountMethod {
/// Returns all pending transactions of the account
/// Expected response: [`Transactions`](crate::Response::Transactions)
PendingTransactions,
/// A generic `burn()` function that can be used to burn native tokens, nfts, foundries and aliases.
/// A generic function that can be used to burn native tokens, nfts, foundries and aliases.
///
/// Note that burning **native tokens** doesn't require the foundry output which minted them, but will not
/// increase the foundries `melted_tokens` field, which makes it impossible to destroy the foundry output.
Expand Down
3 changes: 1 addition & 2 deletions bindings/nodejs/lib/wallet/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,9 @@ export class Account {
}

/**
* A generic `burn()` function that can be used to prepare to burn native tokens, nfts, foundries and aliases.
* A generic function that can be used to prepare to burn native tokens, nfts, foundries and aliases.
* @param burn The outputs or native tokens to burn
* @param transactionOptions Additional transaction options
* or custom inputs.
* @returns The prepared transaction.
*/
async prepareBurn(
Expand Down
1 change: 1 addition & 0 deletions bindings/python/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- `ConflictReason` display implementation with an explanation of the conflict;
- `Account::{burn(), consolidate_outputs(), create_alias_output(), create_native_token(), melt_native_token(), mint_native_token(), mint_nfts(), send_transaction(), send_native_tokens(), send_nft()}` methods;

## 1.0.1 - 2023-08-23

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
# Consolidate unspent outputs and print the consolidation transaction ID
# Set `force` to true to force the consolidation even though the
# `output_threshold` isn't reached.
transaction = account.prepare_consolidate_outputs(
ConsolidationParams(force=True)).send()
transaction = account.consolidate_outputs(ConsolidationParams(force=True))
print('Transaction sent: ', transaction.transactionId)

# Wait for the consolidation transaction to get confirmed
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/how_tos/alias/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"])

# Send transaction.
transaction = account.prepare_create_alias_output(None, None).send()
transaction = account.create_alias_output(None, None)
print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.blockId}')
3 changes: 2 additions & 1 deletion bindings/python/examples/how_tos/alias_wallet/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@

# Find first output unlockable by the alias address
query_parameters = NodeIndexerAPI.QueryParameters(alias_address)
transaction_input = wallet.get_client().basic_output_ids(query_parameters).items[0]
transaction_input = wallet.get_client(
).basic_output_ids(query_parameters).items[0]

params = [SendParams(
address='rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu',
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 @@ -25,7 +25,7 @@
# existing one.
if not balance.aliases:
# If we don't have an alias, we need to create one
transaction = account.prepare_create_alias_output(None, None).send()
transaction = account.create_alias_output(None, None)
print(f'Transaction sent: {transaction.transactionId}')

# Wait for transaction to get included
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/how_tos/native_tokens/melt.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
melt_amount = 10

# Send transaction.
transaction = account.prepare_melt_native_token(token_id, melt_amount).send()
transaction = account.melt_native_token(token_id, melt_amount)
print(f'Transaction sent: {transaction.transactionId}')

# Wait for transaction to get included
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/examples/how_tos/native_tokens/mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

mint_amount = 10

# Prepare and send transaction.
transaction = account.prepare_mint_native_token(token_id, mint_amount).send()
# Send transaction.
transaction = account.mint_native_token(token_id, mint_amount)
print(f'Transaction sent: {transaction.transactionId}')

# Wait for transaction to get included
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/how_tos/native_tokens/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
)],
)]

transaction = account.prepare_send_native_tokens(outputs, None).send()
transaction = account.send_native_tokens(outputs, None)
print(f'Transaction sent: {transaction.transactionId}')

# Wait for transaction to get included
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
)


prepared = account.prepare_mint_nfts([params])
transaction = prepared.send()
transaction = account.mint_nfts([params])

# Wait for transaction to get included
block_id = account.retry_transaction_until_included(transaction.transactionId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def get_immutable_metadata(index: int, collection_id: str) -> str:
chunk, nft_mint_params = nft_mint_params[:NUM_NFTS_MINTED_PER_TRANSACTION], nft_mint_params[NUM_NFTS_MINTED_PER_TRANSACTION:]
print(
f'Minting {len(chunk)} NFTs... ({NFT_COLLECTION_SIZE-len(nft_mint_params)}/{NFT_COLLECTION_SIZE})')
prepared = account.prepare_mint_nfts(chunk)
transaction = prepared.send()
transaction = account.mint_nfts(chunk)

# Wait for transaction to get included
block_id = account.retry_transaction_until_included(
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/how_tos/nfts/mint_nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@
immutableMetadata=utf8_to_hex("some immutable nft metadata"),
)]

transaction = account.prepare_mint_nfts(outputs).send()
transaction = account.mint_nfts(outputs)
print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.blockId}')
2 changes: 1 addition & 1 deletion bindings/python/examples/how_tos/nfts/send_nft.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
nftId=balance.nfts[0],
)]

transaction = account.prepare_send_nft(outputs).send()
transaction = account.send_nft(outputs)
print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.blockId}')
2 changes: 1 addition & 1 deletion bindings/python/examples/wallet/create_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"])

# Send transaction.
transaction = account.prepare_create_alias_output(None, None).send()
transaction = account.create_alias_output(None, None)
print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.blockId}')
66 changes: 66 additions & 0 deletions bindings/python/iota_sdk/wallet/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ def get_metadata(self) -> AccountMetadata:
return AccountMetadata(
self.meta["alias"], self.meta["coinType"], self.meta["index"])

def burn(
self, burn: Burn, options: Optional[TransactionOptions] = None) -> Transaction:
"""A generic function that can be used to burn native tokens, nfts, foundries and aliases.
"""
return self.prepare_burn(burn, options).send()

def prepare_burn(
self, burn: Burn, options: Optional[TransactionOptions] = None) -> PreparedTransaction:
"""A generic `prepare_burn()` function that can be used to prepare the burn of native tokens, nfts, foundries and aliases.
Expand Down Expand Up @@ -119,6 +125,12 @@ def prepare_burn_nft(self,
)
return PreparedTransaction(self, prepared)

def consolidate_outputs(
self, params: ConsolidationParams) -> Transaction:
"""Consolidate outputs.
"""
return self.prepare_consolidate_outputs(params).send()

def prepare_consolidate_outputs(
self, params: ConsolidationParams) -> PreparedTransaction:
"""Consolidate outputs.
Expand All @@ -130,6 +142,13 @@ def prepare_consolidate_outputs(
)
return PreparedTransaction(self, prepared)

def create_alias_output(self,
params: Optional[CreateAliasOutputParams] = None,
options: Optional[TransactionOptions] = None) -> Transaction:
"""Create an alias output.
"""
return self.prepare_create_alias_output(params, options).send()

def prepare_create_alias_output(self,
params: Optional[CreateAliasOutputParams] = None,
options: Optional[TransactionOptions] = None) -> PreparedTransaction:
Expand Down Expand Up @@ -272,6 +291,12 @@ def pending_transactions(self):
)
return [Transaction.from_dict(tx) for tx in transactions]

def create_native_token(self, params: CreateNativeTokenParams,
options: Optional[TransactionOptions] = None) -> Transaction:
"""Create native token.
"""
return self.prepare_create_native_token(params, options).send()

def prepare_create_native_token(self, params: CreateNativeTokenParams,
options: Optional[TransactionOptions] = None) -> PreparedTransaction:
"""Create native token.
Expand All @@ -285,6 +310,16 @@ def prepare_create_native_token(self, params: CreateNativeTokenParams,
return PreparedCreateTokenTransaction(
account=self, prepared_transaction_data=prepared)

def melt_native_token(self,
token_id: HexStr,
melt_amount: int,
options: Optional[TransactionOptions] = None) -> Transaction:
"""Melt native tokens. This happens with the foundry output which minted them, by increasing it's
`melted_tokens` field.
"""
return self.prepare_melt_native_token(
token_id, melt_amount, options).send()

def prepare_melt_native_token(self,
token_id: HexStr,
melt_amount: int,
Expand All @@ -301,6 +336,13 @@ def prepare_melt_native_token(self,
)
return PreparedTransaction(self, prepared)

def mint_native_token(self, token_id: HexStr, mint_amount: int,
options: Optional[TransactionOptions] = None) -> Transaction:
"""Mint additional native tokens.
"""
return self.prepare_mint_native_token(
token_id, mint_amount, options).send()

def prepare_mint_native_token(self, token_id: HexStr, mint_amount: int,
options: Optional[TransactionOptions] = None) -> PreparedTransaction:
"""Mint additional native tokens.
Expand All @@ -314,6 +356,12 @@ def prepare_mint_native_token(self, token_id: HexStr, mint_amount: int,
)
return PreparedTransaction(self, prepared)

def mint_nfts(self, params: List[MintNftParams],
options: Optional[TransactionOptions] = None) -> Transaction:
"""Mint NFTs.
"""
return self.prepare_mint_nfts(params, options).send()

def prepare_mint_nfts(self, params: List[MintNftParams],
options: Optional[TransactionOptions] = None) -> PreparedTransaction:
"""Mint NFTs.
Expand Down Expand Up @@ -361,6 +409,12 @@ def prepare_send(self, params: List[SendParams],
)
return PreparedTransaction(self, prepared)

def send_transaction(
self, outputs: List[Output], options: Optional[TransactionOptions] = None) -> Transaction:
"""Send a transaction.
"""
return self.prepare_transaction(outputs, options).send()

def prepare_transaction(
self, outputs: List[Output], options: Optional[TransactionOptions] = None) -> PreparedTransaction:
"""Prepare transaction.
Expand Down Expand Up @@ -420,6 +474,12 @@ def send_with_params(
}
))

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

def prepare_send_native_tokens(
self, params: List[SendNativeTokensParams], options: Optional[TransactionOptions] = None) -> PreparedTransaction:
"""Send native tokens.
Expand All @@ -432,6 +492,12 @@ def prepare_send_native_tokens(
)
return PreparedTransaction(self, prepared)

def send_nft(self, params: List[SendNftParams],
options: Optional[TransactionOptions] = None) -> Transaction:
"""Send nft.
"""
return self.prepare_send_nft(params, options).send()

def prepare_send_nft(self, params: List[SendNftParams],
options: Optional[TransactionOptions] = None) -> PreparedTransaction:
"""Send nft.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
pub(crate) mod melt_native_token;

impl Account {
/// A generic `burn()` function that can be used to burn native tokens, nfts, foundries and aliases.
/// A generic function that can be used to burn native tokens, nfts, foundries and aliases.
///
/// Note that burning **native tokens** doesn't require the foundry output which minted them, but will not increase
/// the foundries `melted_tokens` field, which makes it impossible to destroy the foundry output. Therefore it's
Expand Down

0 comments on commit d2e2474

Please sign in to comment.