Beispiel #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 _epoch_cli():
    try:
        ctx = click.get_current_context()
        # set the default configuration
        Config.set_defaults(
            Config(external_url=ctx.obj.get(CTX_EPOCH_URL),
                   internal_url=ctx.obj.get(CTX_EPOCH_URL_INTERNAL),
                   websocket_url=ctx.obj.get(CTX_EPOCH_URL_WEBSOCKET)))
    except ConfigException as e:
        print("Configuration error: ", e)
        exit(1)
    # load the epoch client
    return EpochClient()
Beispiel #3
0
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)
Beispiel #4
0
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
import logging
import os
from aeternity.config import Config
from aeternity.signing import KeyPair

logging.getLogger("requests").setLevel(logging.DEBUG)
logging.getLogger("urllib3").setLevel(logging.DEBUG)

PUBLIC_KEY = os.environ.get('WALLET_PUB')
PRIVATE_KEY = os.environ.get('WALLET_PRIV')
NODE_URL = os.environ.get('TEST_URL')
NODE_URL_INTERNAL = os.environ.get('TEST_INTERNAL_URL')
EPOCH_VERSION = '0.18.0'
# set the key folder as environment variables
KEYPAIR = KeyPair.from_public_private_key_strings(PUBLIC_KEY, PRIVATE_KEY)

Config.set_defaults(
    Config(external_url=NODE_URL, internal_url=NODE_URL_INTERNAL))
Beispiel #6
0
logging.getLogger("requests").setLevel(logging.DEBUG)
logging.getLogger("urllib3").setLevel(logging.DEBUG)
logging.getLogger("aeternity").setLevel(logging.DEBUG)

PUBLIC_KEY = os.environ.get('WALLET_PUB')
PRIVATE_KEY = os.environ.get('WALLET_PRIV')
NODE_URL = os.environ.get('TEST_URL')
NODE_URL_DEBUG = os.environ.get('TEST_DEBUG_URL')
EPOCH_VERSION = '0.25.0'
# set the key folder as environment variables
genesis = Account.from_public_private_key_strings(PUBLIC_KEY, PRIVATE_KEY)
# default values for tests
TEST_FEE = 1
TEST_TTL = 50

Config.set_defaults(Config(external_url=NODE_URL, internal_url=NODE_URL_DEBUG))

# Instantiate the epoch client for the tests
EPOCH_CLI = epoch.EpochClient(blocking_mode=True, debug=True)
# create a new account and fill it with some money
ACCOUNT = Account.generate()
EPOCH_CLI.spend(genesis, ACCOUNT.get_address(), 100000)
a = EPOCH_CLI.get_account_by_pubkey(pubkey=ACCOUNT.get_address())
print(f"Test account is {ACCOUNT.get_address()} with balance {a.balance}")


@contextmanager
def tempdir():
    # contextmanager to generate and delete a temporary directory
    path = tempfile.mkdtemp()
    try: