Пример #1
0
def verify_testnet_production():
    result = is_head_block_num()
    domain = "LOCAL" if is_local_testnet() else "REMOTE"
    if not result:
        raise errors.Error('''
        {} testnet is not running or is not responding @ {}.
        '''.format(domain, setup.nodeos_address()))
    else:
        logger.INFO('''
        {} testnet is active @ {}.
        '''.format(domain, setup.nodeos_address()))
    return result
Пример #2
0
def set_local_nodeos_address_if_none():
    if not setup.nodeos_address():
        setup.set_nodeos_address(
            "http://" + config.http_server_address())
        setup.is_local_address = True

    return setup.is_local_address
Пример #3
0
def config_rpc():
    code = utils.heredoc('''
const eosjs = require('eosjs');
const fetch = require('node-fetch');
const rpc = new eosjs.Rpc.JsonRpc('%(endpoint)s', { fetch });
    ''')

    return code % {'endpoint': setup.nodeos_address()}
Пример #4
0
    def __init__(self, args, first, second, is_verbose=True):
        self.out_msg = None
        self.out_msg_details = None
        self.err_msg = None
        self.json = {}
        self.is_verbose = is_verbose

        cl = [config.cli_exe()]
        set_local_nodeos_address_if_none()
        cl.extend(["--url", setup.nodeos_address()])

        if setup.is_print_request:
            cl.append("--print-request")
        if setup.is_print_response:
            cl.append("--print-response")

        cl.append(first)
        cl.extend(re.sub(re.compile(r'\s+'), ' ', second.strip()).split(" "))
        cl.extend(args)
        self.args = args

        if setup.is_print_command_line:
            print("command line sent to cleos:")
            print(" ".join(cl))
            print("")

        while True:
            process = subprocess.run(
                cl,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                cwd=str(pathlib.Path(config.cli_exe()).parent)) 

            self.out_msg = process.stdout.decode("ISO-8859-1")
            self.out_msg_details = process.stderr.decode("ISO-8859-1")
            self.err_msg = None
            error_key_words = ["ERROR", "Error", "error", "Failed"]
            for word in error_key_words:
                if word in self.out_msg_details:
                    self.err_msg = self.out_msg_details
                    self.out_msg_details = None
                    break

            if not self.err_msg or self.err_msg and \
                    not "Transaction took too long" in self.err_msg:
                break

        errors.validate(self)
            
        try:
            self.json = json.loads(self.out_msg)
        except:
            pass

        try:
            self.json = json.loads(self.out_msg_details)
        except:
            pass        
Пример #5
0
def resume(nodeos_stdout=None, verbosity=None):
    ''' Resume the EOSIO local node.
    ''' 
    if not cleos.set_local_nodeos_address_if_none():   
        logger.INFO('''
            Not local nodeos is set: {}
        '''.format(setup.nodeos_address()), verbosity)

    node_start(nodeos_stdout=nodeos_stdout, verbosity=verbosity)
Пример #6
0
def status():
    '''
    Display EOS node status.
    '''

    logger.INFO('''
    ######### Node ``{}``, head block number ``{}``.
    '''.format(setup.nodeos_address(),
               cleos_get.GetInfo(is_verbose=0).head_block))
Пример #7
0
def verify_testnet_production():
    head_block_num = 0
    try: # if running, json is produced
        head_block_num = cleos_get.GetInfo(is_verbose=False).head_block
    except:
        pass

    domain = "LOCAL" if is_local_testnet() else "REMOTE"
    if not head_block_num:
        raise errors.Error('''
        {} testnet is not running or is not responding @ {}.
        '''.format(domain, setup.nodeos_address()))
    else:
        logger.INFO('''
        {} testnet is active @ {}.
        '''.format(domain, setup.nodeos_address()))

    return head_block_num
