示例#1
0
文件: main.py 项目: uivlis/sto
def restart_nonce(config: BoardCommmadConfiguration):
    """Resets the broadcasting account nonce."""

    assert is_ethereum_network(config.network)

    logger = config.logger

    from sto.ethereum.nonce import restart_nonce

    dbsession = config.dbsession

    restart_nonce(logger,
                  dbsession,
                  config.network,
                  ethereum_node_url=config.ethereum_node_url,
                  ethereum_private_key=config.ethereum_private_key,
                  ethereum_gas_limit=config.ethereum_gas_limit,
                  ethereum_gas_price=config.ethereum_gas_price)
示例#2
0
文件: main.py 项目: uivlis/sto
def cli(ctx, config: str, **kwargs):

    config_file = config

    # Fill in arguments from the configuration file
    if config_file:
        if not os.path.exists(config_file):

            sys.exit("Config file does not exist {}".format(config_file))

        config = configobj.ConfigObj(config_file, raise_errors=True)

        # TODO: Bug here - could not figure out how to pull out from click if an option is set on a command line or are we using default.
        # Thus you cannot override config file variables by giving a default value from command line
        for opt in ctx.command.params:  # type: click.core.Options:

            dashed_name = opt.name.replace("_", "-")
            value = kwargs.get(opt.name)
            if value == opt.default:
                config_file_value = config.get(dashed_name)
                if config_file_value:
                    # TODO: Figure out how to apply opt.process_value() here
                    if opt.type == click.types.INT:
                        kwargs[opt.name] = int(config_file_value)
                    else:
                        kwargs[opt.name] = config_file_value

    log_level = kwargs["log_level"]

    config = BoardCommmadConfiguration(**kwargs)
    logger = config.logger = create_command_line_logger(log_level.upper())

    # Mute SQLAlchemy logger who is quite a verbose friend otherwise
    sa_logger = logging.getLogger("sqlalchemy")
    sa_logger.setLevel(logging.WARN)

    # TODO: No idea how to peek into click internals to figure out upcoming subcommand
    prelude = True
    if sys.argv[-1] == "version":
        # Mute generic prelude
        prelude = False

    # Print out the info
    dbfile = os.path.abspath(config.database_file)
    version = pkg_resources.require("sto")[0].version
    config.version = version

    # TODO: A hack to post process gas price, as command line help originally told it is going to be gwei,
    # but in reality raw wei values were used
    # Figure out how to do this with click() argument processors
    config.ethereum_gas_price = config.ethereum_gas_price * 10**9 if config.ethereum_gas_price else config.ethereum_gas_price

    if prelude:
        copyright = "Copyright TokenMarket Ltd. 2018 - 2019"
        logger.info("STO tool, version %s%s%s - %s",
                    colorama.Fore.LIGHTCYAN_EX, version, colorama.Fore.RESET,
                    copyright)
        logger.info("Using database %s%s%s", colorama.Fore.LIGHTCYAN_EX,
                    dbfile, colorama.Fore.RESET)

        config.dbsession, new_db = setup_database(logger, dbfile)
        if new_db:
            if config.auto_restart_nonce and config.ethereum_private_key:
                logger.info(
                    "Automatically fetching the initial nonce for the deployment account from blockchain"
                )
                from sto.ethereum.nonce import restart_nonce
                restart_nonce(logger,
                              config.dbsession,
                              config.network,
                              ethereum_node_url=config.ethereum_node_url,
                              ethereum_private_key=config.ethereum_private_key,
                              ethereum_gas_limit=config.ethereum_gas_limit,
                              ethereum_gas_price=config.ethereum_gas_price)

    ctx.obj = config