Esempio n. 1
0
def set_contract_workspace_dir(contract_workspace_dir=None, is_set=False):
    from termcolor import cprint, colored
    import pathlib

    def tilde(tilde_path):
        return tilde_path.replace("~", str(pathlib.Path.home()))

    def set(contract_workspace_dir):
        if contract_workspace_dir and os.path.exists(
                contract_workspace_dir) and os.path.isdir(
                    contract_workspace_dir):
            map = config_map()
            map[contract_workspace_dir_[0]] = contract_workspace_dir
            write_config_map(map)
            return True

        return False

    if set(contract_workspace_dir):
        return

    current_path_color = "green"
    error_path_color = "red"

    while True:
        map = config_map()
        contract_workspace_dir = None

        if contract_workspace_dir_[0] in map:
            contract_workspace_dir = map[contract_workspace_dir_[0]]
        else:
            contract_workspace_dir = os.path.join(APP_CWD_DIR, CONTRACTS_DIR)

        new_dir = tilde(
            input(
                utils.heredoc('''
            Where do you prefer to keep your smart-contract projects?
            The current location of the is:
            '{}'
            Otherwise, input another existing directory path, or nothing to 
            keep the current one:
            '''.format(colored(contract_workspace_dir, current_path_color))) +
                "\n"))

        if not new_dir:
            new_dir = contract_workspace_dir

        if set(new_dir):
            print("OK")
            break
        else:
            print("\n" + utils.heredoc('''
            The path you entered:
            {}
            doesn't seem to exist!
            ''').format(colored(new_dir, error_path_color)) + "\n")
Esempio n. 2
0
def install(wsl_root=None):
    if wsl_root:
        map = config.config_map()
        map[config.wsl_root_[0]] = wsl_root
        config.write_config_map(map)

    current_path_color = "green"
    error_path_color = "red"

    while True:
        map = config.config_map()
        contract_workspace_dir = None

        if config.contract_workspace_[0] in map:
            contract_workspace_dir = map[config.contract_workspace_[0]]
            _contract_workspace_dir = tilde(
                input(
                    utils.heredoc('''
                Where do you prefer to keep your smart-contract projects?
                The current location is:
                {}
                Input another existing directory path, or nothing to keep the current one:
                ''').format(colored(contract_workspace_dir,
                                    current_path_color)) + "\n"))
        else:
            _contract_workspace_dir = tilde(
                input(
                    utils.heredoc('''
                Where do you prefer to keep your smart-contract projects?
                Input an existing directory path:
                ''') + "\n"))
        if not _contract_workspace_dir:
            _contract_workspace_dir = contract_workspace_dir

        if _contract_workspace_dir and os.path.exists(
                _contract_workspace_dir) and os.path.isdir(
                    _contract_workspace_dir):
            map = config.config_map()
            map[config.contract_workspace_[0]] = _contract_workspace_dir
            config.write_config_map(map)
            print()
            break

        print("\n" + utils.heredoc('''
        The path you entered:
        {}
        doesn't seem to exist!
        ''').format(colored(_contract_workspace_dir, error_path_color)) + "\n")
Esempio n. 3
0
    def __init__(self, header, js, is_verbose=1):
        self.out_msg = None
        self.err_msg = None
        self.json = None
        self.is_verbose = is_verbose
        cl = ["node", "-e"]
        js = header + "\n" + utils.heredoc(js)

        cl.append(js)

        set_local_nodeos_address_if_none()
        # cl.extend(["--url", setup.nodeos_address()])

        if setup.is_print_command_line:
            print("javascript:")
            print("___________")
            print("")
            print(js)
            print("")

        process = subprocess.run(cl,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)

        self.err_msg = process.stderr.decode("utf-8")
        if self.err_msg:
            raise errors.Error(self.err_msg)

        self.out_msg = process.stdout.decode("utf-8")
        self.json = json.loads(self.out_msg)

        self.printself()
Esempio n. 4
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()}
Esempio n. 5
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)
    }
