Пример #1
0
def main(refresh, api_key, verbose):
    # setup logging
    log_level = logging.DEBUG if verbose else logging.WARNING
    root = logging.getLogger()
    root.setLevel(log_level)
    handler = logging.StreamHandler(sys.stdout)
    handler.setLevel(log_level)
    root.addHandler(handler)

    marketcap.init(api_key, refresh=refresh)

    defs, _ = coin_info.coin_info_with_duplicates()
    support_info = coin_info.support_info(defs)

    coins = {}
    coins.update(update_bitcoin(defs.bitcoin, support_info))
    coins.update(update_erc20(defs.erc20, defs.eth, support_info))
    coins.update(update_ethereum_networks(defs.eth, support_info))
    coins.update(update_nem_mosaics(defs.nem, support_info))
    coins.update(update_simple(defs.misc, support_info, "coin"))

    apply_overrides(coins)
    finalize_wallets(coins)
    update_marketcaps(coins)

    check_missing_data(coins)

    info = summary(coins, api_key)
    details = dict(coins=coins, info=info)

    print(json.dumps(info, sort_keys=True, indent=4))
    with open(os.path.join(coin_info.DEFS_DIR, "coins_details.json"),
              "w") as f:
        json.dump(details, f, sort_keys=True, indent=4)
        f.write("\n")
Пример #2
0
def set_support_value(key, entries, reason):
    """Set a support info variable.

    Examples:
    support.py set coin:BTC trezor1=soon trezor2=2.0.7 webwallet=yes connect=no
    support.py set coin:LTC trezor1=yes connect=

    Setting a variable to "yes", "true" or "1" sets support to true.
    Setting a variable to "no", "false" or "0" sets support to false.
    (or null, in case of trezor1/2)
    Setting variable to empty ("trezor1=") will set to null, or clear the entry.
    Setting to "soon", "planned", "2.1.1" etc. will set the literal string.

    Entries that are always present:
    trezor1 trezor2 webwallet connect

    Entries with other names will be inserted into "others". This is a good place
    to store links to 3rd party software, such as Electrum forks or claim tools.
    """
    defs, _ = coin_info.coin_info_with_duplicates()
    coins = defs.as_dict()
    if key not in coins:
        click.echo(f"Failed to find key {key}")
        click.echo("Use 'support.py show' to search for the right one.")
        sys.exit(1)

    if coins[key].get("duplicate") and coin_info.is_token(coins[key]):
        shortcut = coins[key]["shortcut"]
        click.echo(f"Note: shortcut {shortcut} is a duplicate.")
        click.echo(f"Coin will NOT be listed regardless of support.json status.")

    for entry in entries:
        try:
            device, value = entry.split("=", maxsplit=1)
        except ValueError:
            click.echo(f"Invalid entry: {entry}")
            sys.exit(2)

        if device not in SUPPORT_INFO:
            raise click.ClickException(f"unknown device: {device}")

        if value in ("yes", "true", "1"):
            set_supported(device, key, True)
        elif value in ("no", "false", "0"):
            if device in coin_info.MISSING_SUPPORT_MEANS_NO:
                click.echo("Setting explicitly unsupported for {device}.")
                click.echo("Perhaps you meant removing support, i.e., '{device}=' ?")
            if not reason:
                reason = click.prompt(f"Enter reason for not supporting on {device}:")
            set_unsupported(device, key, reason)
        elif value == "":
            clear_support(device, key)
        else:
            # arbitrary string
            set_supported(device, key, value)

    print_support(coins[key])
    write_support_info()
