Example #1
0
def start_as_rest_server(args):
    peer_port = args.port
    channel = conf.LOOPCHAIN_DEFAULT_CHANNEL
    amqp_key = args.amqp_key or conf.AMQP_KEY
    api_port = int(peer_port) + conf.PORT_DIFF_REST_SERVICE_CONTAINER

    from iconrpcserver.default_conf.icon_rpcserver_config import default_rpcserver_config
    from iconrpcserver.icon_rpcserver_cli import start_process, find_procs_by_params
    from iconcommons.icon_config import IconConfig
    from iconcommons.logger import Logger

    additional_conf = {
        "log": {
            "logger": "iconrpcserver",
            "colorLog": True,
            "level": "info",
            "filePath": "./log/iconrpcserver.log",
            "outputType": "console|file"
        },
        "channel": channel,
        "port": api_port,
        "amqpKey": amqp_key,
        "gunicornWorkerCount": 1,
        "tbearsMode": False
    }

    rpcserver_conf = IconConfig("", default_rpcserver_config)
    rpcserver_conf.load()
    rpcserver_conf.update_conf(additional_conf)
    Logger.load_config(rpcserver_conf)

    if not find_procs_by_params(api_port):
        start_process(conf=rpcserver_conf)
        Logger.info("start_command done!, IconRpcServerCli")
    def open(
        self,
        config_path: str,
        fee: bool = True,
        audit: bool = True,
        deployer_whitelist: bool = False,
        score_package_validator: bool = False,
        builtin_score_owner: str = "",
    ):
        conf = IconConfig("", default_icon_config)

        if config_path != "":
            conf.load(config_path)

        conf.update_conf({
            "builtinScoreOwner": builtin_score_owner,
            "service": {
                "fee": fee,
                "audit": audit,
                "scorePackageValidator": score_package_validator,
                "deployerWhiteList": deployer_whitelist,
            },
        })

        Logger.load_config(conf)
        self._engine.open(conf)
Example #3
0
    def get_icon_conf(command: str, project: str = None, args: dict = None):
        """Load config file using IconConfig instance
        config file is loaded as below priority
        system config -> default config -> user config -> user input config (higher priority)

        :param command: command name (e.g. deploy)
        :param project: project name (in case of deploy)
        :param args: user input command (converted to dictionary type)
        :return: command configuration
        """
        # load configurations
        conf = IconConfig(FN_CLI_CONF, copy.deepcopy(tbears_cli_config))

        if project is not None:
            conf['project'] = project

        # load config file
        conf.load(config_path=args.get('config', None) if args else None)

        # move command config
        if command in conf:
            conf.update_conf(conf[command])
            del conf[command]

        # load user argument
        if args:
            conf.update_conf(args)

        return conf
Example #4
0
    def get_icon_conf(command: str, args: dict = None) -> dict:
        """Load config file using IconConfig instance
        config file is loaded as below priority
        system config -> default config -> user config -> user input config (higher priority)

        :param command: command name (e.g. start)
        :param args: user input command (converted to dictionary type)
        :return: command configuration
        """
        # load configurations
        conf = IconConfig(FN_SERVER_CONF, copy.deepcopy(tbears_server_config))
        # load config file
        conf.load(config_path=args.get('config', None) if args else None)

        # move command config
        if command in conf:
            conf.update_conf(conf[command])
            del conf[command]

        # load user argument
        if args:
            conf.update_conf(args)

        # add default configuration file
        if args.get('config', None) is None:
            if os.path.exists(FN_SERVER_CONF):
                conf['config'] = FN_SERVER_CONF

        return conf
Example #5
0
def main():
    # Parse arguments.
    try:
        parser = create_parser()
    except Exception as e:
        exit(f"Argument parsing exception : {e}")

    args = parser.parse_args(sys.argv[1:])

    if args.config:
        conf_path = args.config
        if not IconConfig.valid_conf_path(conf_path):
            print(f'Invalid configuration file : {conf_path}')
            sys.exit(1)
    else:
        conf_path = str()

    # Load configuration
    conf = IconConfig(conf_path, tbears_server_config)
    conf.load()
    conf.update_conf(dict(vars(args)))
    Logger.load_config(conf)
    Logger.print_config(conf, TBEARS_BLOCK_MANAGER)

    setproctitle.setproctitle(f'{TBEARS_BLOCK_MANAGER}.{conf[TConfigKey.CHANNEL]}.{conf[TConfigKey.AMQP_KEY]}')

    # run block_manager service
    block_manager = BlockManager(conf=conf)
    block_manager.serve()

    Logger.info('===============tbears block_manager done================', TBEARS_BLOCK_MANAGER)
