Exemple #1
0
def get_account(iw):

    account_manager = iw.AccountManager(
        storage_path='./alice-database'
    ) #note: `storage` and `storage_path` have to be declared together

    account_manager.set_stronghold_password("password")

    # mnemonic (seed) should be set only for new storage
    # once the storage has been initialized earlier then you should omit this step
    #account_manager.store_mnemonic("Stronghold")

    account_name = 'AliceX'

    # general Tangle specific options
    client_options = {
        "nodes": [
            {
                "url": "https://api.hornet-0.testnet.chrysalis2.com",
                "auth": None,
                "disabled": False
            }
        ],
        "local_pow": True
    }

    try:

        account = account_manager.get_account(account_name)

        return account

    except ValueError:

        # Account not found, create it

        account_manager.store_mnemonic("Stronghold")

        # an account is generated with the given alias via `account_initialiser`
        account_initialiser = account_manager.create_account(client_options)
        account_initialiser.alias(account_name)

        # initialise account based via `account_initialiser`
        # store it to db and sync with Tangle
        account = account_initialiser.initialise()

        return account
Exemple #2
0
def start_worker():

    # Get the acount manager
    manager = iw.AccountManager(storage_path='./alice-database')

    account = get_account(iw)

    # NOTE: In real use cases you need to set the password in a safer way, like getting it from env variables
    #manager.set_stronghold_password(STRONGHOLD_PASSWORD)

    # Get the account
    #account = manager.get_account('Alice')
    print(f'Account: {account.alias()}')

    # Always sync before doing anything with the account
    print('Syncing...')
    #synced = account.sync().execute()

    # Get the latest unused address
    last_address_obj = account.latest_address()
    print(f"Address: {last_address_obj['address']}")

    # turn-on the worker thread
    t1 = threading.Thread(target=worker, daemon=True)
    t2 = threading.Thread(target=test, daemon=True, args=(account, ))

    t1.start()
    t2.start()

    # listen to the on_balance_change event
    #iota_wallet.on_balance_change(balance_changed_event_processing)
    iw.on_new_transaction(new_transaction_event_processing)

    # Use the Chrysalis Faucet to send testnet tokens to your address:
    print(
        f"Fill your Address ({last_address_obj['address']['inner']}) with the Faucet: https://faucet.tanglekit.de/"
    )
    print(
        "To see how the on_balance_change is called, please send tokens to the address in 1 min"
    )
    time.sleep(600)

    # block until all tasks are done
    q.join()
    print('All work completed')
Exemple #3
0
import iota_wallet as iw

import requests
import json

from tkinter import *
from tkinter import ttk
from PIL import Image, ImageTk

asset_price = 0.000000  # MIOTA pr hour

### Connect to wallet account or create account if it does not exist

account_manager = iw.AccountManager(
    storage_path='./alice-database'
)  #note: `storage` and `storage_path` have to be declared together

account_manager.set_stronghold_password("password")

# mnemonic (seed) should be set only for new storage
# once the storage has been initialized earlier then you should omit this step
#account_manager.store_mnemonic("Stronghold")

account_name = 'AliceX'

# general Tangle specific options
client_options = {
    "nodes": [{
        "url": "https://api.hornet-0.testnet.chrysalis2.com",
        "auth": None,
        "disabled": False
Exemple #4
0
# This example generates a new mnemonic using iota_wallet library.
# This step is not necessary since in the following examples is an "example" seed provided.
# However, if you want to try this workshop with the Firefly wallet, you may want to use this example file.
# In that case, import the generated Mnemonic in the Firefly wallet and replace Seed values in the following exercises
# with the generated Seed.

# YOU SHOULD NEVER TRUST 3RD PARTY TOOLS/PROGRAMS WITH YOUR SEED/MNEMONIC!
# USE THE PRIVATE KEYS GENERATED BY THIS EXAMPLE ONLY IN THIS WORKSHOP!
# IN PRACTISE, NEVER STORE YOUR PRIVATE KEYS IN YOUR CODE. USE ENVIROMENT VARIABLES!

import binascii
import hashlib
import unicodedata
import iota_wallet

# Creates an AccountManager class from iota_wallet library to generate a mnemonic
mnemonic = iota_wallet.AccountManager(
    storage_path='./storage').generate_mnemonic()
# iota_wallet's AccountManager creates its own ./storage folder. We won't need it for this workshop
# since we will be using iota_client, that uses Seed instead of Accounts stored in Stronghold.
# Feel free to remove that folder if it was created BY THIS WORKSHOP (not by you or your applications)

seed = hashlib.pbkdf2_hmac(
    "sha512",
    unicodedata.normalize("NFKD", mnemonic).encode("utf-8"),
    "mnemonic".encode("utf-8"), 2048)
print(f'Generated mnemonic: {mnemonic}')
print(f'Generated seed: {binascii.hexlify(seed).decode("utf-8")}')
Exemple #5
0
# Get the stronghold password
#STRONGHOLD_PASSWORD = os.getenv('STRONGHOLD_PASSWORD')

result_available = threading.Event()
result_available.daemon=True


def new_transaction_event_processing(event):
    print(f'On new transaction: {event}')
    #result_available.set()


# This example shows some events.
account_manager = iw.AccountManager(
    storage_path='./alice-database'
)

# NOTE: In real use cases you need to set the password in a safer way, like getting it from env variables
#account_manager.set_stronghold_password(STRONGHOLD_PASSWORD)

#account = account_manager.get_account('Alice')
print(f'Account: {account.alias()}')

# Always sync before doing anything with the account
print('Syncing...')
synced = account.sync().execute()

# Get the latest unused address
last_address_obj = account.latest_address()
print(f"Address: {last_address_obj['address']}")
Exemple #6
0
    """
    while True:
        item = q.get(True)
        print(f'Get event: {item}')
        q.task_done()


def balance_changed_event_processing(event):
    """Processing function when event is received.
    """
    print(f'On balanced changed: {event}')
    q.put(event)


# Get the acount manager
manager = iota_wallet.AccountManager(
    storage_path='./alice-database')

# NOTE: In real use cases you need to set the password in a safer way, like getting it from env variables
manager.set_stronghold_password(STRONGHOLD_PASSWORD)

# Get the account
account = manager.get_account('Alice')
print(f'Account: {account.alias()}')

# Always sync before doing anything with the account
print('Syncing...')
synced = account.sync().execute()

# Get the latest unused address
last_address_obj = account.latest_address()
print(f"Address: {last_address_obj['address']}")