Пример #3
0
def set_support_value(key, entries, reason):
    """Set a support info variable.

    Examples:
    support.py set coin:BTC trezor1=soon trezor2=2.0.7 webwallet=yes connect=no
    support.py set coin:LTC trezor1=yes connect=

    Setting a variable to "yes", "true" or "1" sets support to true.
    Setting a variable to "no", "false" or "0" sets support to false.
    (or null, in case of trezor1/2)
    Setting variable to empty ("trezor1=") will set to null, or clear the entry.
    Setting to "soon", "planned", "2.1.1" etc. will set the literal string.

    Entries that are always present:
    trezor1 trezor2 webwallet connect

    Entries with other names will be inserted into "others". This is a good place
    to store links to 3rd party software, such as Electrum forks or claim tools.
    """
    defs, _ = coin_info.coin_info_with_duplicates()
    coins = defs.as_dict()
    if key not in coins:
        click.echo(f"Failed to find key {key}")
        click.echo("Use 'support.py show' to search for the right one.")
        sys.exit(1)

    if coins[key].get("duplicate") and coin_info.is_token(coins[key]):
        shortcut = coins[key]["shortcut"]
        click.echo(f"Note: shortcut {shortcut} is a duplicate.")
        click.echo(f"Coin will NOT be listed regardless of support.json status.")

    for entry in entries:
        try:
            device, value = entry.split("=", maxsplit=1)
        except ValueError:
            click.echo(f"Invalid entry: {entry}")
            sys.exit(2)

        if device not in SUPPORT_INFO:
            raise click.ClickException(f"unknown device: {device}")

        if value in ("yes", "true", "1"):
            set_supported(device, key, True)
        elif value in ("no", "false", "0"):
            if device in coin_info.MISSING_SUPPORT_MEANS_NO:
                click.echo("Setting explicitly unsupported for {device}.")
                click.echo("Perhaps you meant removing support, i.e., '{device}=' ?")
            if not reason:
                reason = click.prompt(f"Enter reason for not supporting on {device}:")
            set_unsupported(device, key, reason)
        elif value == "":
            clear_support(device, key)
        else:
            # arbitrary string
            set_supported(device, key, value)

    print_support(coins[key])
    write_support_info()
Пример #4
0
def show(keyword):
    """Show support status of specified coins.

    Keywords match against key, name or shortcut (ticker symbol) of coin.
    """
    defs, _ = coin_info.coin_info_with_duplicates()

    for kw in keyword:
        for coin in coin_info.search(defs, kw):
            print_support(coin)
Пример #5
0
def show(keyword):
    """Show support status of specified coins.

    Keywords match against key, name or shortcut (ticker symbol) of coin.
    """
    defs, _ = coin_info.coin_info_with_duplicates()

    for kw in keyword:
        for coin in coin_info.search(defs, kw):
            print_support(coin)
Пример #6
0
def set_support_value(key, entries, reason):
    """Set a support info variable.

    Examples:
    support.py set coin:BTC trezor1=1.10.5 trezor2=2.4.7 suite=yes connect=no
    support.py set coin:LTC trezor1=yes connect=

    Setting a variable to "yes", "true" or "1" sets support to true.
    Setting a variable to "no", "false" or "0" sets support to false.
    (or null, in case of trezor1/2)
    Setting variable to empty ("trezor1=") will set to null, or clear the entry.
    Setting a variable to a particular version string (e.g., "2.4.7") will set that
    particular version.
    """
    defs, _ = coin_info.coin_info_with_duplicates()
    coins = defs.as_dict()
    if key not in coins:
        click.echo(f"Failed to find key {key}")
        click.echo("Use 'support.py show' to search for the right one.")
        sys.exit(1)

    if coins[key].get("duplicate") and coin_info.is_token(coins[key]):
        shortcut = coins[key]["shortcut"]
        click.echo(f"Note: shortcut {shortcut} is a duplicate.")

    for entry in entries:
        try:
            device, value = entry.split("=", maxsplit=1)
        except ValueError:
            click.echo(f"Invalid entry: {entry}")
            sys.exit(2)

        if device not in SUPPORT_INFO:
            raise click.ClickException(f"unknown device: {device}")

        if value in ("yes", "true", "1"):
            set_supported(device, key, True)
        elif value in ("no", "false", "0"):
            if device in coin_info.MISSING_SUPPORT_MEANS_NO:
                click.echo(f"Setting explicitly unsupported for {device}.")
                click.echo(f"Perhaps you meant removing support, i.e., '{device}=' ?")
            if not reason:
                reason = click.prompt(f"Enter reason for not supporting on {device}:")
            set_unsupported(device, key, reason)
        elif value == "":
            clear_support(device, key)
        else:
            # arbitrary string
            set_supported(device, key, value)

    print_support(coins[key])
    write_support_info()
