def rest_faucet(recipient_address): """top up an account""" # recipient_address = request.form.get("account") # validate the address if len(recipient_address.strip()) < 3 or not is_valid_hash( recipient_address, prefix='ak'): return jsonify({"message": "bad request"}), 400 # genesys key bank_wallet_key = os.environ.get('BANK_WALLET_KEY') kp = KeyPair.from_private_key_string(bank_wallet_key) # target node Config.set_defaults( Config(external_url=os.environ.get('EPOCH_URL', "https://sdk-testnet.aepps.com"))) # amount amount = int(os.environ.get('TOPUP_AMOUNT', 250)) ttl = int(os.environ.get('TX_TTL', 100)) client = EpochClient() tx = client.spend(kp, recipient_address, amount, tx_ttl=ttl) balance = client.get_balance(account_pubkey=recipient_address) logging.info( f"top up accont {recipient_address} of {amount} tx_ttl:{ttl} tx_hash: {tx}" ) return jsonify({"tx_hash": tx, "balance": balance})
def test_name_transfer_ownership(): client = EpochClient() name = AEName(random_domain()) name.full_claim_blocking(keypair, name_ttl=70) 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=new_key_pair.get_address(), name_ttl=10) 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()
from aeternity.epoch import EpochClient from aeternity.config import Config import sys Config.set_defaults(Config(external_host=3013, internal_host=3113, websocket_host=3114)) recipient, amount = sys.argv[1:3] amount = int(amount) epoch = EpochClient() epoch.spend(recipient, amount)
def rest_faucet(recipient_address): """top up an account""" amount = int(os.environ.get('TOPUP_AMOUNT', 250)) ttl = int(os.environ.get('TX_TTL', 100)) try: # validate the address logging.info(f"Top up request for {recipient_address}") if not is_valid_hash(recipient_address, prefix='ak'): return jsonify({"message": "The provided account is not valid"}), 400 # genesys key bank_wallet_key = os.environ.get('FAUCET_ACCOUNT_PRIV_KEY') kp = Account.from_private_key_string(bank_wallet_key) # target node Config.set_defaults( Config( external_url=os.environ.get('EPOCH_URL', "https://sdk-testnet.aepps.com"), internal_url=os.environ.get('EPOCH_URL_DEBUG', "https://sdk-testnet.aepps.com"), network_id=os.environ.get('NETWORK_ID', "ae_devnet"), )) # payload payload = os.environ.get('TX_PAYLOAD', "Faucet Tx") # execute the spend transaction client = EpochClient() _, _, _, tx = client.spend(kp, recipient_address, amount, payload=payload, tx_ttl=ttl) balance = client.get_account_by_pubkey( pubkey=recipient_address).balance logging.info( f"Top up accont {recipient_address} of {amount} tx_ttl: {ttl} tx_hash: {tx} completed" ) # telegram bot notifications enable_telegaram = os.environ.get('TELEGRAM_API_TOKEN', False) if enable_telegaram: token = os.environ.get('TELEGRAM_API_TOKEN', None) chat_id = os.environ.get('TELEGRAM_CHAT_ID', None) node = os.environ.get('EPOCH_URL', "https://sdk-testnet.aepps.com").replace( "https://", "") if token is None or chat_id is None: logging.warning( f"missing chat_id ({chat_id}) or token {token} for telegram integration" ) bot = telegram.Bot(token=token) bot.send_message( chat_id=chat_id, text= f"Account `{recipient_address}` credited with {amount} tokens on `{node}`. (tx hash: `{tx}`)", parse_mode=telegram.ParseMode.MARKDOWN) return jsonify({"tx_hash": tx, "balance": balance}) except OpenAPIClientException as e: logging.error( f"Api error: top up accont {recipient_address} of {amount} failed with error", e) return jsonify({ "message": "The node is temporarily unavailable, contact aepp-dev[at]aeternity.com" }), 503 except Exception as e: logging.error( f"Generic error: top up accont {recipient_address} of {amount} failed with error", e) return jsonify({ "message": "Unknow error, please contact contact aepp-dev[at]aeternity.com" }), 500