Skip to content

Commit

Permalink
Merge branch '2.0' into refactor-MetadataFeature
Browse files Browse the repository at this point in the history
  • Loading branch information
thibault-martinez authored Dec 21, 2023
2 parents 23c3670 + 88773be commit b076fe6
Show file tree
Hide file tree
Showing 84 changed files with 1,512 additions and 1,434 deletions.
114 changes: 114 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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,27 @@
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'])

account = wallet.create_account('Alice')
SecretManager(secret_manager).store_mnemonic(os.environ['MNEMONIC'])

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
Loading

0 comments on commit b076fe6

Please sign in to comment.