コード例 #1
0
    def create(self, request, **kwargs):
        pub_key = kwargs.get('key')
        amount = kwargs.get('amount', 100)

        with redis.lock(f'get_faucet_{pub_key}', expire=120):

            free_tokens = FaucetTransaction.receivable_tokens(pub_key)
            actual_tokens = min(amount, free_tokens)

            config = Config(external_host='epoch:3013',
                            internal_host='epoch:3113',
                            websocket_host='epoch:3114')
            client = EpochClient(configs=config)  # connect with the Epoch node
            try:
                # check balance
                balance = client.get_balance()
                if balance < actual_tokens:
                    raise ParseError('Faucet is out of cash')

                client.spend(pub_key, actual_tokens)
            except AException:
                raise ParseError('Faucet has no account')

            FaucetTransaction.objects.create(public_key=pub_key,
                                             amount=actual_tokens)
コード例 #2
0
def get_aeternity():
    """get the epoch client and the genesis keypair from config"""
    # configure epoch client in case we need it

    epoch = EpochClient(configs=Config(external_host=epoch_node,
                                       internal_host=f"{epoch_node}/internal",
                                       secure_connection=True))

    logging.info(f"using node at {epoch_node}")

    # load the genesis keypair
    gp = bar_wallet_address
    gk = bar_wallet_private
    main_wallet = KeyPair.from_public_private_key_strings(gp, gk)

    return epoch, main_wallet
コード例 #3
0
    def create(self, request, **kwargs):
        pub_key = request.data.get('key')
        amount = request.data.get('amount', 100)

        with redis.lock(f'get_faucet_{pub_key}', timeout=5):

            free_coins = FaucetTransaction.receivable_tokens(pub_key)
            actual_coins = min(amount, free_coins)

            if actual_coins > 0:
                epoch_host = settings.EPOCH_HOST
                config = Config(
                    external_host=f'{epoch_host}:3013',
                    internal_host=f'{epoch_host}:3113',
                    websocket_host=f'{epoch_host}:3114'
                )

                # connect with the Epoch node
                client = EpochClient(configs=config)

                key_pair = KeyPair.read_from_dir(
                    settings.EPOCH_KEYS,
                    settings.EPOCH_PASSWORD
                )
                try:
                    # check balance
                    balance = client.get_balance()
                    if balance < actual_coins:
                        raise ParseError('Faucet is out of cash')
                except AException:
                    raise ParseError('Faucet has no account')

                try:
                    client.spend(pub_key, int(actual_coins), key_pair)
                except AException:
                    raise ParseError(f'Spend TX failed Amount {actual_coins}')

                FaucetTransaction.objects.create(
                    public_key=pub_key,
                    amount=actual_coins
                )
            elif amount > 0:
                raise ParseError('Your hourly/daily rate has been reached')

        return JsonResponse({'spent': actual_coins})
コード例 #4
0
from aeternity import Config
from aeternity import EpochClient
from aeternity import OracleQuery

logging.basicConfig(level=logging.DEBUG)


class AeternityInUSDOracleQuery(OracleQuery):
    def on_response(self, message, query):
        print(query)
        print(message)


dev1_config = Config(external_host=3013,
                     internal_host=3113,
                     websocket_host=3114)
client = EpochClient(configs=dev1_config)
oracle_pubkey = 'ok$3WRqCYwdr9B5aeAMT7Bfv2gGZpLUdD4RQM4hzFRpRzRRZx7d8pohQ6xviXxDTLHVwWKDbGzxH1xRp19LtwBypFpCVBDjEQ'