Пример #7
0
def check(check_tokens, ignore_missing):
    """Check validity of support information.

    Ensures that `support.json` data is well formed, there are no keys without
    corresponding coins, and there are no coins without corresponding keys.

    If `--check-tokens` is specified, the check will also take into account ERC20 tokens
    without support info. This is disabled by default, because support info for ERC20
    tokens is not strictly required.

    If `--ignore-missing` is specified, the check will display coins with missing
    support info, but will not fail when missing coins are found. This is
    useful in Travis.
    """
    all_coins, buckets = coin_info.coin_info_with_duplicates()
    clear_erc20_mixed_buckets(buckets)
    coins_dict = all_coins.as_dict()
    checks_ok = True

    errors = check_support_values()
    if errors:
        for error in errors:
            print(error)
        checks_ok = False

    orphaned = find_orphaned_support_keys(coins_dict)
    for orphan in orphaned:
        print(f"orphaned key {orphan}")
        checks_ok = False

    missing = find_unsupported_coins(coins_dict)
    for device, values in missing.items():
        if not check_tokens:
            values = [coin for coin in values if not coin_info.is_token(coin)]
        if values:
            if not ignore_missing:
                checks_ok = False
            print(f"Device {device} has missing support infos:")
            for coin in values:
                print(f"{coin['key']} - {coin['name']}")

    supported_dups = find_supported_duplicate_tokens(coins_dict)
    for key in supported_dups:
        coin = coins_dict[key]
        checks_ok = False
        print(
            f"Token {coin['key']} ({coin['name']}) is duplicate but supported")

    if not checks_ok:
        print("Some checks have failed")
        sys.exit(1)
Пример #8
0
def check(check_tokens, ignore_missing):
    """Check validity of support information.

    Ensures that `support.json` data is well formed, there are no keys without
    corresponding coins, and there are no coins without corresponding keys.

    If `--check-tokens` is specified, the check will also take into account ERC20 tokens
    without support info. This is disabled by default, because support info for ERC20
    tokens is not strictly required.

    If `--ignore-missing` is specified, the check will display coins with missing
    support info, but will not fail when missing coins are found. This is
    useful in Travis.
    """
    all_coins, _ = coin_info.coin_info_with_duplicates()
    coins_dict = all_coins.as_dict()
    checks_ok = True

    errors = check_support_values()
    if errors:
        for error in errors:
            print(error)
        checks_ok = False

    orphaned = find_orphaned_support_keys(coins_dict)
    for orphan in orphaned:
        print(f"orphaned key {orphan}")
        checks_ok = False

    missing = find_unsupported_coins(coins_dict)
    for device, values in missing.items():
        if not check_tokens:
            values = [coin for coin in values if not coin_info.is_token(coin)]
        if values:
            if not ignore_missing:
                checks_ok = False
            print(f"Device {device} has missing support infos:")
            for coin in values:
                print(f"{coin['key']} - {coin['name']}")

    supported_dups = find_supported_duplicate_tokens(coins_dict)
    for key in supported_dups:
        coin = coins_dict[key]
        checks_ok = False
        print(f"Token {coin['key']} ({coin['name']}) is duplicate but supported")

    if not checks_ok:
        print("Some checks have failed")
        sys.exit(1)
Пример #9
0
def fix(dry_run):
    """Fix expected problems.

    Prunes orphaned keys and ensures that ERC20 duplicate info matches support info.
    """
    all_coins, _ = coin_info.coin_info_with_duplicates()
    coins_dict = all_coins.as_dict()

    orphaned = find_orphaned_support_keys(coins_dict)
    for orphan in orphaned:
        print(f"pruning orphan {orphan}")
        for device in SUPPORT_INFO:
            clear_support(device, orphan)

    process_erc20(coins_dict)
    if not dry_run:
        write_support_info()
Пример #10
0
def fix(dry_run):
    """Fix expected problems.

    Prunes orphaned keys and ensures that ERC20 duplicate info matches support info.
    """
    all_coins, _ = coin_info.coin_info_with_duplicates()
    coins_dict = all_coins.as_dict()

    orphaned = find_orphaned_support_keys(coins_dict)
    for orphan in orphaned:
        print(f"pruning orphan {orphan}")
        for device in SUPPORT_INFO:
            clear_support(device, orphan)

    process_erc20(coins_dict)
    if not dry_run:
        write_support_info()