Пример #8
0
def reset(nodeos_stdout=None):
    ''' Start clean the local EOSIO node.

    The procedure addresses problems with instabilities of EOSIO *nodeos* 
    executable: it happens that it blocks itself on clean restart. 

    The issue is patched with one subsequent restart if the first attempt 
    fails. However, it happens that both launches fail, rarely due to 
    instability of *nodeos*, sometimes because of misconfiguration.

    When both launch attempts fail, an exception routine passes. At first,
    the command line is printed, for *example*::

        ERROR:
        The local ``nodeos`` failed to start twice in sequence. Perhaps, something is
        wrong with configuration of the system. See the command line issued:

        /usr/bin/nodeosx 
        --http-server-address 127.0.0.1:8888 
        --data-dir /mnt/c/Workspaces/EOS/eosfactory/localnode/ 
        --config-dir /mnt/c/Workspaces/EOS/eosfactory/localnode/ 
        --chain-state-db-size-mb 200 --contracts-console --verbose-http-errors --enable-stale-production --producer-name eosio 
        --signature-provider EOS6MRyAjQq8ud7hVNYcfnVPJqcVpscN5So8BhtHuGYqET5GDW5CV=KEY:5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 
        --plugin eosio::producer_plugin 
        --plugin eosio::chain_api_plugin 
        --plugin eosio::http_plugin 
        --plugin eosio::history_api_plugin 
        --genesis-json /mnt/c/Workspaces/EOS/eosfactory/localnode/genesis.json
        --delete-all-blocks

    Next, the command line is executed, for *example*::

        Now, see the result of an execution of the command line.
        /bin/sh: 1: /usr/bin/nodeosx: not found

    The exemplary case is easy, it explains itself. Generally, the command 
    line given can be executed in a *bash* terminal separately, in order to 
    understand a problem.

    Args:
        nodeos_stdout (str): If set, a file where *stdout* stream of
            the local *nodeos* is send. Note that the file can be included to 
            the configuration of EOSFactory, see :func:`.core.config.nodeos_stdout`.
            If the file is set with the configuration, and in the same time 
            it is set with this argument, the argument setting prevails. 
    '''

    if not cleos.set_local_nodeos_address_if_none():
        logger.INFO('''
        No local nodeos is set: {}
        '''.format(setup.nodeos_address()))

    import eosfactory.shell.account as account
    teos.keosd_start()
    account.reboot()
    clear_testnet_cache()
    node_start(clear=True, nodeos_stdout=nodeos_stdout)
Пример #9
0
def status():
    '''
    Display EOS node status.
    '''
    get_info = cleos.GetInfo(is_verbose=0)

    logger.INFO('''
    ######### Node ``{}``, head block number ``{}``.
    '''.format(
        setup.nodeos_address(),
        get_info.json["head_block_num"]))
Пример #10
0
def reset(verbosity=None):
    ''' Start clean the EOSIO local node.
    '''
    if not cleos.set_local_nodeos_address_if_none():
        logger.INFO('''
        No local nodeos is set: {}
        '''.format(setup.nodeos_address()), verbosity)

    import eosfactory.shell.account as account
    account.reboot()
    clear_testnet_cache()
    teos.node_start(clear=True, verbosity=verbosity)
Пример #11
0
    def __init__(self, args, first, second, is_verbose=True):
        self.out_msg = None
        self.out_msg_details = None
        self.err_msg = None
        self.json = {}
        self.is_verbose = is_verbose

        cl = [config.cli_exe()]
        set_local_nodeos_address_if_none()
        cl.extend(["--url", setup.nodeos_address()])

        if setup.is_print_request:
            cl.append("--print-request")
        if setup.is_print_response:
            cl.append("--print-response")

        cl.extend([first, second])
        cl.extend(args)
        self.args = args

        if setup.is_print_command_line:
            print("command line sent to cleos:")
            print(" ".join(cl))
            print("")

        process = subprocess.run(cl,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE,
                                 cwd=str(
                                     pathlib.Path(config.cli_exe()).parent))

        self.out_msg = process.stdout.decode("utf-8")
        self.out_msg_details = process.stderr.decode("utf-8")
        error_key_words = ["ERROR", "Error", "error", "Failed"]
        for word in error_key_words:
            if word in self.out_msg_details:
                self.err_msg = self.out_msg_details
                self.out_msg_details = None
                break

        errors.validate(self)

        try:
            self.json = json.loads(self.out_msg)
        except:
            pass

        try:
            self.json = json.loads(self.out_msg_details)
        except:
            pass
Пример #12
0
def resume(nodeos_stdout=None):
    ''' Resume the local EOSIO node.

    Args:
        nodeos_stdout (str): If set, a file where *stdout* stream of
            the local *nodeos* is send. Note that the file can be included to 
            the configuration of EOSFactory, see :func:`.core.config.nodeos_stdout`.
            If the file is set with the configuration, and in the same time 
            it is set with this argument, the argument setting prevails. 
    '''
    if not cleos.set_local_nodeos_address_if_none():
        logger.INFO('''
            Not local nodeos is set: {}
        '''.format(setup.nodeos_address()))

    node_start(nodeos_stdout=nodeos_stdout)
Пример #13
0
def config_api():
    code = utils.heredoc('''
const eosjs = require('eosjs')
const fetch = require('node-fetch')
const rpc = new eosjs.Rpc.JsonRpc('%(endpoint)s', { fetch })

const { TextDecoder, TextEncoder } = require('text-encoding');
const signatureProvider = new eosjs.SignatureProvider(%(keys)s);
const api = new eosjs.Api({ rpc, signatureProvider, 
    textDecoder: new TextDecoder, textEncoder: new TextEncoder });
    ''')

    return code % {
        'endpoint': setup.nodeos_address(),
        'keys': json.dumps(wm.private_keys(is_verbose=False), indent=4)
    }