oracle_query = AeternityInUSDOracleQuery(
    oracle_pubkey=oracle_pubkey,
    query_fee=4,
    query_ttl=10,
    response_ttl=10,
    fee=6,
)
client.mount(oracle_query)
oracle_query.query(
    json.dumps({
        'url':
コード例 #5
0
        idx = d.index(key)
        d.pop(idx)  # remove arg
        return d.pop(idx)  # remove value after arg
    except ValueError:
        if default == _no_popargs_default:
            raise
        return default


external_host = popargs(args, '--external-host', None)
internal_host = popargs(args, '--internal-host', None)
websocket_host = popargs(args, '--websocket-host', None)

config = Config(
    external_host=external_host,
    internal_host=internal_host,
    websocket_host=websocket_host,
)

client = EpochClient(configs=config)

main_arg = args[0]


def aens(args, force=False):
    command = args[1]
    domain = args[2]
    try:
        AEName.validate_name(domain)
    except AENSException as exc:
        stderr('Error:', str(exc))
コード例 #6
0
ファイル: test_aens.py プロジェクト: devsnd/dev-tools
import random
import string

from pytest import raises

from aeternity import Config, EpochClient
from aeternity.aens import InvalidName, Name, AENSException
from aeternity.config import ConfigException

# to run this test in other environments set the env vars as specified in the
# config.py
try:
    # if there are no env vars set for the config, this call will fail
    Config()
except ConfigException:
    # in this case we create a default config that should work on the dev
    # machines.
    Config.set_default(
        Config(local_port=3013, internal_port=3113, websocket_port=3114))


def random_domain(length=10):
    rand_str = ''.join(
        random.choice(string.ascii_letters) for _ in range(length))
    return rand_str + '.aet'


def test_name_validation_fails():
    with raises(InvalidName):
        Name('test.lol')
コード例 #7
0
import random
import string

import logging
logger = logging.getLogger(__name__)

from aeternity import Config, EpochClient, Oracle, OracleQuery
from aeternity.config import ConfigException

# to run this test in other environments set the env vars as specified in the
# config.py
try:
    # if there are no env vars set for the config, this call will fail
    Config()
except ConfigException:
    # in this case we create a default config that should work on the dev
    # machines.
    Config.set_defaults(
        Config(external_host='localhost:3013',
               internal_host='localhost:3113',
               websocket_host='localhost:3114'))

logging.basicConfig(level=logging.DEBUG)


class WeatherOracle(Oracle):
    def get_response(self, message):
        query = message['payload']['query']
        logger.debug('Received query %s' % query)
        response = "{'temp_c': 30}"  # nice and sunny
        logger.debug('Sending back %s' % str(response))
コード例 #8
0
            return False
        else:
            raise


external_host = popargs(args, '--external-host', None)
internal_host = popargs(args, '--internal-host', None)
websocket_host = popargs(args, '--websocket-host', None)
docker = popargs(args, '--docker', False, True)
verbose = popargs(args, '--verbose', False, True)

if verbose:
    logging.getLogger().setLevel(logging.DEBUG)

config = Config(external_host=external_host,
                internal_host=internal_host,
                websocket_host=websocket_host,
                docker_semantics=docker)

client = EpochClient(configs=config)

main_arg = args[0]


def aens(args, force=False):
    command = args[1]
    domain = args[2]
    try:
        AEName.validate_name(domain)
    except AENSException as exc:
        stderr('Error:', str(exc))
        sys.exit(1)
コード例 #9
0
import pytest
from pytest import raises, skip

from aeternity import Config, EpochClient
from aeternity.aens import AEName, AENSException
from aeternity.config import ConfigException

# to run this test in other environments set the env vars as specified in the
# config.py
from aeternity.formatter import pretty_block
from aeternity.signing import KeyPair

try:
    # if there are no env vars set for the config, this call will fail
    Config()
except ConfigException:
    # in this case we create a default config that should work on the dev
    # machines.
    Config.set_defaults(
        Config(external_host=3013, internal_host=3113, websocket_host=3114))

keypair = KeyPair.read_from_dir(
    '/home/tom/data/aeternity/epoch/_build/dev1/rel/epoch/data/aecore/keys/',
    'secret')


def random_domain(length=10):
    rand_str = ''.join(
        random.choice(string.ascii_letters) for _ in range(length))
    return rand_str + '.aet'