Пример #11
0
def check(backend, icons, show_duplicates):
    """Validate coin definitions.

    Checks that every btc-like coin is properly filled out, reports duplicate symbols,
    missing or invalid icons, backend responses, and uniform key information --
    i.e., that all coins of the same type have the same fields in their JSON data.

    Uniformity check ignores NEM mosaics and ERC20 tokens, where non-uniformity is
    expected.

    The `--show-duplicates` option can be set to:

    - all: all shortcut collisions are shown, including colliding ERC20 tokens

    - nontoken: only collisions that affect non-ERC20 coins are shown

    - errors: only collisions between non-ERC20 tokens are shown. This is the default,
    as a collision between two or more non-ERC20 tokens is an error.

    In the output, duplicate ERC tokens will be shown in cyan; duplicate non-tokens
    in red. An asterisk (*) next to symbol name means that even though it was detected
    as duplicate, it is still included in results.

    The collision detection checks that SLIP44 numbers don't collide between different
    mainnets (testnet collisions are allowed), that `address_prefix` doesn't collide
    with Bitcoin (other collisions are reported as warnings). `address_prefix_p2sh`
    is also checked but we have a bunch of collisions there and can't do much
    about them, so it's not an error.

    In the collision checks, Bitcoin is shown in red, other mainnets in blue,
    testnets in green and unsupported networks in gray, marked with `(X)` for
    non-colored output.
    """
    if backend and requests is None:
        raise click.ClickException(
            "You must install requests for backend check")

    if icons and not CAN_BUILD_DEFS:
        raise click.ClickException("Missing requirements for icon check")

    defs, buckets = coin_info.coin_info_with_duplicates()
    all_checks_passed = True

    print("Checking BTC-like coins...")
    if not check_btc(defs.bitcoin):
        all_checks_passed = False

    print("Checking Ethereum networks...")
    if not check_eth(defs.eth):
        all_checks_passed = False

    if show_duplicates == "all":
        dup_level = logging.DEBUG
    elif show_duplicates == "nontoken":
        dup_level = logging.INFO
    else:
        dup_level = logging.ERROR
    print("Checking unexpected duplicates...")
    if not check_dups(buckets, dup_level):
        all_checks_passed = False

    nontoken_dups = [
        coin for coin in defs.as_list() if "dup_key_nontoken" in coin
    ]
    if nontoken_dups:
        nontoken_dup_str = ", ".join(
            highlight_key(coin, "red") for coin in nontoken_dups)
        print_log(logging.ERROR,
                  "Non-token duplicate keys: " + nontoken_dup_str)
        all_checks_passed = False

    if icons:
        print("Checking icon files...")
        if not check_icons(defs.bitcoin):
            all_checks_passed = False

    if backend:
        print("Checking backend responses...")
        if not check_backends(defs.bitcoin):
            all_checks_passed = False

    print("Checking key uniformity...")
    for cointype, coinlist in defs.items():
        if cointype in ("erc20", "nem"):
            continue
        if not check_key_uniformity(coinlist):
            all_checks_passed = False

    if not all_checks_passed:
        print("Some checks failed.")
        sys.exit(1)
    else:
        print("Everything is OK.")
