예제 #1
0
async def setup_kin():
    client = kin.KinClient(kin.TEST_ENVIRONMENT)
    try:
        global computer_account
        global player_account
        global player_keypair
        keypair = kin.Keypair(seed="SAYWTBSMRBCPCATEPV3ETU5UVIWTBZJP53OBTEKVLSTLVZN7DPLMN3Z6")
        computer_account = client.kin_account(keypair.secret_seed)
        player_keypair = kin.Keypair()
        player_account = await computer_account.create_account(player_keypair.public_address, starting_balance=0, fee=100, memo_text='create player account')
    finally:
        await client.close()
예제 #2
0
    async def setup_kin(app, loop):

        # Setup kin client
        kin_env = kin.Environment('CUSTOM', config.HORIZON_ENDPOINT,
                                  config.NETWORK_PASSPHRASE)
        app.kin_client = kin.KinClient(kin_env)

        # Create channels
        if config.CHANNEL_COUNT > 0:
            logger.info(f'Setting up {config.CHANNEL_COUNT} channels')
            channels = get_hd_channels(config.SEED, config.CHANNEL_SALT,
                                       config.CHANNEL_COUNT)
        else:
            channels = None

        app.kin_account = app.kin_client.kin_account(
            config.SEED, channel_secret_keys=channels, app_id=config.APP_ID)
async def kin_function():
    print(
        'First we will create our KinClient object, and direct it to our test environment'
    )
    async with kin.KinClient(kin.TEST_ENVIRONMENT) as client:

        print('\nEnvironment: ')
        print(client.environment)

        # Get keypair
        # Address: GABGTDCVQDME54Q2WMB45SNEYZN2WG4MLC2CPI35XQ6PMWAXDWNOI47A, Seed: SDTOH63RNOSXHIHA6SPDGUTG5T4VYM4PQYY76AE4VC4EBEGIA2U73UOT
        existing = input('Use existing seed? [y/n]:  ')
        if existing == 'y':
            seed = input('Input your seed: ')
            try:
                keypair = kin.Keypair(seed=seed)
            except kin.KinErrors.StellarSecretInvalidError:
                print('Your seed was not valid')
                raise
        else:
            print('\nNext we will generate a keypair')
            keypair = kin.Keypair()

        print('We are using the following keypair\n')
        print(keypair)

        print(
            'Using the client, we can check if this account already exists on the blockchain'
        )
        exist = await client.does_account_exists(keypair.public_address)
        if exist:
            print('The account already exist on the blockchain')
        else:
            print('The account does not exist on the blockchain')
            print(
                '\nSince we are on the testnet blockchain, we can use the friendbot to create our account...\n'
            )
            await client.friendbot(keypair.public_address)

        # Init KinAccount
        print(
            'We can now create a KinAccount object, we will use it to interact with our account'
        )
        account = client.kin_account(keypair.secret_seed)

        print('We can use our KinAccount object to get our balance')
        print('Our balance is {} KIN'.format(await account.get_balance()))

        # Create a different account
        print('\nWe will now create a different account')
        new_keypair = kin.Keypair()
        print('Creating account: {}'.format(new_keypair.public_address))
        tx_hash = await account.create_account(new_keypair.public_address,
                                               starting_balance=1000,
                                               fee=100,
                                               memo_text='Example')
        print('\nWe created the account and got the transaction id: {}'.format(
            tx_hash))

        # Get info about a tx
        print(
            '\nWe can now use the client to get info about the transaction we did\n'
        )
        transaction = await client.get_transaction_data(tx_hash=tx_hash)
        # We don't have __str__ for the transaction class, so we print it like this till we add it
        transaction.operation = vars(transaction.operation)
        pprint(vars(transaction))

        tx_hash = await account.send_kin(new_keypair.public_address,
                                         amount=10,
                                         fee=100,
                                         memo_text='Hello World')
        print('The transaction succeeded with the hash {}'.format(tx_hash))
예제 #4
0
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(asctime)s | level=%(levelname)s | request_id=%(request_id)s | %(message)s'))
handler.addFilter(RequestIDLogFilter())
logging.root.addHandler(handler)
logger = logging.getLogger('migration')
logger.setLevel('INFO')

kin_logger = logging.getLogger('kin')
kin_logger.setLevel('ERROR')

# Setup DogStatsd
statsd = DogStatsd(host=config.STATSD_HOST, port=config.STATSD_PORT, namespace='migration')

# Setup kin
# Passphrase is not needed for the old environment since we don't send any txs to it
old_env = kin.Environment('OLD', config.OLD_HORIZON, '')
new_env = kin.Environment('NEW', config.NEW_HORIZON, config.NEW_PASSPHRASE)

old_client = kin.KinClient(old_env)
new_client = kin.KinClient(new_env)

channels = create_channels(config.MAIN_SEED, new_env, config.CHANNEL_COUNT, 0, config.CHANNEL_SALT)
main_account = new_client.kin_account(config.MAIN_SEED, channels, app_id=config.APP_ID)

