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/single account #1757

Merged
merged 55 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
6b236d1
initial
Dec 5, 2023
d86385f
tests
Dec 6, 2023
ab831a3
sync options
Dec 6, 2023
7e7647b
Merge branch '2.0' into python/single-account
Dec 6, 2023
c3b93a4
init example replace
Dec 6, 2023
d2e3a84
examples lint fix
Dec 7, 2023
9a11da5
format
Dec 7, 2023
71ec713
prot params
Dec 7, 2023
2dce642
examples update
Dec 8, 2023
99c3016
Merge branch '2.0' into python/single-account
Dec 8, 2023
dd13c19
update comment
Dec 8, 2023
f754ffc
lint
Dec 8, 2023
1960a74
Merge branch '2.0' into python/single-account
Dec 11, 2023
bb97a04
added missing prot params
Dec 11, 2023
fc8f1f5
lint....
Dec 11, 2023
60aa91f
removed some account references
Dec 11, 2023
78e022b
fmt again
Dec 11, 2023
6bacf19
added protocol params to sign
Dec 11, 2023
fe73986
Merge branch '2.0' into python/single-account
Alex6323 Dec 12, 2023
3eac44d
fix, maybe lint?
Dec 12, 2023
a1af8c9
Merge branch '2.0' into python/single-account
Dec 12, 2023
3e95f28
Merge branch 'python/single-account' of https://github.com/kwek20/iot…
Dec 12, 2023
df02aad
rename fix
Dec 12, 2023
dff9e39
review
Dec 12, 2023
aa11a90
Merge branch '2.0' into python/single-account
Dec 12, 2023
49b1ccc
Merge branch '2.0' into python/single-account
thibault-martinez Dec 13, 2023
138c2b6
Merge branch '2.0' into python/single-account
Alex6323 Dec 13, 2023
0a8213e
some review remarks
Dec 13, 2023
c984ac5
Merge branch 'python/single-account' of https://github.com/kwek20/iot…
Dec 13, 2023
489986c
worded different
Dec 13, 2023
2f2b0fa
file rename
Dec 13, 2023
92be08f
Merge branch '2.0' into python/single-account
Dec 13, 2023
720d57c
fix
Dec 14, 2023
202fb2c
one more account removed
Dec 14, 2023
ec37154
its a str not a var u dummy
Dec 14, 2023
5206f88
one more timeee
Dec 14, 2023
1165ccc
Merge branch '2.0' into python/single-account
Thoralf-M Dec 14, 2023
84d5cb3
Merge branch '2.0' into python/single-account
Dec 14, 2023
e2bbe10
Merge branch '2.0' into python/single-account
Thoralf-M Dec 14, 2023
fc45b39
fix utils
Dec 14, 2023
1f60680
Merge branch 'python/single-account' of https://github.com/kwek20/iot…
Dec 14, 2023
3e1d46f
Merge branch '2.0' into python/single-account
Thoralf-M Dec 15, 2023
840df6c
Merge branch '2.0' into python/single-account
Dec 18, 2023
71618d6
Merge branch '2.0' into python/single-account
thibault-martinez Dec 18, 2023
313e79b
More rename
thibault-martinez Dec 18, 2023
525f5d3
More rename + fmt
thibault-martinez Dec 18, 2023
ddfff75
Merge branch '2.0' into python/single-account
Dec 19, 2023
f0f6223
Revert "examples update"
Dec 19, 2023
f3c4b4d
Merge branch 'python/single-account' of https://github.com/kwek20/iot…
Dec 19, 2023
7bcf247
revert part of revert again :D
Dec 20, 2023
4a22ef5
Merge branch '2.0' into python/single-account
Dec 20, 2023
aff8f3d
newline
Dec 20, 2023
e5ca713
Lint/fmt examples
thibault-martinez Dec 20, 2023
4315f0b
Remove root yarn.lock
thibault-martinez Dec 20, 2023
5da0344
SyncOptions wallet
thibault-martinez Dec 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
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ resolver = "2"
members = [
"bindings/core",
"bindings/nodejs",
# TODO: issue #1423
#"bindings/python",
"bindings/python",
"bindings/wasm",
"cli",
"sdk",
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ disable=missing-module-docstring,
fixme, # TODOS
too-many-instance-attributes,
too-many-arguments,
too-few-public-methods
too-few-public-methods,
too-many-public-methods,
too-many-locals

Expand Down
2 changes: 1 addition & 1 deletion bindings/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ The following example creates a Client instance connected to the Shimmer Testnet

## Wallet Usage

The following example will create a new Wallet Account using a StrongholdSecretManager, and then print the account's information.
The following example will create a new Wallet using a StrongholdSecretManager, and then print the wallet's information.

[examples/wallet/getting_started.py](examples/wallet/getting_started.py)

Expand Down
2 changes: 1 addition & 1 deletion bindings/python/examples/client/04_get_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

# Get an outputs by its id
output_with_metadata = client.get_output(
'0x022aefa73dff09b35b21ab5493412b0d354ad07a970a12b71e8087c6f3a7b8660000')
'0x022aefa73dff09b35b21ab5493412b0d354ad07a970a12b71e8087c6f3a7b866000000000000')
print(json.dumps(output_with_metadata.to_dict(), indent=4))
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from dotenv import load_dotenv