Пример #12
0
def release(
    ctx,
    device: str,
    version,
    git_tag,
    release_missing,
    dry_run,
    soon,
    force,
    add_all,
    verbose,
):
    """Release a new Trezor firmware.

    Update support infos so that all coins have a clear support status.
    By default, marks duplicate tokens as unsupported, and all coins that either
    don't have support info, or they are supported "soon", are set to the
    released firmware version.

    Optionally tags the repository with the given version.

    `device` can be "1", "2", or a string matching `support.json` key. Version
    is autodetected by downloading a list of latest releases and incrementing
    micro version by one, or you can specify `--version` explicitly.

    Unless `--add-all` is specified, the tool will ask you to confirm each added
    coin. ERC20 tokens are added automatically. Use `--verbose` to see them.
    """
    # check condition(s)
    if soon and git_tag:
        raise click.ClickException("Cannot git-tag a 'soon' revision")

    # process `device`
    if device.isnumeric():
        device = f"trezor{device}"

    if not force and device not in coin_info.VERSIONED_SUPPORT_INFO:
        raise click.ClickException(
            f"Non-releasable device {device} (support info is not versioned). "
            "Use --force to proceed anyway.")

    if not soon:
        # guess `version` if not given
        if not version:
            versions = coin_info.latest_releases()
            latest_version = versions.get(device)
            if latest_version is None:
                raise click.ClickException(
                    "Failed to guess version. "
                    "Please use --version to specify it explicitly.")
            else:
                latest_version = list(latest_version)
            latest_version[-1] += 1
            version = ".".join(str(n) for n in latest_version)

        # process `version`
        try:
            version_numbers = list(map(int, version.split(".")))
            expected_device = f"trezor{version_numbers[0]}"
            if not force and device != expected_device:
                raise click.ClickException(
                    f"Device {device} should not be version {version}. "
                    "Use --force to proceed anyway.")
        except ValueError as e:
            if not force:
                raise click.ClickException(
                    f"Failed to parse '{version}' as a version. "
                    "Use --force to proceed anyway.") from e

    if soon:
        version = "soon"
        print(f"Moving {device} missing infos to 'soon'")
    else:
        print(f"Releasing {device} firmware version {version}")

    defs, _ = coin_info.coin_info_with_duplicates()
    coins_dict = defs.as_dict()

    # Invoke data fixup as dry-run. That will modify data internally but won't write
    # changes. We will write changes at the end based on our own `dry_run` value.
    print("Fixing up data...")
    ctx.invoke(fix, dry_run=True)

    def maybe_add(coin, label):
        add = False
        if add_all:
            add = True
        else:
            text = f"Add {label} coin {coin['key']} ({coin['name']})?"
            add = click.confirm(text, default=True)
        if add:
            set_supported(device, coin["key"], version)

    # if we're releasing, process coins marked "soon"
    if not soon:
        supported, _ = support_dicts(device)
        soon_list = [
            coins_dict[key] for key, val in supported.items()
            if val == "soon" and key in coins_dict
        ]
        for coin in soon_list:
            key = coin["key"]
            maybe_add(coin, "soon")

    # process missing (not listed) supportinfos
    if release_missing:
        missing_list = find_unsupported_coins(coins_dict)[device]
        tokens = [coin for coin in missing_list if coin_info.is_token(coin)]
        nontokens = [
            coin for coin in missing_list if not coin_info.is_token(coin)
        ]
        for coin in tokens:
            key = coin["key"]
            # assert not coin.get("duplicate"), key
            if verbose:
                print(f"Adding missing {key} ({coin['name']})")
            set_supported(device, key, version)

        for coin in nontokens:
            maybe_add(coin, "missing")

    tagname = f"{device}-{version}"
    if git_tag:
        if dry_run:
            print(f"Would tag current commit with {tagname}")
        else:
            print(f"Tagging current commit with {tagname}")
            subprocess.check_call(["git", "tag", tagname])

    if not dry_run:
        write_support_info()
    else:
        print("No changes written")
