def create(self, request, **kwargs): pub_key = kwargs.get('key') amount = kwargs.get('amount', 100) with redis.lock(f'get_faucet_{pub_key}', expire=120): free_tokens = FaucetTransaction.receivable_tokens(pub_key) actual_tokens = min(amount, free_tokens) config = Config(external_host='epoch:3013', internal_host='epoch:3113', websocket_host='epoch:3114') client = EpochClient(configs=config) # connect with the Epoch node try: # check balance balance = client.get_balance() if balance < actual_tokens: raise ParseError('Faucet is out of cash') client.spend(pub_key, actual_tokens) except AException: raise ParseError('Faucet has no account') FaucetTransaction.objects.create(public_key=pub_key, amount=actual_tokens)
def test_transfer_failure_wrong_pubkey(): client = EpochClient() name = Name(random_domain()) name.full_claim_blocking() client.wait_for_next_block() with raises(AENSException): name.transfer_ownership('ak$deadbeef')
def test_transfer_ownership(): client = EpochClient() name = Name(random_domain()) name.full_claim_blocking() client.wait_for_next_block() name.transfer_ownership( 'ak$3scLu3oJbhsdCJkDjfJ6BUPJ4M9ZZJe57CQ56deSbEXhaTSfG3Wf3i2GYZV6APX7RDDVk4Weewb7oLePte3H3QdBw4rMZw' ) assert name.status == Name.Status.TRANSFERRED
def test_revocation(): domain = random_domain() name = AEName(domain) name.full_claim_blocking(keypair) EpochClient().wait_for_next_block() name.revoke() assert name.status == AEName.Status.REVOKED EpochClient().wait_for_next_block() assert AEName(domain).is_available()
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_name_status_unavailable(): # claim a domain domain = random_domain() occupy_name = Name(domain) occupy_name.full_claim_blocking() # wait for the state to propagate in the block chain EpochClient().wait_for_next_block() same_name = Name(domain) assert not same_name.is_available()
def test_name_update(): client = EpochClient() # claim a domain domain = random_domain() name = AEName(domain) name.full_claim_blocking(keypair) client.wait_for_next_block() client.wait_for_next_block() assert not AEName(domain).is_available(), 'The name should be claimed now' name.update_status() transaction = name.update(keypair, target=client.get_pubkey()) client.wait_for_next_block() name.update_status() assert name.pointers != [], 'Pointers should not be empty' assert name.pointers['account_pubkey'] == client.get_pubkey()
def test_oracle_query_received(): client = EpochClient() weather_oracle = WeatherOracle( query_format="{'city': str}", response_format="{'temp_c': int}", default_query_fee=0, default_fee=10, default_ttl=50, default_query_ttl=2, default_response_ttl=2, ) client.register_oracle(weather_oracle) client.listen_until(weather_oracle.is_ready, timeout=5) weather_query = WeatherQuery( oracle_pubkey=weather_oracle.oracle_id, query_fee=0, fee=10, query_ttl=2, response_ttl=2, ) client.mount(weather_query) weather_query.query("{'city': 'Berlin'}") client.listen_until(lambda: weather_query.response_received, timeout=5)
def test_name_update(): client = EpochClient() # claim a domain domain = random_domain() name = Name(domain) name.full_claim_blocking() name.update(target=client.get_pubkey()) client.wait_for_next_block() name.update_status() assert name.pointers['account_pubkey'] == client.get_pubkey()
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 test_oracle_registration(): client = EpochClient() weather_oracle = WeatherOracle( query_format="{'city': str}", response_format="{'temp_c': int}", default_query_fee=0, default_fee=10, default_ttl=50, default_query_ttl=2, default_response_ttl=2, ) client.register_oracle(weather_oracle) client.listen_until(weather_oracle.is_ready, timeout=5) assert weather_oracle.oracle_id is not None
def __init__(self, code, abi, client=None): if client is None: client = EpochClient() self.client = client self.code = code self.abi = abi
external_host = popargs(args, '--external-host', None) internal_host = popargs(args, '--internal-host', None) websocket_host = popargs(args, '--websocket-host', None) docker = popargs(args, '--docker', False, True) verbose = popargs(args, '--verbose', False, True) if verbose: logging.getLogger().setLevel(logging.DEBUG) config = Config(external_host=external_host, internal_host=internal_host, websocket_host=websocket_host, docker_semantics=docker) client = EpochClient(configs=config) main_arg = args[0] def aens(args, force=False): command = args[1] domain = args[2] try: AEName.validate_name(domain) except AENSException as exc: stderr('Error:', str(exc)) sys.exit(1) name = AEName(domain)
sys.stderr.flush() def prompt(message, skip): if skip: return True if input(message + ' [y/N]') != 'y': print('cancelled') sys.exit(0) args = sys.argv[1:] if len(args) < 2: print_usage() client = EpochClient() system, command = args[:2] # allow using the --no-input parameter anywhere noinput = False if '--no-input' in args: args.remove('--no-input') noinput = True if system == 'aens': domain = args[2] try: Name.validate_name(domain) except InvalidName as exc: stderr('Error:', str(exc))
def test_revocation(): name = Name(random_domain()) name.full_claim_blocking() EpochClient().wait_for_next_block() name.revoke() assert name.status == Name.Status.REVOKED
def test_transfer_ownership(): client = EpochClient() name = AEName(random_domain()) name.full_claim_blocking(keypair) assert name.status == AEName.Status.CLAIMED client.wait_for_next_block() new_key_pair = KeyPair.generate() # put some coins into the account so the account is in the state tree # otherwise it couldn't become the owner of an address. client.spend(keypair, new_key_pair.get_address(), 1) client.wait_for_next_block() # now transfer the name to the other account name.transfer_ownership(keypair, new_key_pair.get_address()) assert name.status == AEName.Status.TRANSFERRED client.wait_for_next_block() # try changing the target using that new keypair name.update_status() name.update(new_key_pair, target=keypair.get_address()) client.wait_for_next_block() name.update_status() assert name.pointers != [], 'Pointers should not be empty' assert name.pointers['account_pubkey'] == new_key_pair.get_address()
def spend(amount, receipient, keypair_folder, password): keypair = KeyPair.read_from_dir(keypair_folder, password) EpochClient().spend(receipient, amount, keypair)
return self._success(ret_data) dev1_config = Config(external_host=3013, internal_host=3113, websocket_host=3114) oraclef_jean = OraclefJean( # example spec (this spec is fictional and will be defined later) query_format='''{'url': 'str', 'jq': 'str'}''', # example spec (this spec is fictional and will be defined later) response_format='''{'status': 'error'|'ok', 'message': 'str', 'data': {}}''', default_ttl=50, default_query_fee=4, default_fee=6, default_query_ttl=10, default_response_ttl=10, ) client = EpochClient(configs=dev1_config) client.register_oracle(oraclef_jean) client.listen_until(oraclef_jean.is_ready) print(f'''You can now query this oracle using the following parameters: oracle_pubkey: {oraclef_jean.oracle_id} query_fee: {oraclef_jean.get_query_fee()} query_ttl: {oraclef_jean.get_query_ttl()} response_ttl: {oraclef_jean.get_response_ttl()} fee: {oraclef_jean.get_fee()} query_format: {oraclef_jean.query_format} ''') print('Oracle ready') client.listen() print('Oracle Stopped')
if default == _no_popargs_default: raise return default external_host = popargs(args, '--external-host', None) internal_host = popargs(args, '--internal-host', None) websocket_host = popargs(args, '--websocket-host', None) config = Config( external_host=external_host, internal_host=internal_host, websocket_host=websocket_host, ) client = EpochClient(configs=config) main_arg = args[0] def aens(args, force=False): command = args[1] domain = args[2] try: AEName.validate_name(domain) except AENSException as exc: stderr('Error:', str(exc)) sys.exit(1) name = AEName(domain)
def test_get_info(): info = EpochClient().get_info() assert type(info) == EpochInfo assert type(info.last_30_blocks_time[0]) == LastBlockInfo assert info.last_30_blocks_time[0].time_delta_to_parent > 0
from aeternity import EpochClient from aeternity import OracleQuery logging.basicConfig(level=logging.DEBUG) class AeternityInUSDOracleQuery(OracleQuery): def on_response(self, message, query): print(query) print(message) dev1_config = Config(external_host=3013, internal_host=3113, websocket_host=3114) client = EpochClient(configs=dev1_config) oracle_pubkey = 'ok$3WRqCYwdr9B5aeAMT7Bfv2gGZpLUdD4RQM4hzFRpRzRRZx7d8pohQ6xviXxDTLHVwWKDbGzxH1xRp19LtwBypFpCVBDjEQ' oracle_query = AeternityInUSDOracleQuery( oracle_pubkey=oracle_pubkey, query_fee=4, query_ttl=10, response_ttl=10, fee=6, ) client.mount(oracle_query) oracle_query.query( json.dumps({ 'url': 'https://api.coinmarketcap.com/v1/ticker/aeternity/?convert=USD', 'jq': '.[0].price_usd',
def setup_module(module): global client client = EpochClient()