Esempio n. 1
0
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})
Esempio n. 2
0
def test_api_get_balance():
    client = EpochClient()
    assert client.get_balance(account_pubkey=PUBLIC_KEY) > 0