Пример #13
0
def check(backend, icons, show_duplicates):
    """Validate coin definitions.

    Checks that every btc-like coin is properly filled out, reports duplicate symbols,
    missing or invalid icons, backend responses, and uniform key information --
    i.e., that all coins of the same type have the same fields in their JSON data.

    Uniformity check ignores NEM mosaics and ERC20 tokens, where non-uniformity is
    expected.

    The `--show-duplicates` option can be set to:

    - all: all shortcut collisions are shown, including colliding ERC20 tokens

    - nontoken: only collisions that affect non-ERC20 coins are shown

    - errors: only collisions between non-ERC20 tokens are shown. This is the default,
    as a collision between two or more non-ERC20 tokens is an error.

    In the output, duplicate ERC tokens will be shown in cyan; duplicate non-tokens
    in red. An asterisk (*) next to symbol name means that even though it was detected
    as duplicate, it is still included in results.

    The collision detection checks that SLIP44 numbers don't collide between different
    mainnets (testnet collisions are allowed), that `address_prefix` doesn't collide
    with Bitcoin (other collisions are reported as warnings). `address_prefix_p2sh`
    is also checked but we have a bunch of collisions there and can't do much
    about them, so it's not an error.

    In the collision checks, Bitcoin is shown in red, other mainnets in blue,
    testnets in green and unsupported networks in gray, marked with `(X)` for
    non-colored output.
    """
    if backend and requests is None:
        raise click.ClickException("You must install requests for backend check")

    if icons and not CAN_BUILD_DEFS:
        raise click.ClickException("Missing requirements for icon check")

    defs, buckets = coin_info.coin_info_with_duplicates()
    all_checks_passed = True

    print("Checking BTC-like coins...")
    if not check_btc(defs.bitcoin):
        all_checks_passed = False

    print("Checking Ethereum networks...")
    if not check_eth(defs.eth):
        all_checks_passed = False

    if show_duplicates == "all":
        dup_level = logging.DEBUG
    elif show_duplicates == "nontoken":
        dup_level = logging.INFO
    else:
        dup_level = logging.ERROR
    print("Checking unexpected duplicates...")
    if not check_dups(buckets, dup_level):
        all_checks_passed = False

    nontoken_dups = [coin for coin in defs.as_list() if "dup_key_nontoken" in coin]
    if nontoken_dups:
        nontoken_dup_str = ", ".join(
            highlight_key(coin, "red") for coin in nontoken_dups
        )
        print_log(logging.ERROR, "Non-token duplicate keys: " + nontoken_dup_str)
        all_checks_passed = False

    if icons:
        print("Checking icon files...")
        if not check_icons(defs.bitcoin):
            all_checks_passed = False

    if backend:
        print("Checking backend responses...")
        if not check_backends(defs.bitcoin):
            all_checks_passed = False

    print("Checking segwit fields...")
    if not check_segwit(defs.bitcoin):
        all_checks_passed = False

    print("Checking key uniformity...")
    for cointype, coinlist in defs.items():
        if cointype in ("erc20", "nem"):
            continue
        if not check_key_uniformity(coinlist):
            all_checks_passed = False

    if not all_checks_passed:
        print("Some checks failed.")
        sys.exit(1)
    else:
        print("Everything is OK.")
Пример #14
0
def release(
    ctx,
    device: str,
    version,
    git_tag,
    release_missing,
    dry_run,
    soon,
    force,
    add_all,
    verbose,
):
    """Release a new Trezor firmware.

    Update support infos so that all coins have a clear support status.
    By default, marks duplicate tokens as unsupported, and all coins that either
    don't have support info, or they are supported "soon", are set to the
    released firmware version.

    Optionally tags the repository with the given version.

    `device` can be "1", "2", or a string matching `support.json` key. Version
    is autodetected by downloading a list of latest releases and incrementing
    micro version by one, or you can specify `--version` explicitly.

    Unless `--add-all` is specified, the tool will ask you to confirm each added
    coin. ERC20 tokens are added automatically. Use `--verbose` to see them.
    """
    # check condition(s)
    if soon and git_tag:
        raise click.ClickException("Cannot git-tag a 'soon' revision")

    # process `device`
    if device.isnumeric():
        device = f"trezor{device}"

    if not force and device not in coin_info.VERSIONED_SUPPORT_INFO:
        raise click.ClickException(
            f"Non-releasable device {device} (support info is not versioned). "
            "Use --force to proceed anyway."
        )

    if not soon:
        # guess `version` if not given
        if not version:
            versions = coin_info.latest_releases()
            latest_version = versions.get(device)
            if latest_version is None:
                raise click.ClickException(
                    "Failed to guess version. "
                    "Please use --version to specify it explicitly."
                )
            else:
                latest_version = list(latest_version)
            latest_version[-1] += 1
            version = ".".join(str(n) for n in latest_version)

        # process `version`
        try:
            version_numbers = list(map(int, version.split(".")))
            expected_device = f"trezor{version_numbers[0]}"
            if not force and device != expected_device:
                raise click.ClickException(
                    f"Device {device} should not be version {version}. "
                    "Use --force to proceed anyway."
                )
        except ValueError as e:
            if not force:
                raise click.ClickException(
                    f"Failed to parse '{version}' as a version. "
                    "Use --force to proceed anyway."
                ) from e

    if soon:
        version = "soon"
        print(f"Moving {device} missing infos to 'soon'")
    else:
        print(f"Releasing {device} firmware version {version}")

    defs, _ = coin_info.coin_info_with_duplicates()
    coins_dict = defs.as_dict()

    # Invoke data fixup as dry-run. That will modify data internally but won't write
    # changes. We will write changes at the end based on our own `dry_run` value.
    print("Fixing up data...")
    ctx.invoke(fix, dry_run=True)

    def maybe_add(coin, label):
        add = False
        if add_all:
            add = True
        else:
            text = f"Add {label} coin {coin['key']} ({coin['name']})?"
            add = click.confirm(text, default=True)
        if add:
            set_supported(device, coin["key"], version)

    # if we're releasing, process coins marked "soon"
    if not soon:
        supported, _ = support_dicts(device)
        soon_list = [
            coins_dict[key]
            for key, val in supported.items()
            if val == "soon" and key in coins_dict
        ]
        for coin in soon_list:
            key = coin["key"]
            maybe_add(coin, "soon")

    # process missing (not listed) supportinfos
    if release_missing:
        missing_list = find_unsupported_coins(coins_dict)[device]
        tokens = [coin for coin in missing_list if coin_info.is_token(coin)]
        nontokens = [coin for coin in missing_list if not coin_info.is_token(coin)]
        for coin in tokens:
            key = coin["key"]
            assert not coin.get("duplicate")
            if verbose:
                print(f"Adding missing {key} ({coin['name']})")
            set_supported(device, key, version)

        for coin in nontokens:
            maybe_add(coin, "missing")

    tagname = f"{device}-{version}"
    if git_tag:
        if dry_run:
            print(f"Would tag current commit with {tagname}")
        else:
            print(f"Tagging current commit with {tagname}")
            subprocess.check_call(["git", "tag", tagname])

    if not dry_run:
        write_support_info()
    else:
        print("No changes written")
