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

Python: rename alias to account #1151

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions bindings/python/examples/client/build_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
hexAddress = Utils.bech32_to_hex(
'rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy')

alias_id = '0x0000000000000000000000000000000000000000000000000000000000000000'
account_id = '0x0000000000000000000000000000000000000000000000000000000000000000'
state_metadata = data = utf8_to_hex('Hello, World!')
unlock_conditions = [
StateControllerAddressUnlockCondition(Ed25519Address(hexAddress)),
Expand All @@ -28,14 +28,14 @@
MetadataFeature(utf8_to_hex('Hello, World!'))
]

# Build alias output
alias_output = client.build_alias_output(
alias_id=alias_id,
# Build account output
account_output = client.build_account_output(
account_id=account_id,
state_metadata=state_metadata,
unlock_conditions=unlock_conditions,
features=features,
immutable_features=immutable_features
)

# Print the output
print(json.dumps(alias_output.to_dict(), indent=4))
print(json.dumps(account_output.to_dict(), indent=4))
4 changes: 2 additions & 2 deletions bindings/python/examples/client/build_foundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
serial_number = 1
token_scheme = SimpleTokenScheme(32, 0, 64)
unlock_conditions = [
ImmutableAliasAddressUnlockCondition(
AliasAddress(
ImmutableAccountAddressUnlockCondition(
AccountAddress(
'0xa5c28d5baa951de05e375fb19134ea51a918f03acc2d0cee011a42b298d3effa')
)
]
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/exchange/1_create_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
account = wallet.create_account('Alice')

# Set sync_only_most_basic_outputs to True if not interested in outputs that are timelocked,
# have a storage deposit return, expiration or are nft/alias/foundry outputs.
# have a storage deposit return, expiration or are nft/account/foundry outputs.
account.set_default_sync_options(
SyncOptions(sync_only_most_basic_outputs=True))

Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/exchange/3_check_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
print(f'Addresses:', addresses)

# Set sync_only_most_basic_outputs to True if not interested in outputs that are timelocked,
# have a storage deposit return, expiration or are nft/alias/foundry outputs.
# have a storage deposit return, expiration or are nft/account/foundry outputs.
balance = account.sync(SyncOptions(sync_only_most_basic_outputs=True))
print('Balance', balance)

Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/exchange/4_listen_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ def callback(event):

# Sync to detect new outputs
# Set sync_only_most_basic_outputs to True if not interested in outputs that are timelocked,
# have a storage deposit return , expiration or are nft/alias/foundry
# have a storage deposit return , expiration or are nft/account/foundry
# outputs.
account.sync(SyncOptions(sync_only_most_basic_outputs=True))
2 changes: 1 addition & 1 deletion bindings/python/examples/exchange/5_send_amount.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"])

# Set sync_only_most_basic_outputs to True if not interested in outputs that are timelocked,
# have a storage deposit return, expiration or are nft/alias/foundry outputs.
# have a storage deposit return, expiration or are nft/account/foundry outputs.
balance = account.sync(SyncOptions(sync_only_most_basic_outputs=True))
print('Balance', balance)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

load_dotenv()

# In this example we will create an alias ouput
# In this example we will create an account output

wallet = Wallet(os.environ['WALLET_DB_PATH'])

Expand All @@ -19,5 +19,5 @@
wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"])

# Send transaction.
transaction = account.prepare_create_alias_output(None, None).send()
transaction = account.prepare_create_account_output(None, None).send()
print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.block_id}')
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

load_dotenv()

# In this example we will destroy an alias output
# In this example we will destroy an account output

wallet = Wallet(os.environ['WALLET_DB_PATH'])

Expand All @@ -13,14 +13,14 @@
# Sync account with the node
balance = account.sync()

# We try to destroy the first alias in the account
alias_id = balance.aliases[0]
# We try to destroy the first account in the account
account_id = balance.accounts[0]

if 'STRONGHOLD_PASSWORD' not in os.environ:
raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")

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

# Send transaction.
transaction = account.prepare_destroy_alias(alias_id).send()
transaction = account.prepare_destroy_account(account_id).send()
print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.block_id}')
38 changes: 38 additions & 0 deletions bindings/python/examples/how_tos/account_wallet/request_funds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from iota_sdk import Wallet, Utils, SyncOptions, AccountSyncOptions
from dotenv import load_dotenv
import os
import time

# In this example we request funds to an account wallet.
kwek20 marked this conversation as resolved.
Show resolved Hide resolved

load_dotenv()

FAUCET_URL = os.environ.get(
'FAUCET_URL', 'https://faucet.testnet.shimmer.network/api/enqueue')

wallet = Wallet(os.environ['WALLET_DB_PATH'])

account = wallet.get_account('Alice')
balance = account.sync(None)

total_base_token_balance = balance.base_coin.total
print(
f'Balance before requesting funds on account address: {total_base_token_balance}')

account_id = balance.accounts[0]
print(f'Account Id: {account_id}')

# Get Account address
account_address = Utils.account_id_to_bech32(
account_id, wallet.get_client().get_bech32_hrp())
faucet_response = wallet.get_client().request_funds_from_faucet(
FAUCET_URL, account_address)
print(faucet_response)

time.sleep(10)

sync_options = SyncOptions(alias=AccountSyncOptions(basic_outputs=True))

total_base_token_balance = account.sync(sync_options).base_coin.total
print(
f'Balance after requesting funds on account address: {total_base_token_balance}')
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from iota_sdk import Wallet, Utils, NodeIndexerAPI, SyncOptions, AliasSyncOptions, SendParams
from iota_sdk import Wallet, Utils, NodeIndexerAPI, SyncOptions, AccountSyncOptions, SendParams
from dotenv import load_dotenv
import os

# In this example we send funds from an alias wallet.
# In this example we send funds from an account wallet.

load_dotenv()

sync_options = SyncOptions(alias=AliasSyncOptions(basic_outputs=True))
sync_options = SyncOptions(alias=AccountSyncOptions(basic_outputs=True))

wallet = Wallet(os.environ['WALLET_DB_PATH'])

Expand All @@ -20,17 +20,17 @@
balance = account.sync(sync_options)

total_base_token_balance = balance.base_coin.total
print(f'Balance before sending funds from alias: {total_base_token_balance}')
print(f'Balance before sending funds from account: {total_base_token_balance}')

alias_id = balance.aliases[0]
print(f'Alias Id: {alias_id}')
account_id = balance.accounts[0]
print(f'Account Id: {account_id}')

# Get alias address
alias_address = Utils.alias_id_to_bech32(
alias_id, wallet.get_client().get_bech32_hrp())
# Get account address
account_address = Utils.account_id_to_bech32(
account_id, wallet.get_client().get_bech32_hrp())

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

params = [SendParams(
Expand All @@ -47,4 +47,4 @@
f'Transaction with custom input: https://explorer.shimmer.network/testnet/transaction/{transaction.transaction_id}')

total_base_token_balance = account.sync(sync_options).base_coin.total
print(f'Balance after sending funds from alias: {total_base_token_balance}')
print(f'Balance after sending funds from account: {total_base_token_balance}')
38 changes: 0 additions & 38 deletions bindings/python/examples/how_tos/alias_wallet/request_funds.py

This file was deleted.

10 changes: 5 additions & 5 deletions bindings/python/examples/how_tos/native_tokens/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
# Sync account with the node
balance = account.sync()

# We can first check if we already have an alias in our account, because
# an alias can have many foundry outputs and therefore we can reuse an
# We can first check if we already have an account output in our account, because
# an account can have many foundry outputs and therefore we can reuse an
# 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()
if not balance.accounts:
# If we don't have an account, we need to create one
transaction = account.prepare_create_account_output(None, None).send()
print(f'Transaction sent: {transaction.transaction_id}')

# Wait for transaction to get included
Expand Down
14 changes: 7 additions & 7 deletions bindings/python/examples/how_tos/outputs/unlock_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
hex_address = Utils.bech32_to_hex(
'rms1qpllaj0pyveqfkwxmnngz2c488hfdtmfrj3wfkgxtk4gtyrax0jaxzt70zy')

alias_hex_address = Utils.bech32_to_hex(
account_hex_address = Utils.bech32_to_hex(
'rms1pr59qm43mjtvhcajfmupqf23x29llam88yecn6pyul80rx099krmv2fnnux')

address_unlock_condition = AddressUnlockCondition(
Expand Down Expand Up @@ -58,8 +58,8 @@
outputs.append(basic_output)

# Output with governor and state controller unlock condition
alias_output = client.build_alias_output(
alias_id='0x0000000000000000000000000000000000000000000000000000000000000000',
account_output = client.build_account_output(
account_id='0x0000000000000000000000000000000000000000000000000000000000000000',
unlock_conditions=[
GovernorAddressUnlockCondition(
Ed25519Address(hex_address),
Expand All @@ -69,15 +69,15 @@
),
],
)
outputs.append(alias_output)
outputs.append(account_output)

# Output with immutable alias unlock condition
# Output with immutable account unlock condition
foundry_output = client.build_foundry_output(
serial_number=1,
token_scheme=token_scheme,
unlock_conditions=[
ImmutableAliasAddressUnlockCondition(
AliasAddress(alias_hex_address),
ImmutableAccountAddressUnlockCondition(
AccountAddress(account_hex_address),
),
],
)
Expand Down
4 changes: 2 additions & 2 deletions bindings/python/examples/wallet/create_alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

load_dotenv()

# In this example we will create an alias output
# In this example we will create an account output

wallet = Wallet(os.environ['WALLET_DB_PATH'])

Expand All @@ -19,5 +19,5 @@
wallet.set_stronghold_password(os.environ["STRONGHOLD_PASSWORD"])

# Send transaction.
transaction = account.prepare_create_alias_output(None, None).send()
transaction = account.prepare_create_account_output(None, None).send()
print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.block_id}')
2 changes: 1 addition & 1 deletion bindings/python/iota_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .utils import Utils
from .wallet.wallet import Wallet, Account
from .wallet.common import WalletError
from .wallet.sync_options import AccountSyncOptions, AliasSyncOptions, NftSyncOptions, SyncOptions
from .wallet.sync_options import AccountSyncOptions, AccountSyncOptions, NftSyncOptions, SyncOptions
from .secret_manager.secret_manager import *
from .prefix_hex import *
from .types.address import *
Expand Down
24 changes: 12 additions & 12 deletions bindings/python/iota_sdk/client/_node_indexer_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class QueryParameters:
**Attributes:**
address :
Bech32-encoded address that should be searched for.
alias_address :
Filter foundry outputs based on bech32-encoded address of the controlling alias.
account_address :
Filter foundry outputs based on bech32-encoded address of the controlling account.
created_after :
Returns outputs that were created after a certain Unix timestamp.
created_before :
Expand Down Expand Up @@ -69,7 +69,7 @@ class QueryParameters:
Returns outputs that are timelocked before a certain Unix timestamp.
"""
address: Optional[str] = None
alias_address: Optional[str] = None
account_address: Optional[str] = None
created_after: Optional[int] = None
created_before: Optional[int] = None
cursor: Optional[str] = None
Expand Down Expand Up @@ -122,29 +122,29 @@ def basic_output_ids(
})
return self.OutputIdsResponse(response)

def alias_output_ids(
def account_output_ids(
self, query_parameters: QueryParameters) -> OutputIdsResponse:
"""Fetch alias output IDs from the given query parameters.
"""Fetch account output IDs from the given query parameters.

Returns:
The corresponding output IDs of the alias outputs.
The corresponding output IDs of the account outputs.
"""

query_parameters_camelized = query_parameters.to_dict()

response = self._call_method('aliasOutputIds', {
response = self._call_method('accountOutputIds', {
'queryParameters': query_parameters_camelized,
})
return self.OutputIdsResponse(response)

def alias_output_id(self, alias_id: HexStr) -> OutputId:
"""Fetch alias output ID from the given alias ID.
def account_output_id(self, account_id: HexStr) -> OutputId:
"""Fetch account output ID from the given account ID.

Returns:
The output ID of the alias output.
The output ID of the account output.
"""
return OutputId.from_string(self._call_method('aliasOutputId', {
'aliasId': alias_id
return OutputId.from_string(self._call_method('accountOutputId', {
'accountId': account_id
}))

def nft_output_ids(
Expand Down
Loading
Loading