Exemple #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})
def wallet_save(ctx, private_key):
    try:
        kp = KeyPair.from_private_key_string(private_key)
        kf = ctx.obj.get(CTX_KEY_PATH)
        if os.path.exists(kf):
            click.confirm(f'Key file {kf} already exists, overwrite?',
                          abort=True)
        password = click.prompt("Enter the wallet password",
                                default='',
                                hide_input=True)
        kp.save_to_file(kf, password)
        _pp([('Wallet address', kp.get_address()),
             ('Wallet path', os.path.abspath(kf))],
            title='Wallet saved')
    except Exception as e:
        _ppe(e)