logger.info(f'Initialized app with address: {main_account.keypair.public_address}, '
            f'Old horizon: {config.OLD_HORIZON}, '
            f'New horizon: {config.NEW_HORIZON}')



예제 #5
0
base_seed, channel_seeds = ssm.get_stellar_credentials()
if not base_seed:
    log.error('could not get base seed - aborting')
    sys.exit(-1)

if channel_seeds is None:
    log.error('could not get channels seeds - aborting')
    sys.exit(-1)

# init sdk:
print('using kin sdk version: %s' % kin.version.__version__)
print("kin horizon: %s" % config.STELLAR_HORIZON_URL)

myenv = kin.Environment('CUSTOM', config.STELLAR_HORIZON_URL,
                        config.STELLAR_NETWORK)
app.kin_sdk = kin.KinClient(myenv)
app.kin_account = app.kin_sdk.kin_account(base_seed, channel_seeds, "TIPC")
log.info('Kin account status: %s' % app.kin_account.get_status())

# init encryption util
key, iv = ssm.get_encrpytion_creds()
app.encryption = AESCipher(key, iv)


# SQLAlchemy stuff:
# create an sqlalchemy engine with "autocommit" to tell sqlalchemy NOT to use un-needed transactions.
# see this: http://oddbird.net/2014/06/14/sqlalchemy-postgres-autocommit/
# and this: https://github.com/mitsuhiko/flask-sqlalchemy/pull/67
class MySQLAlchemy(SQLAlchemy):
    def apply_driver_hacks(self, app, info, options):
        options['isolation_level'] = 'AUTOCOMMIT'
예제 #6
0
"""Simple example of the kin-sdk usage"""
from pprint import pprint

import kin

# Init client
print(
    'First we will create our KinClient object, and direct it to our test environment'
)
client = kin.KinClient(kin.TEST_ENVIRONMENT)
print('\nEnvironment: ')
pprint(vars(client.environment))

# Get keypair
existing = input('Use existing seed? [y/n]:  ')
if existing == 'y':
    seed = input('Input your seed: ')
    try:
        keypair = kin.Keypair(seed=seed)
    except kin.KinErrors.StellarSecretInvalidError:
        print('Your seed was not valid')
        raise
else:
    print('\nNext we will generate a keypair')
    keypair = kin.Keypair()

print('We are using the following keypair\n')
pprint(vars(keypair))

# Check account status
print(
예제 #7
0
async def quickstart():
    # Init client
    print('First we will create our KinClient object, and direct it to our test environment')
    async with kin.KinClient(kin.TEST_ENVIRONMENT) as client:

        print('\nEnvironment: ')
        print(client.environment)

        # Get keypair
        existing = input('Use existing seed? [y/n]:  ')
        if existing == 'y':
            seed = input('Input your seed: ')
            try:
                keypair = kin.Keypair(seed=seed)
            except kin.KinErrors.StellarSecretInvalidError:
                print('Your seed was not valid')
                raise
        else:
            print('\nNext we will generate a keypair')
            keypair = kin.Keypair()

        print('We are using the following keypair\n')
        print(keypair)

        # Check account status
        print('Using the client, we can check if this account already exists on the blockchain')
        exist = await client.does_account_exists(keypair.public_address)
        if exist:
            print('The account already exist on the blockchain')
        else:
            print('The account does not exist on the blockchain')
            print('\nSince we are on the testnet blockchain, we can use the friendbot to create our account...\n')
            await client.friendbot(keypair.public_address)

        # Init KinAccount
        print('We can now create a KinAccount object, we will use it to interact with our account')
        account = client.kin_account(keypair.secret_seed)

        # Get balance
        print('We can use our KinAccount object to get our balance')
        print('Our balance is {} KIN'.format(await account.get_balance()))

        # Create a different account
        print('\nWe will now create a different account')
        new_keypair = kin.Keypair()
        print('Creating account: {}'.format(new_keypair.public_address))
        tx_hash = await account.create_account(new_keypair.public_address, starting_balance=1000, fee=100, memo_text='Example')
        print('\nWe created the account and got the transaction id: {}'.format(tx_hash))

        # Get info about a tx
        print('\nWe can now use the client to get info about the transaction we did\n')
        transaction = await client.get_transaction_data(tx_hash=tx_hash)
        # We don't have __str__ for the transaction class, so we print it like this till we add it
        transaction.operation = vars(transaction.operation)
        pprint(vars(transaction))

        print('\nSince we created that account, we can now send kin to it')
        tx_hash = await account.send_kin(new_keypair.public_address, amount=10, fee=100, memo_text='Hello World')
        print('The transaction succeeded with the hash {}'.format(tx_hash))

        transaction = await client.get_transaction_data(tx_hash=tx_hash)

        # We don't have __str__ for the transaction class, so we print it like this till we add it
        transaction.operation = vars(transaction.operation)
        print('\nThese are the details of the transaction we just executed sending Kin to our test account')
        pprint(vars(transaction))

        print('\nNow we can check the balance of that account to see it\'s updated balance')
        print('Updated balance is {}'.format(await client.get_account_balance(new_keypair.public_address)))