Example #6
0
def main():

    # Response server name as loopchain, not gunicorn.
    gunicorn.SERVER_SOFTWARE = 'loopchain'

    # Parse arguments.
    parser = argparse.ArgumentParser()
    parser.add_argument("-p",
                        type=str,
                        dest=ConfigKey.PORT,
                        default=None,
                        help="rest_proxy port")
    parser.add_argument("-c",
                        type=str,
                        dest=ConfigKey.CONFIG,
                        default=None,
                        help="json configure file path")

    args = parser.parse_args()

    conf_path = args.config

    if conf_path is not None:
        if not IconConfig.valid_conf_path(conf_path):
            print(f'invalid config file : {conf_path}')
            sys.exit(ExitCode.COMMAND_IS_WRONG.value)
    if conf_path is None:
        conf_path = str()

    conf = IconConfig(conf_path, default_rpcserver_config)
    conf.load()
    conf.update_conf(dict(vars(args)))
    Logger.load_config(conf)

    _run_async(_run(conf))
Example #7
0
    def setUp(self):
        self._state_db_root_path = '.db'
        self._score_root_path = '.score'

        rmtree(self._score_root_path)
        rmtree(self._state_db_root_path)

        engine = IconServiceEngine()
        conf = IconConfig("", default_icon_config)
        conf.load()
        conf.update_conf({
            ConfigKey.BUILTIN_SCORE_OWNER:
            str(create_address(AddressPrefix.EOA)),
            ConfigKey.SCORE_ROOT_PATH:
            self._score_root_path,
            ConfigKey.STATE_DB_ROOT_PATH:
            self._state_db_root_path
        })
        # engine._load_builtin_scores = Mock()
        # engine._init_global_value_by_governance_score = Mock()
        engine.open(conf)
        self._engine = engine

        self._genesis_address = create_address(AddressPrefix.EOA)
        self._treasury_address = create_address(AddressPrefix.EOA)
        self._governance_score_address =\
            Address.from_string('cx0000000000000000000000000000000000000001')

        self.from_ = self._genesis_address
        self._to = create_address(AddressPrefix.EOA)
        self._icon_score_address = create_address(AddressPrefix.CONTRACT)
        self._total_supply = 100 * 10**18

        accounts = [{
            'name': 'god',
            'address': self._genesis_address,
            'balance': self._total_supply
        }, {
            'name': 'treasury',
            'address': self._treasury_address,
            'balance': 0
        }]

        block = Block(0, create_block_hash(), 0, None)
        tx = {
            'method': '',
            'params': {
                'txHash': create_tx_hash()
            },
            'genesisData': {
                'accounts': accounts
            }
        }
        tx_lists = [tx]

        self._engine.invoke(block, tx_lists)
        self._engine.commit(block)
        self.genesis_block = block
Example #8
0
def main():

    # Response server name as loopchain, not gunicorn.
    gunicorn.SERVER_SOFTWARE = 'loopchain'

    # Parse arguments.
    parser = argparse.ArgumentParser()
    parser.add_argument("-p",
                        type=str,
                        dest=ConfigKey.PORT,
                        default=None,
                        help="rest_proxy port")
    parser.add_argument("-c",
                        type=str,
                        dest=ConfigKey.CONFIG,
                        default=None,
                        help="json configure file path")
    parser.add_argument("-at",
                        type=str,
                        dest=ConfigKey.AMQP_TARGET,
                        default=None,
                        help="amqp target info [IP]:[PORT]")
    parser.add_argument(
        "-ak",
        type=str,
        dest=ConfigKey.AMQP_KEY,
        default=None,
        help=
        "key sharing peer group using queue name. use it if one more peers connect one MQ"
    )
    parser.add_argument("-ch",
                        dest=ConfigKey.CHANNEL,
                        default=None,
                        help="icon score channel")
    parser.add_argument("-tbears",
                        dest=ConfigKey.TBEARS_MODE,
                        action='store_true',
                        help="tbears mode")

    args = parser.parse_args()

    conf_path = args.config

    if conf_path is not None:
        if not IconConfig.valid_conf_path(conf_path):
            print(f'invalid config file : {conf_path}')
            sys.exit(ExitCode.COMMAND_IS_WRONG.value)
    if conf_path is None:
        conf_path = str()

    conf = IconConfig(conf_path, default_rpcserver_config)
    conf.load()
    conf.update_conf(dict(vars(args)))
    Logger.load_config(conf)

    _run_async(_check_rabbitmq(conf[ConfigKey.AMQP_TARGET]))
    _run_async(_run(conf))
Example #9
0
    def load_config(config: 'IconConfig' = None,
                    config_path: Optional[str] = None) -> None:
        if config is None:
            conf = IconConfig(config_path, default_log_config)
        else:
            conf = IconConfig("", default_log_config)
            conf.update_conf(config)
        log_conf = conf[Logger.CATEGORY]

        Logger._init_logger(log_conf[Logger.LOGGER_NAME])
        Logger._update_logger(log_conf)