Esempio n. 6
0
    def __init__(self, js):
        self.json = None
        cl = ["node", "-e"]
        js = utils.heredoc(js)
        cl.append(js)

        if setup.is_print_command_line:
            print("javascript:")
            print("___________")
            print("")
            print(js)
            print("")

        process = subprocess.run(cl,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
        err_msg = process.stderr.decode("utf-8")
        if err_msg:
            raise errors.Error(err_msg)

        self.json = json.loads(process.stdout.decode("utf-8"))
Esempio n. 7
0
def set_contract_workspace_dir(contract_workspace_dir=None, is_set=False):
    import pathlib

    def tilde(tilde_path):
        return tilde_path.replace("~", str(pathlib.Path.home()))

    def set(contract_workspace_dir):
        if contract_workspace_dir:
            path = utils.wslMapWindowsLinux(contract_workspace_dir)
            if os.path.exists(path) and os.path.isdir(path):
                map = config_map()
                map[contract_workspace_dir_[0]] = path
                write_config_map(map)
                return True

        return False

    if set(contract_workspace_dir):
        return

    current_path_color = "green"
    error_path_color = "red"

    while True:
        map = config_map()
        contract_workspace_dir = None

        if contract_workspace_dir_[0] in map:
            contract_workspace_dir = map[contract_workspace_dir_[0]]
        else:
            contract_workspace_dir = os.path.join(TMP, CONTRACTS_DIR)

        input_msg = utils.heredoc('''
Where do you prefer to keep your smart-contract projects?
The current location is:
    {}
Otherwise, input another existing directory path, or nothing to 
keep the current one:
            '''.format(
            logger.colored(contract_workspace_dir, current_path_color)
        )) if os.path.exists(contract_workspace_dir) else utils.heredoc('''
Where do you prefer to keep your smart-contract projects?
The set location is:
    {}
but it does not exist. Input an existing directory path:
            '''.format(
            logger.colored(contract_workspace_dir, current_path_color)))

        new_dir = tilde(input(input_msg + "\n"))

        if not new_dir:
            new_dir = contract_workspace_dir

        if set(new_dir):
            print("OK")
            break
        else:
            print("\n" + utils.heredoc('''
The path you entered:
    {}
doesn't seem to exist!
            ''').format(logger.colored(new_dir, error_path_color)) + "\n")
Esempio n. 8
0
def install(wsl_root=None):
    if wsl_root:
        map = config.config_map()
        map[config.wsl_root_[0]] = wsl_root
        config.write_config_map(map)

    current_path_color = "green"
    error_path_color = "red"

    while True:
        map = config.config_map()
        eosio_repository_dir = None

        if config.eosio_repository_dir_[0] in map:
            eosio_repository_dir = map[config.eosio_repository_dir_[0]]
            _eosio_repository_dir = tilde(
                input(
                    utils.heredoc('''
                Where is the EOSIO repository located on your machine?
                The current location is:
                {}
                Input another existing directory path, or nothing to keep the current one:
                ''').format(colored(eosio_repository_dir, current_path_color))
                    + "\n"))
        else:
            _eosio_repository_dir = tilde(
                input(
                    utils.heredoc('''
                Where is the EOSIO repository located on your machine?
                Input an existing directory path:
                ''') + "\n"))

        if not _eosio_repository_dir:
            _eosio_repository_dir = eosio_repository_dir

        ok = _eosio_repository_dir and os.path.exists(
            os.path.join(_eosio_repository_dir, config.node_exe_[1][0]))

        if ok:
            map = config.config_map()
            map[config.eosio_repository_dir_[0]] = _eosio_repository_dir
            config.write_config_map(map)
            print()
            break

        print("\n" + utils.heredoc('''
        The path you entered:
        {}
        doesn't seem to be correct! EOSIO executables are not detected there.
        ''').format(colored(_eosio_repository_dir, error_path_color)) + "\n")

    while True:
        map = config.config_map()
        contract_workspace_dir = None

        if config.contract_workspace_[0] in map:
            contract_workspace_dir = map[config.contract_workspace_[0]]
            _contract_workspace_dir = tilde(
                input(
                    utils.heredoc('''
                Where do you prefer to keep your smart-contract projects?
                The current location is:
                {}
                Input another existing directory path, or nothing to keep the current one:
                ''').format(colored(contract_workspace_dir,
                                    current_path_color)) + "\n"))
        else:
            _contract_workspace_dir = tilde(
                input(
                    utils.heredoc('''
                Where do you prefer to keep your smart-contract projects?
                Input an existing directory path:
                ''') + "\n"))
        if not _contract_workspace_dir:
            _contract_workspace_dir = contract_workspace_dir

        if _contract_workspace_dir and os.path.exists(
                _contract_workspace_dir) and os.path.isdir(
                    _contract_workspace_dir):
            map = config.config_map()
            map[config.contract_workspace_[0]] = _contract_workspace_dir
            config.write_config_map(map)
            print()
            break

        print("\n" + utils.heredoc('''
        The path you entered:
        {}
        doesn't seem to exist!
        ''').format(colored(_contract_workspace_dir, error_path_color)) + "\n")
Esempio n. 9
0
            contract_dir = os.path.join(con_dir,
                                        eosio_build_contracts_src_sub_dir)
        return is_ok

    if ok(eosio_contracts_src_dir):
        break

    if EOSIO_CONTRACTS in map:
        eosio_contracts_src_dir = map[EOSIO_CONTRACTS]
        if ok(eosio_contracts_src_dir):
            break

    eosio_contracts_src_dir = input(
        colored(
            utils.heredoc('''
        Where is 'eosio.contracts` repository located on your machine?
        Input an existing directory path:
        ''') + "\n", prompt_color))

    eosio_contracts_src_dir.replace("~", str(pathlib.Path.home()))

    if ok(eosio_contracts_src_dir):
        map[EOSIO_CONTRACTS] = eosio_contracts_src_dir
        config.write_config_map(map)
        print()
        break

    print("\n" + utils.heredoc('''
    The path you entered:
    {}
    doesn't seem to be correct!
    directory --