from iota_sdk import (ClientOptions, CoinType, StrongholdSecretManager,
SyncOptions, Wallet)
SecretManager, SyncOptions, Wallet, WalletOptions, Bip44)

# This example uses secrets in environment variables for simplicity which
# should not be done in production.
Expand All @@ -24,19 +24,21 @@
secret_manager = StrongholdSecretManager(
os.environ.get('STRONGHOLD_SNAPSHOT_PATH'), os.environ['STRONGHOLD_PASSWORD'])

wallet = Wallet(os.environ.get('WALLET_DB_PATH'),
client_options, CoinType.IOTA, secret_manager)

# Store the mnemonic in the Stronghold snapshot, this only needs to be
# done once.
wallet.store_mnemonic(
os.environ['MNEMONIC'])
SecretManager(secret_manager).store_mnemonic(os.environ['MNEMONIC'])

account = wallet.create_account('Alice')
bip_path = Bip44(
coin_type=CoinType.SHIMMER
)
wallet_options = WalletOptions(None, None, bip_path, client_options, secret_manager, os.environ.get('WALLET_DB_PATH'))
wallet = Wallet(wallet_options)

# 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/account/foundry outputs.
account.set_default_sync_options(
wallet.set_default_sync_options(
SyncOptions(sync_only_most_basic_outputs=True))

print(account.get_metadata())
# Update the wallet to the latest state
balance = wallet.sync()
print('Generated new wallet')
17 changes: 7 additions & 10 deletions bindings/python/examples/exchange/2_generate_address.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
# Copyright 2023 IOTA Stiftung
# SPDX-License-Identifier: Apache-2.0

# This example generates an address for an account.
# This example generates an address for a wallet.

import os

from dotenv import load_dotenv

from iota_sdk import Wallet
from iota_sdk import StrongholdSecretManager, SecretManager

# This example uses secrets in environment variables for simplicity which
# should not be done in production.
load_dotenv()

for env_var in ['WALLET_DB_PATH', 'STRONGHOLD_PASSWORD']:
for env_var in ['STRONGHOLD_SNAPSHOT_PATH', 'STRONGHOLD_PASSWORD']:
if env_var not in os.environ:
raise Exception(f'.env {env_var} is undefined, see .env.example')

wallet = Wallet(os.environ.get('WALLET_DB_PATH'))
secret_manager = SecretManager(StrongholdSecretManager(
os.environ.get('STRONGHOLD_SNAPSHOT_PATH'), os.environ['STRONGHOLD_PASSWORD']))

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

account = wallet.get_account('Alice')

address = account.generate_ed25519_addresses(1)[0]
print('Address:', address.address)
address = secret_manager.generate_ed25519_addresses(1)[0]
print('Address:', address)
21 changes: 10 additions & 11 deletions bindings/python/examples/exchange/3_check_balance.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
# Copyright 2023 IOTA Stiftung
# SPDX-License-Identifier: Apache-2.0

# This example gets the balance of an account.
# This example gets the balance of a wallet.

import os

from dotenv import load_dotenv

from iota_sdk import SyncOptions, Wallet
from iota_sdk import SyncOptions, Wallet, WalletOptions

# This example uses secrets in environment variables for simplicity which
# should not be done in production.
load_dotenv()

if 'WALLET_DB_PATH' not in os.environ:
raise Exception(".env WALLET_DB_PATH is undefined, see .env.example")
for env_var in ['WALLET_DB_PATH', 'FAUCET_URL']:
if env_var not in os.environ:
raise Exception(f'.env {env_var} is undefined, see .env.example')

wallet = Wallet(os.environ.get('WALLET_DB_PATH'))
wallet = Wallet(WalletOptions(storage_path=os.environ.get('WALLET_DB_PATH')))

account = wallet.get_account('Alice')

addresses = account.addresses()
print('Addresses:', addresses)
address = wallet.address()
print('Address:', address)

# 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/account/foundry outputs.
balance = account.sync(SyncOptions(sync_only_most_basic_outputs=True))
balance = wallet.sync(SyncOptions(sync_only_most_basic_outputs=True))
print('Balance', balance)

# Use the faucet to send tokens to your address.
print('Fill your address with the Faucet: https://faucet.testnet.shimmer.network/')
print(f'Fill your address with the Faucet: {os.environ["FAUCET_URL"]}')
21 changes: 9 additions & 12 deletions bindings/python/examples/exchange/4_listen_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@

from dotenv import load_dotenv

from iota_sdk import SyncOptions, Wallet, WalletEventType
from iota_sdk import SyncOptions, Wallet, WalletOptions, WalletEventType

# This example uses secrets in environment variables for simplicity which
# should not be done in production.
load_dotenv()

if 'WALLET_DB_PATH' not in os.environ:
raise Exception(".env WALLET_DB_PATH is undefined, see .env.example")
for env_var in ['WALLET_DB_PATH', 'FAUCET_URL']:
if env_var not in os.environ:
raise Exception(".env WALLET_DB_PATH is undefined, see .env.example")

wallet = Wallet(os.environ.get('WALLET_DB_PATH'))

account = wallet.get_account('Alice')
wallet = Wallet(WalletOptions(storage_path=os.environ.get('WALLET_DB_PATH')))

received_event = False

Expand All @@ -41,13 +40,11 @@ def callback(event):
# Only interested in new outputs here.
wallet.listen(callback, [WalletEventType.NewOutput])

account = wallet.get_account('Alice')

# Use the faucet to send testnet tokens to your address.
print('Fill your address with the faucet: https://faucet.testnet.shimmer.network/')
print(f'Fill your address with the Faucet: {os.environ["FAUCET_URL"]}')

addresses = account.addresses()
print('Send funds to:', addresses[0].address)
address = wallet.address()
print('Send funds to:', address)

# Sync every 5 seconds until the faucet transaction gets confirmed.
for _ in range(100):
Expand All @@ -59,4 +56,4 @@ def callback(event):
# 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/account/foundry
# outputs.
account.sync(SyncOptions(sync_only_most_basic_outputs=True))
wallet.sync(SyncOptions(sync_only_most_basic_outputs=True))
10 changes: 4 additions & 6 deletions bindings/python/examples/exchange/5_send_amount.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from dotenv import load_dotenv

from iota_sdk import SyncOptions, Wallet
from iota_sdk import SyncOptions, Wallet, WalletOptions

# This example uses secrets in environment variables for simplicity which
# should not be done in production.
Expand All @@ -17,18 +17,16 @@
if env_var not in os.environ:
raise Exception(f'.env {env_var} is undefined, see .env.example')

wallet = Wallet(os.environ.get('WALLET_DB_PATH'))

account = wallet.get_account('Alice')
wallet = Wallet(WalletOptions(storage_path=os.environ.get('WALLET_DB_PATH')))

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/account/foundry outputs.
balance = account.sync(SyncOptions(sync_only_most_basic_outputs=True))
balance = wallet.sync(SyncOptions(sync_only_most_basic_outputs=True))
print('Balance', balance)

transaction = account.send(
transaction = wallet.send(
1000000,
"rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu",
)
Expand Down
28 changes: 18 additions & 10 deletions bindings/python/examples/how_tos/account_output/create.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
import os
import time

from dotenv import load_dotenv

from iota_sdk import Wallet

load_dotenv()
from iota_sdk import Wallet, WalletOptions

# In this example we will create an account output

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

account = wallet.get_account('Alice')
for env_var in ['WALLET_DB_PATH', 'STRONGHOLD_PASSWORD', 'EXPLORER_URL']:
if env_var not in os.environ:
raise Exception(f".env {env_var} is undefined, see .env.example")

# Sync account with the node
account.sync()
wallet = Wallet(WalletOptions(storage_path=os.environ.get('WALLET_DB_PATH')))

if 'STRONGHOLD_PASSWORD' not in os.environ:
raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")
# Sync wallet with the node
balance = wallet.sync()
print(f'Accounts BEFORE: {balance.accounts}')

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

print("Sending the create-account transaction...")

# Send transaction.
transaction = account.create_account_output(None, None)
transaction = wallet.create_account_output(None, None)
print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.block_id}')

time.sleep(10)

balance = wallet.sync()
print(f'Accounts AFTER: {balance.accounts}')
21 changes: 10 additions & 11 deletions bindings/python/examples/how_tos/account_output/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@

from dotenv import load_dotenv

from iota_sdk import Wallet

load_dotenv()
from iota_sdk import Wallet, WalletOptions

# In this example we will destroy an account output

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

account = wallet.get_account('Alice')
for env_var in ['WALLET_DB_PATH', 'STRONGHOLD_PASSWORD', 'EXPLORER_URL']:
if env_var not in os.environ:
raise Exception(f".env {env_var} is undefined, see .env.example")

# Sync account with the node
balance = account.sync()
wallet = Wallet(WalletOptions(storage_path=os.environ.get('WALLET_DB_PATH')))

# Sync wallet with the node
balance = wallet.sync()

# 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_account(account_id).send()
transaction = wallet.prepare_destroy_account(account_id).send()
print(f'Block sent: {os.environ["EXPLORER_URL"]}/block/{transaction.block_id}')
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os

from dotenv import load_dotenv

from iota_sdk import Wallet, WalletOptions

# In this example, we create an implicit account creation address.

load_dotenv()

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

wallet = Wallet(WalletOptions(storage_path=os.environ.get('WALLET_DB_PATH')))

# Get the implicit account address
address = wallet.implicit_account_creation_address()
print(f'Fund the following address: {address}')
17 changes: 10 additions & 7 deletions bindings/python/examples/how_tos/account_wallet/request_funds.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@

from dotenv import load_dotenv

from iota_sdk import Wallet, Utils, SyncOptions, AccountSyncOptions
from iota_sdk import Wallet, WalletOptions, Utils, SyncOptions, WalletSyncOptions

# In this example we request funds to an account wallet.

load_dotenv()

for env_var in ['FAUCET_URL', 'WALLET_DB_PATH', 'EXPLORER_URL']:
if env_var not in os.environ:
raise Exception(f".env {env_var} is undefined, see .env.example")

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)
wallet = Wallet(WalletOptions(storage_path=os.environ.get('WALLET_DB_PATH')))
balance = wallet.sync(None)
print(f'{balance}')

total_base_token_balance = balance.base_coin.total
print(
Expand All @@ -33,8 +36,8 @@

time.sleep(10)

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

total_base_token_balance = account.sync(sync_options).base_coin.total
total_base_token_balance = wallet.sync(sync_options).base_coin.total
print(
f'Balance after requesting funds on account address: {total_base_token_balance}')
Loading
Loading