Example #10
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-sc", dest=ConfigKey.SCORE_ROOT_PATH, type=str, default=None,
                        help="icon score root path  example : .score")
    parser.add_argument("-st", dest=ConfigKey.STATE_DB_ROOT_PATH, type=str, default=None,
                        help="icon score state db root path  example : .statedb")
    parser.add_argument("-ch", dest=ConfigKey.CHANNEL, type=str, default=None,
                        help="icon score channel")
    parser.add_argument("-ak", dest=ConfigKey.AMQP_KEY, type=str, default=None,
                        help="icon score amqp_key : [amqp_key]")
    parser.add_argument("-at", dest=ConfigKey.AMQP_TARGET, type=str, default=None,
                        help="icon score amqp_target : [127.0.0.1]")
    parser.add_argument("-c", dest=ConfigKey.CONFIG, type=str, default=None,
                        help="icon score config")
    parser.add_argument("-tbears", dest=ConfigKey.TBEARS_MODE, action='store_true',
                        help="tbears mode")
    parser.add_argument("-steptrace", dest=ConfigKey.STEP_TRACE_FLAG, action="store_true", help="enable step tracing")

    args = parser.parse_args()

    args_params = dict(vars(args))
    del args_params['config']
    setproctitle.setproctitle(ICON_SERVICE_PROCTITLE_FORMAT.format(**args_params))

    conf_path = args.config
    if conf_path is not None:
        if not IconConfig.valid_conf_path(conf_path):
            print(f'invalid config file : {conf_path}')
            sys.exit(ExitCode.INVALID_COMMAND.value)
    if conf_path is None:
        conf_path = str()

    conf = IconConfig(conf_path, copy.deepcopy(default_icon_config))
    conf.load()
    conf.update_conf(args_to_dict(args))
    Logger.load_config(conf)
    if not check_config(conf, default_icon_config):
        Logger.error(tag=_TAG, msg=f"Invalid Config")
        sys.exit(ExitCode.INVALID_CONFIG.value)

    Logger.print_config(conf, _TAG)

    _run_async(_check_rabbitmq(conf[ConfigKey.AMQP_TARGET]))
    icon_service = IconService()
    icon_service.serve(config=conf)
    Logger.info(f'==========IconService Done==========', _TAG)
Example #11
0
def start_as_rest_server(args):
    peer_port = args.port
    channel = conf.LOOPCHAIN_DEFAULT_CHANNEL
    amqp_key = args.amqp_key or conf.AMQP_KEY
    api_port = int(peer_port) + conf.PORT_DIFF_REST_SERVICE_CONTAINER
    conf_path = conf.CONF_PATH_ICONRPCSERVER_DEV

    if args.radio_station_target:
        if args.radio_station_target == conf.URL_CITIZEN_TESTNET:
            conf_path = conf.CONF_PATH_ICONRPCSERVER_TESTNET
        elif args.radio_station_target == conf.URL_CITIZEN_MAINNET:
            conf_path = conf.CONF_PATH_ICONRPCSERVER_MAINNET

    from iconrpcserver.default_conf.icon_rpcserver_config import default_rpcserver_config
    from iconrpcserver.icon_rpcserver_cli import start_process, find_procs_by_params
    from iconcommons.icon_config import IconConfig
    from iconcommons.logger import Logger

    with open(conf_path) as file:
        load_conf = json.load(file)

    additional_conf = {
        "log": load_conf.get("log"),
        "channel": channel,
        "port": api_port,
        "amqpKey": amqp_key,
        "gunicornWorkerCount": 1,
        "tbearsMode": False
    }

    rpcserver_conf = IconConfig("", default_rpcserver_config)
    rpcserver_conf.load()
    rpcserver_conf.update_conf(additional_conf)
    Logger.load_config(rpcserver_conf)

    if not find_procs_by_params(api_port):
        start_process(conf=rpcserver_conf)
        Logger.info("start_command done!, IconRpcServerCli")
