def initialize(): if len(sys.argv) < 4: print('invalid number of params :', len(clients)) sys.exit(1) global PASSPHRASE global WHITELIST_MANAGER_KEYPAIR global root_account global tx_count PASSPHRASE = sys.argv[1] WHITELIST_MANAGER_KEYPAIR = Keypair(sys.argv[2]) tx_count = int(sys.argv[3]) for arg in sys.argv[4:]: local_env = Environment('LOCAL', arg, PASSPHRASE, 'http://localhost:8001') # Creates a client clients.append(KinClient(local_env)) print('Client ', len(clients), ' created!') # Create the root account object root_account = clients[0].kin_account( derive_root_account(PASSPHRASE).secret_seed) print('Root account object created')
async def main(): """Create accounts and print their seeds to stdout.""" args = parse_args() env = Environment(NETWORK_NAME, (args.horizon)[0], args.passphrase) builder = Builder(NETWORK_NAME, KinClient(env).horizon, MIN_FEE, root_account_seed(args.passphrase)) builder.sequence = builder.get_sequence() kps = await create_accounts(builder, args.horizon, args.accounts, STARTING_BALANCE) for kp in kps: print(kp.secret_seed)
async def init_channel_builders(channel_seeds_file, passphrase, horizon): env = Environment(NETWORK_NAME, (horizon)[0], passphrase) channel_kps = load_accounts(channel_seeds_file) sequences = await get_sequences_multiple_endpoints(horizon, [kp.public_address for kp in channel_kps]) channel_builders = [] for i, kp in enumerate(channel_kps): b = Builder(NETWORK_NAME, KinClient(env).horizon, MIN_FEE, kp.secret_seed) b.sequence = str(sequences[i]) channel_builders.append(b) return channel_builders
async def main(): args = parse_args() # setup network Environment(NETWORK_NAME, args.horizon[0], args.passphrase) logging.info('loading prioritizer accounts') prioritizer_kps = [kp for kp in load_accounts(args.prioritizer_seeds_file)] logging.info('%d prioritizer accounts loaded', len(prioritizer_kps)) logging.info('loading spammer accounts') spam_kps = load_accounts(args.spammer_seeds_file) logging.info('%d spammer accounts loaded', len(spam_kps)) logging.info('fetching sequence number for spammer accounts') spam_sequences = await get_sequences_multiple_endpoints(args.horizon, [kp.public_address for kp in spam_kps]) logging.info('generating spammer builders') spam_builders = [] # we're not submitting using the builder - just generating the xdr, # so each builder's horizon instance is irrelevant stub_horizon = args.horizon[0] for kp, seq in zip(spam_kps, spam_sequences): b = Builder(NETWORK_NAME, stub_horizon, MIN_FEE, kp.secret_seed) b.sequence = str(seq) spam_builders.append(b) logging.info('sleeping for %ds to let horizon cool down after get sequence request surge', COOL_DOWN_AFTER_GET_SEQ) time.sleep(COOL_DOWN_AFTER_GET_SEQ) logging.info('starting spam') results = await spam(args.horizon, prioritizer_kps, spam_builders, args.length, args.txs_per_ledger) logging.info('done spamming') logging.info('writing transaction results to file') with open(args.out, 'w') as f: for spam_round in results: for tx in spam_round: f.write('{}\n'.format(json.dumps(tx))) logging.info('done')
async def main(): args = parse_args() # setup network Environment(NETWORK_NAME, args.horizon[0], args.passphrase) logging.info('loading prioritizer accounts') prioritizer_kps = [kp for kp in load_accounts(args.prioritizer_seeds_file)] logging.info('%d prioritizer accounts loaded', len(prioritizer_kps)) logging.info('loading spammer accounts') spam_kps = load_accounts(args.spammer_seeds_file) logging.info('%d spammer accounts loaded', len(spam_kps)) logging.info('fetching sequence number for spammer accounts') spam_sequences = await get_sequences_multiple_endpoints(args.horizon, [kp.public_address for kp in spam_kps]) logging.info('generating spammer builders') spam_builders = [] # we're not submitting using the builder - just generating the xdr, # so each builder's horizon instance is irrelevant stub_horizon = args.horizon[0] for kp, seq in zip(spam_kps, spam_sequences): b = Builder(NETWORK_NAME, stub_horizon, MIN_FEE, kp.secret_seed) b.sequence = str(seq) spam_builders.append(b) logging.info('generating spam transaction xdrs') spam_rounds = await generate_spam_tx_xdrs(prioritizer_kps, spam_builders, args.length, args.txs_per_ledger, args.avg_block_time) logging.info('done generating spam transaction xdrs') logging.info('writing transaction xdrs to file %s', args.out) with open(args.out, 'w') as f: for rnd in spam_rounds: f.write('{}\n'.format(json.dumps(rnd))) logging.info('done')
async def main(): # Create the environment local_env = Environment('LOCAL', 'http://localhost:8000', PASSPHRASE, 'http://localhost:8001') # Create a client client = KinClient(local_env) print('Client created') initial_ledger_size = get_latest_ledger(client)['max_tx_set_size'] try: # Set ledger tx size to 1 requests.get( 'http://localhost:11626/upgrades?mode=set&maxtxsize=1&upgradetime=2018-10-15T18:34:00Z' ) # Create the root account object root_account = client.kin_account( derive_root_account(PASSPHRASE).secret_seed) print('Root account object created') minimum_fee = client.get_minimum_fee() # Create an account with 0 base reserve test_account = Keypair() root_account.create_account(test_account.public_address, 0, minimum_fee) assert client.does_account_exists(test_account.public_address) print('Test account created') # Add the account to the whitelist if not client.does_account_exists( WHITELIST_MANAGER_KEYPAIR.public_address): root_account.create_account( WHITELIST_MANAGER_KEYPAIR.public_address, 10000, 100) print('Created whitelisting account') builder = Builder('LOCAL', client.horizon, fee=minimum_fee, secret=WHITELIST_MANAGER_KEYPAIR.secret_seed) builder.get_sequence() builder.append_manage_data_op(test_account.public_address, test_account._hint) builder.sign() builder.submit() print('Added account to whitelist') for _ in range(5): txs = [] first_builder = Builder('LOCAL', client.horizon, fee=minimum_fee, secret=test_account.secret_seed) first_builder.append_manage_data_op('test', 'test'.encode()) first_builder.get_sequence() first_builder.sign() txs.append(first_builder) second_builder = Builder( 'LOCAL', client.horizon, fee=minimum_fee, secret=WHITELIST_MANAGER_KEYPAIR.secret_seed) second_builder.append_payment_op(test_account.public_address, '1') second_builder.get_sequence() second_builder.sign() txs.append(second_builder) initial_ledger = get_latest_ledger(client)['sequence'] print(f'Initial ledger: {initial_ledger}') while initial_ledger == get_latest_ledger(client)['sequence']: time.sleep(0.5) first_populated_ledger = initial_ledger + 2 print(f'Sending on ledger: {first_populated_ledger}') print(f'Sending txs at {time.strftime("%d/%m/%Y %H:%M:%S")}') await send_txs(txs) print(f'Done sending txs at {time.strftime("%d/%m/%Y %H:%M:%S")}') first_ledger_txs = client.horizon.ledger_transactions( first_populated_ledger)['_embedded']['records'] # First ledger should have tx from whitelist_manager assert WHITELIST_MANAGER_KEYPAIR.public_address == first_ledger_txs[ 0]['source_account'] print('Verified tx from whitelist manager got priority') except: raise finally: # Set tx size to what it was before requests.get( f'http://localhost:11626/upgrades?mode=set&maxtxsize={initial_ledger_size}&upgradetime=2018-10-15T18:34:00Z' )
def main(): # Create the environment local_env = Environment('LOCAL', 'http://localhost:8000', PASSPHRASE, 'http://localhost:8001') # Create a client client = KinClient(local_env) print('Client created') # Create the root account object root_account = client.kin_account( derive_root_account(PASSPHRASE).secret_seed) print('Root account object created') minimum_fee = client.get_minimum_fee() # Create an account with 0 base reserve test_account = Keypair() root_account.create_account(test_account.public_address, 0, minimum_fee) assert client.does_account_exists(test_account.public_address) print('Test account created') # Send a tx that does not require spending kin builder = Builder('LOCAL', client.horizon, fee=0, secret=test_account.secret_seed) builder.get_sequence() builder.append_manage_data_op('test', 'test'.encode()) builder.sign() try: builder.submit() except KinErrors.HorizonError as e: # Tx should fail since the fee is under minimum fee assert e.extras.result_codes.transaction == KinErrors.TransactionResultCode.INSUFFICIENT_FEE print('Sending under minimum fee - Passed') builder = Builder('LOCAL', client.horizon, fee=minimum_fee, secret=test_account.secret_seed) builder.get_sequence() builder.append_manage_data_op('test', 'test'.encode()) builder.sign() try: builder.submit() except KinErrors.HorizonError as e: # Tx should fail since the account cant pay the fee assert e.extras.result_codes.transaction == KinErrors.TransactionResultCode.INSUFFICIENT_BALANCE print('Sending with no fee to pay - Passed') # Add the account to the whitelist if not client.does_account_exists( WHITELIST_MANAGER_KEYPAIR.public_address): root_account.create_account(WHITELIST_MANAGER_KEYPAIR.public_address, 10000, 100) print('Created whitelisting account') builder = Builder('LOCAL', client.horizon, fee=minimum_fee, secret=WHITELIST_MANAGER_KEYPAIR.secret_seed) builder.get_sequence() builder.append_manage_data_op(test_account.public_address, test_account._hint) builder.sign() builder.submit() print('Added account to whitelist') # test_account is now a whitelister, so the fee should be ignored builder = Builder('LOCAL', client.horizon, fee=0, secret=test_account.secret_seed) builder.get_sequence() builder.append_manage_data_op('test2', 'test2'.encode()) builder.sign() builder.submit() print('Sending prioritized tx under minimum fee - Passed') builder = Builder('LOCAL', client.horizon, fee=999999, secret=test_account.secret_seed) builder.get_sequence() builder.append_manage_data_op('test3', 'test3'.encode()) builder.sign() builder.submit() print('Sending prioritized tx with fee > balance - Passed') # Try the same if the account is not a whitelister, but the tx is whitelisted test_account2 = Keypair() root_account.create_account(test_account2.public_address, 0, minimum_fee) builder = Builder('LOCAL', client.horizon, fee=999999, secret=test_account2.secret_seed) builder.get_sequence() builder.append_manage_data_op('test', 'test'.encode()) builder.sign() # sign with the whitelister as well to prioritize the tx builder.sign(secret=test_account.secret_seed) builder.submit() print('Sending prioritized tx2 with fee > balance - Passed')
async def main(): # Create the environment local_env = Environment('LOCAL', 'http://localhost:8000', PASSPHRASE, 'http://localhost:8001') # Create a client client = KinClient(local_env) print('Client created') initial_ledger_size = get_latest_ledger(client)['max_tx_set_size'] try: # Set ledger tx size to 3 requests.get( 'http://localhost:11626/upgrades?mode=set&maxtxsize=3&upgradetime=2018-10-15T18:34:00Z' ) # Create the root account object root_account = client.kin_account( derive_root_account(PASSPHRASE).secret_seed) print('Root account object created') minimum_fee = client.get_minimum_fee() # Create an account with 0 base reserve test_account = Keypair() root_account.create_account(test_account.public_address, 0, minimum_fee) assert client.does_account_exists(test_account.public_address) print('Test account created') accounts = [Keypair() for _ in range(5)] builder = Builder('LOCAL', client.horizon, fee=minimum_fee, secret=root_account.keypair.secret_seed) for keypair in accounts: builder.append_create_account_op(keypair.public_address, '100') builder.get_sequence() builder.sign() builder.submit() print('Created 5 accounts') txs = [] for index, account in enumerate(accounts, start=1): builder = Builder('LOCAL', client.horizon, fee=minimum_fee * index, secret=account.secret_seed) builder.append_manage_data_op('test', 'test'.encode()) builder.get_sequence() builder.sign() txs.append(builder) initial_ledger = get_latest_ledger(client)['sequence'] print(f'Initial ledger: {initial_ledger}') while initial_ledger == get_latest_ledger(client)['sequence']: time.sleep(0.5) first_populated_ledger = initial_ledger + 2 second_populated_ledger = initial_ledger + 3 print(f'Sending on ledger: {first_populated_ledger}') print(f'Sending txs at {time.strftime("%d/%m/%Y %H:%M:%S")}') await send_txs(txs) print(f'Done sending txs at {time.strftime("%d/%m/%Y %H:%M:%S")}') first_ledger_txs = client.horizon.ledger_transactions( first_populated_ledger)['_embedded']['records'] second_ledger_txs = client.horizon.ledger_transactions( second_populated_ledger)['_embedded']['records'] # First ledger should have txs where fee>=300 first_txs = sum(1 for tx in first_ledger_txs if tx['fee_paid'] >= 300) assert first_txs == 3 print('Verified first ledger') # Second ledger should have txs where fee<=200 second_txs = sum(1 for tx in second_ledger_txs if tx['fee_paid'] <= 200) assert second_txs == 2 print('Verified seconds ledger') except: raise finally: # Set tx size to what it was before requests.get( f'http://localhost:11626/upgrades?mode=set&maxtxsize={initial_ledger_size}&upgradetime=2018-10-15T18:34:00Z' )
import os from datetime import datetime from kin import Environment STELLAR_HORIZON_URL = os.environ['STELLAR_HORIZON_URL'] STELLAR_NETWORK = os.environ['STELLAR_NETWORK'] STELLAR_ENV = Environment('CUSTOM', STELLAR_HORIZON_URL, STELLAR_NETWORK) CHANNEL_SALT = os.environ.get('CHANNEL_SALT') MAX_CHANNELS = int(os.environ.get('MAX_CHANNELS', '1200')) STELLAR_BASE_SEED = os.environ['STELLAR_BASE_SEED'] REDIS = os.environ['APP_REDIS'] APP_NAME = os.environ.get('APP_NAME', 'payment-service') STATSD_HOST = os.environ.get('STATSD_HOST', 'localhost') STATSD_PORT = int(os.environ.get('STATSD_PORT', 8125)) DEBUG = os.environ.get('APP_DEBUG', 'true').lower() == 'true' build = {'commit': os.environ.get('BUILD_COMMIT'), 'timestamp': os.environ.get('BUILD_TIMESTAMP'), 'start_time': datetime.utcnow().isoformat()}
async def main(): # Create the environment local_env = Environment('LOCAL', 'http://localhost:8000', PASSPHRASE, 'http://localhost:8001') # Create a client client = KinClient(local_env) print('Client created') initial_ledger_size = get_latest_ledger(client)['max_tx_set_size'] try: # Set ledger tx size to 3 requests.get( 'http://localhost:11626/upgrades?mode=set&maxtxsize=3&upgradetime=2018-10-15T18:34:00Z' ) # Create the root account object root_account = client.kin_account( derive_root_account(PASSPHRASE).secret_seed) print('Root account object created') minimum_fee = client.get_minimum_fee() # Create an account with 0 base reserve test_account = Keypair() root_account.create_account(test_account.public_address, 0, minimum_fee) assert client.does_account_exists(test_account.public_address) print('Test account created') # Add the account to the whitelist if not client.does_account_exists( WHITELIST_MANAGER_KEYPAIR.public_address): root_account.create_account( WHITELIST_MANAGER_KEYPAIR.public_address, 10000, 100) print('Created whitelisting account') builder = Builder('LOCAL', client.horizon, fee=minimum_fee, secret=WHITELIST_MANAGER_KEYPAIR.secret_seed) builder.get_sequence() builder.append_manage_data_op(test_account.public_address, test_account._hint) builder.sign() builder.submit() print('Added account to whitelist') accounts = [Keypair() for _ in range(5)] builder = Builder('LOCAL', client.horizon, fee=minimum_fee, secret=root_account.keypair.secret_seed) for keypair in accounts: builder.append_create_account_op(keypair.public_address, '100') builder.get_sequence() builder.sign() builder.submit() print('Created 5 accounts') txs = [] for account in accounts: builder = Builder('LOCAL', client.horizon, fee=minimum_fee, secret=account.secret_seed) builder.append_manage_data_op('test', 'test'.encode()) builder.get_sequence() builder.sign() txs.append(builder) for tx in txs[2:]: tx.sign(test_account.secret_seed) print('Whitelisted 3 transactions') initial_ledger = get_latest_ledger(client)['sequence'] print(f'Initial ledger: {initial_ledger}') while initial_ledger == get_latest_ledger(client)['sequence']: time.sleep(0.5) first_populated_ledger = initial_ledger + 2 second_populated_ledger = initial_ledger + 3 print(f'Sending on ledger: {first_populated_ledger}') print(f'Sending txs at {time.strftime("%d/%m/%Y %H:%M:%S")}') await send_txs(txs) print(f'Done sending txs at {time.strftime("%d/%m/%Y %H:%M:%S")}') first_ledger_txs = client.horizon.ledger_transactions( first_populated_ledger)['_embedded']['records'] second_ledger_txs = client.horizon.ledger_transactions( second_populated_ledger)['_embedded']['records'] # First ledger should have 2 whitelisted txs, and 1 non-whitelisted whitelisted_amount = sum(1 for tx in first_ledger_txs if len(tx['signatures']) == 2) assert whitelisted_amount == 2 regular_amount = sum(1 for tx in first_ledger_txs if len(tx['signatures']) == 1) assert regular_amount == 1 # # Second ledger should have 1 whitelisted tx, and 1 non-whitelisted whitelisted_amount = sum(1 for tx in second_ledger_txs if len(tx['signatures']) == 2) assert whitelisted_amount == 1 regular_amount = sum(1 for tx in second_ledger_txs if len(tx['signatures']) == 1) assert regular_amount == 1 except: raise finally: # Set tx size to what it was before requests.get( f'http://localhost:11626/upgrades?mode=set&maxtxsize={initial_ledger_size}&upgradetime=2018-10-15T18:34:00Z' )
async def main(): # Create the environment local_env = Environment('LOCAL', 'http://localhost:8000', PASSPHRASE, 'http://localhost:8001') # Create a client client = KinClient(local_env) print('Client created') initial_ledger_size = get_latest_ledger(client)['max_tx_set_size'] try: # Set ledger tx size to 1 requests.get( 'http://localhost:11626/upgrades?mode=set&maxtxsize=1&upgradetime=2018-10-15T18:34:00Z' ) # Create the root account object root_account = client.kin_account( derive_root_account(PASSPHRASE).secret_seed) print('Root account object created') minimum_fee = client.get_minimum_fee() # Create an account with 0 base reserve test_account = Keypair() root_account.create_account(test_account.public_address, 0, minimum_fee) assert client.does_account_exists(test_account.public_address) print('Test account created') # Add the account to the whitelist if not client.does_account_exists( WHITELIST_MANAGER_KEYPAIR.public_address): root_account.create_account( WHITELIST_MANAGER_KEYPAIR.public_address, 10000, 100) print('Created whitelisting account') initial_ledger = get_latest_ledger(client)['sequence'] print(f'Adding account to whitelist on ledger: {initial_ledger + 2}') builder = Builder('LOCAL', client.horizon, fee=minimum_fee, secret=WHITELIST_MANAGER_KEYPAIR.secret_seed) builder.get_sequence() builder.append_manage_data_op(test_account.public_address, test_account._hint) builder.sign() builder.submit() print('Added account to whitelist') while initial_ledger + 1 == get_latest_ledger(client)['sequence']: time.sleep(0.5) print( f'Submitting tx from test account on ledger: {initial_ledger + 3}') builder = Builder('LOCAL', client.horizon, fee=0, secret=test_account.secret_seed) builder.append_manage_data_op('test', 'test'.encode()) builder.get_sequence() builder.sign() builder.submit() while initial_ledger + 2 == get_latest_ledger(client)['sequence']: time.sleep(0.5) populated_ledger_txs = client.horizon.ledger_transactions( initial_ledger + 3)['_embedded']['records'] assert len(populated_ledger_txs) == 1 assert populated_ledger_txs[0]['fee_paid'] == 0 except: raise finally: # Set tx size to what it was before requests.get( f'http://localhost:11626/upgrades?mode=set&maxtxsize={initial_ledger_size}&upgradetime=2018-10-15T18:34:00Z' )