Пример #15
0
def release(
    ctx,
    v1,
    v2,
    dry_run,
    force,
    verbose,
    skip_testnets,
):
    """Release a new Trezor firmware.

    Update support infos so that all coins have a clear support status.
    By default, marks duplicate tokens and testnets as unsupported, and all coins that
    don't have support info are set to the released firmware version.

    The tool will ask you to confirm each added coin. ERC20 tokens are added
    automatically. Use `--verbose` to see them.
    """
    latest_releases = coin_info.latest_releases()

    def bump_version(version_tuple):
        version_list = list(version_tuple)
        version_list[-1] += 1
        return ".".join(str(n) for n in version_list)

    # guess `version` if not given
    if not v1:
        v1 = bump_version(latest_releases["trezor1"])
    if not v2:
        v2 = bump_version(latest_releases["trezor2"])

    versions = {"trezor1": v1, "trezor2": v2}

    for number in "1", "2":
        device = f"trezor{number}"
        version = versions[device]
        if not force and not version.startswith(number + "."):
            raise click.ClickException(
                f"Device trezor{device} should not be version {version}. "
                "Use --force to proceed anyway."
            )

        print(f"Releasing {device} firmware version {version}")

    defs, _ = coin_info.coin_info_with_duplicates()
    coins_dict = defs.as_dict()

    # Invoke data fixup as dry-run. That will modify data internally but won't write
    # changes. We will write changes at the end based on our own `dry_run` value.
    print("Fixing up data...")
    ctx.invoke(fix, dry_run=True)

    def maybe_add(coin):
        add = click.confirm(
            f"Add missing coin {coin['key']} ({coin['name']})?", default=True
        )
        if not add:
            unsupport_reason = click.prompt(
                "Enter reason for not supporting (blank to skip)",
                default="",
                show_default=False,
            )
            if not unsupport_reason:
                return

        for device, version in versions.items():
            if add:
                support_setdefault(device, coin["key"], version)
            else:
                support_setdefault(device, coin["key"], False, unsupport_reason)

    # process missing (not listed) supportinfos
    missing_list = []
    unsupported = find_unsupported_coins(coins_dict)
    for val in unsupported.values():
        for coin in val:
            if coin not in missing_list:
                missing_list.append(coin)

    tokens = [coin for coin in missing_list if coin_info.is_token(coin)]
    nontokens = [coin for coin in missing_list if not coin_info.is_token(coin)]
    for coin in tokens:
        key = coin["key"]
        # assert not coin.get("duplicate"), key
        if verbose:
            print(f"Adding missing {key} ({coin['name']})")
        for device, version in versions.items():
            support_setdefault(device, key, version)

    for coin in nontokens:
        if skip_testnets and "testnet" in coin["name"].lower():
            for device, version in versions.items():
                support_setdefault(device, coin["key"], False, "(AUTO) exclude testnet")
        else:
            maybe_add(coin)

    if not dry_run:
        write_support_info()
    else:
        print("No changes written")