Exemplo 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})
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
 def __init__(self, config=None):
     if config is None:
         config = Config.get_default()
     self._config = config
     self._listeners = defaultdict(list)
     self._connection = Connection(config=config)
     self._top_block = None
Exemplo n.º 4
0
 def __init__(self, *, configs=None, retry=True):
     if configs is None:
         configs = Config.get_defaults()
     if isinstance(configs, Config):
         configs = [configs]
     self._configs = configs
     self._active_config_idx = 0
     self._listeners = defaultdict(list)
     self._connection = self._make_connection()
     self._top_block = None
     self._retry = retry
Exemplo n.º 5
0
    def __init__(self, *, configs=None, retry=True):
        if configs is None:
            configs = Config.get_defaults()
        if isinstance(configs, Config):
            configs = [configs]
        self._configs = configs
        self._active_config_idx = 0
        self._listeners = defaultdict(list)
        self._connection = self._make_connection()
        self._top_block = None
        self._retry = retry

        # instantiate the request client
        self.cli = OpenAPICli(configs[0].api_url, configs[0].api_url_internal)
Exemplo n.º 6
0
logging.basicConfig(level=logging.DEBUG)


class WeatherOracle(Oracle):
    query_format = 'weather_query2'
    response_format = 'weather_resp2'
    default_query_fee = 4
    default_fee = 6
    default_query_ttl = 10
    default_response_ttl = 10

    def get_reply(self, message):
        return '26 C'


dev1_config = Config(local_port=3013, internal_port=3113, websocket_port=3114)

weather_oracle = WeatherOracle()
client = EpochClient(config=dev1_config)
client.register_oracle(weather_oracle)
print(f'''You can now query this oracle using the following parameters:
    oracle_pub_key: {client.get_pub_key()}
    query_fee: {weather_oracle.get_query_fee()}
    query_ttl: {weather_oracle.get_query_ttl()}
    response_ttl: {weather_oracle.get_response_ttl()}
    fee: {weather_oracle.get_fee()}
    query_format: {weather_oracle.query_format}
''')
print('Oracle ready')
client.run()
print('Oracle Stopped')
Exemplo n.º 7
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)
Exemplo n.º 8
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
Exemplo n.º 9
0
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))
Exemplo n.º 10
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:
Exemplo n.º 11
0
from aeternity.aens import Name
from aeternity.config import Config

Config.set_default(
    Config(local_port=3013, internal_port=3113, websocket_port=3114))

name = Name('foobar.aet')
if name.is_available():
    name.preclaim()
    name.claim_blocking()
    name.update(target='ak$deadbeef')