Example #12
0
def main():
    parser = argparse.ArgumentParser(prog='iconrpcserver_cli.py',
                                     usage=f"""
    ==========================
    iconrpcserver server
    ==========================
    iconrpcserver commands:
        start : iconrpcserver start
        stop : iconrpcserver stop
        -p : rest_proxy port
        -c : json configure file path
        -at : amqp target info [IP]:[PORT]
        -ak : key sharing peer group using queue name. use it if one more peers connect one MQ
        -ch : loopchain channel ex) loopchain_default
        -fg : foreground process
        -tbears : tbears mode
    """)

    parser.add_argument('command',
                        type=str,
                        nargs='*',
                        choices=['start', 'stop'],
                        help='rest type [start|stop]')

    parser.add_argument("-p",
                        type=str,
                        dest=ConfigKey.PORT,
                        default=None,
                        help="rest_proxy port")
    parser.add_argument("-c",
                        type=str,
                        dest=ConfigKey.CONFIG,
                        default=None,
                        help="json configure file path")
    parser.add_argument("-at",
                        type=str,
                        dest=ConfigKey.AMQP_TARGET,
                        default=None,
                        help="amqp target info [IP]:[PORT]")
    parser.add_argument(
        "-ak",
        type=str,
        dest=ConfigKey.AMQP_KEY,
        default=None,
        help=
        "key sharing peer group using queue name. use it if one more peers connect one MQ"
    )
    parser.add_argument("-ch",
                        dest=ConfigKey.CHANNEL,
                        default=None,
                        help="icon score channel")
    parser.add_argument("-fg",
                        dest='foreground',
                        action='store_true',
                        help="icon rpcserver run foreground")
    parser.add_argument("-tbears",
                        dest=ConfigKey.TBEARS_MODE,
                        action='store_true',
                        help="tbears mode")

    args = parser.parse_args()

    if len(args.command) < 1:
        parser.print_help()
        sys.exit(ExitCode.COMMAND_IS_WRONG.value)

    conf_path = args.config

    if conf_path is not None:
        if not IconConfig.valid_conf_path(conf_path):
            print(f'invalid config file : {conf_path}')
            sys.exit(ExitCode.COMMAND_IS_WRONG.value)
    if conf_path is None:
        conf_path = str()

    conf = IconConfig(conf_path, default_rpcserver_config)
    conf.load()
    conf.update_conf(dict(vars(args)))
    Logger.load_config(conf)

    command = args.command[0]
    if command == 'start' and len(args.command) == 1:
        result = start(conf)
    elif command == 'stop' and len(args.command) == 1:
        result = stop(conf)
    else:
        parser.print_help()
        result = ExitCode.COMMAND_IS_WRONG.value
    sys.exit(result)
Example #13
0
def main():
    parser = argparse.ArgumentParser(prog='icon_service_cli.py', usage=f"""
    ==========================
    iconservice
    ==========================
    iconservice commands:
        start : iconservice start
        stop : iconservice stop

        -c : json configure file path
        -sc : icon score root path ex).score
        -st : icon score state db root path ex).state
        -at : amqp target info [IP]:[PORT]
        -ak : key sharing peer group using queue name. use it if one more peers connect one MQ
        -ch : loopchain channel ex) loopchain_default
        -fg : foreground process
        -tbears : tbears mode
    """)

    parser.add_argument('command', type=str,
                        nargs='*',
                        choices=['start', 'stop'],
                        help='iconservice type [start|stop]')
    parser.add_argument("-sc", dest=ConfigKey.SCORE_ROOT_PATH, type=str, default=None,
                        help="icon score root path  example : .score")
    parser.add_argument("-st", dest=ConfigKey.STATE_DB_ROOT_PATH, type=str, default=None,
                        help="icon score state db root path  example : .statedb")
    parser.add_argument("-ch", dest=ConfigKey.CHANNEL, type=str, default=None,
                        help="icon score channel")
    parser.add_argument("-ak", dest=ConfigKey.AMQP_KEY, type=str, default=None,
                        help="icon score amqp_key : [amqp_key]")
    parser.add_argument("-at", dest=ConfigKey.AMQP_TARGET, type=str, default=None,
                        help="icon score amqp_target : [127.0.0.1]")
    parser.add_argument("-c", dest=ConfigKey.CONFIG, type=str, default=None,
                        help="icon score config")
    parser.add_argument("-fg", dest='foreground', action='store_true',
                        help="icon score service run foreground")
    parser.add_argument("-tbears", dest=ConfigKey.TBEARS_MODE, action='store_true',
                        help="tbears mode")

    args = parser.parse_args()

    if len(args.command) < 1:
        parser.print_help()
        sys.exit(ExitCode.COMMAND_IS_WRONG.value)

    conf_path = args.config

    if conf_path is not None:
        if not IconConfig.valid_conf_path(conf_path):
            print(f'invalid config file : {conf_path}')
            sys.exit(ExitCode.COMMAND_IS_WRONG.value)
    if conf_path is None:
        conf_path = str()

    conf = IconConfig(conf_path, default_icon_config)
    conf.load()
    conf.update_conf(dict(vars(args)))
    Logger.load_config(conf)

    command = args.command[0]
    if command == 'start' and len(args.command) == 1:
        result = _start(conf)
    elif command == 'stop' and len(args.command) == 1:
        result = _stop(conf)
    else:
        parser.print_help()
        result = ExitCode.COMMAND_IS_WRONG.value
    sys.exit(result)