def read_keypair(wallet_path): if not os.path.exists(wallet_path): stderr(f'Path to wallet "{wallet_path}" does not exist!') sys.exit(1) password = getpass('Wallet password: ') keypair = KeyPair.read_from_dir(wallet_path, password) return keypair
def create(self, request, **kwargs): pub_key = request.data.get('key') amount = request.data.get('amount', 100) with redis.lock(f'get_faucet_{pub_key}', timeout=5): free_coins = FaucetTransaction.receivable_tokens(pub_key) actual_coins = min(amount, free_coins) if actual_coins > 0: epoch_host = settings.EPOCH_HOST config = Config( external_host=f'{epoch_host}:3013', internal_host=f'{epoch_host}:3113', websocket_host=f'{epoch_host}:3114' ) # connect with the Epoch node client = EpochClient(configs=config) key_pair = KeyPair.read_from_dir( settings.EPOCH_KEYS, settings.EPOCH_PASSWORD ) try: # check balance balance = client.get_balance() if balance < actual_coins: raise ParseError('Faucet is out of cash') except AException: raise ParseError('Faucet has no account') try: client.spend(pub_key, int(actual_coins), key_pair) except AException: raise ParseError(f'Spend TX failed Amount {actual_coins}') FaucetTransaction.objects.create( public_key=pub_key, amount=actual_coins ) elif amount > 0: raise ParseError('Your hourly/daily rate has been reached') return JsonResponse({'spent': actual_coins})
def test_create_transaction_signing(): client = EpochClient() new_keypair = KeyPair.generate() receiver_address = new_keypair.get_address() keypair = KeyPair.read_from_dir('/home/tom/data/aeternity/epoch/_build/dev1/rel/epoch/data/aecore/keys/', 'secret') transaction = client.create_spend_transaction(receiver_address, 10) signed_transaction, b58signature = keypair.sign_transaction(transaction) result = client.send_signed_transaction(signed_transaction) assert result == {} current_block = client.get_latest_block() # make sure this works for very short block times client.wait_for_next_block(polling_interval=0.01) next_block = client.get_latest_block() # find the transaction that is the spend transaction we just submitted spend_tx = next(tx for tx in next_block.transactions if type(tx.tx) == SpendTx) assert spend_tx.signatures[0] == b58signature
def spend(amount, receipient, keypair_folder, password): keypair = KeyPair.read_from_dir(keypair_folder, password) EpochClient().spend(receipient, amount, keypair)
elif main_arg == 'oracle': oracle(args, force=force) elif main_arg == 'balance': balance(args) elif main_arg == 'height': height() elif main_arg == 'spend': if len(args) != 4: print( 'You must specify <amount>, <receipient> and <wallet-path>. ' 'Tip: escape the receipient address in single quotes to make ' 'sure that your shell does not get confused with the dollar-sign') sys.exit(1) password = getpass('Wallet password: '******'Transaction sent. Your balance will change once it was included in ' 'the blockchain.') sys.exit(1) elif main_arg == 'generate': # generate wallet keypair = KeyPair.generate() try: path = popargs(args, '--path') except ValueError: print('You must specify the --path argument') sys.exit(1) keypair.save_to_folder(path) address = keypair.get_address() print('You wallet has been generated:')
# to run this test in other environments set the env vars as specified in the # config.py from aeternity.formatter import pretty_block from aeternity.signing import KeyPair try: # if there are no env vars set for the config, this call will fail Config() except ConfigException: # in this case we create a default config that should work on the dev # machines. Config.set_defaults( Config(external_host=3013, internal_host=3113, websocket_host=3114)) keypair = KeyPair.read_from_dir( '/home/tom/data/aeternity/epoch/_build/dev1/rel/epoch/data/aecore/keys/', 'secret') def random_domain(length=10): rand_str = ''.join( random.choice(string.ascii_letters) for _ in range(length)) return rand_str + '.aet' def test_name_validation_fails(): with raises(ValueError): AEName('test.lol') def test_name_validation_succeeds():