1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 20:38:10 +00:00

feat(cardano): add preprod and preview testnets

This commit is contained in:
David Misiak 2022-10-22 10:56:00 +02:00 committed by matejcik
parent ec83d0187f
commit 51a8e18c8d
4 changed files with 26 additions and 10 deletions

View File

@ -1,9 +1,14 @@
# https://book.world.dev.cardano.org/environments.html
MAINNET = 764824073 MAINNET = 764824073
TESTNET = 1097911063 TESTNET_PREPROD = 1
TESTNET_PREVIEW = 2
TESTNET_LEGACY = 1097911063
NAMES = { NAMES = {
MAINNET: "Mainnet", MAINNET: "Mainnet",
TESTNET: "Testnet", TESTNET_PREPROD: "Preprod Testnet",
TESTNET_PREVIEW: "Preview Testnet",
TESTNET_LEGACY: "Legacy Testnet",
} }

View File

@ -290,7 +290,7 @@ class TestCardanoAddress(unittest.TestCase):
address_type=CardanoAddressType.BYRON, address_type=CardanoAddressType.BYRON,
address_n=[0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i], address_n=[0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i],
) )
address = derive_human_readable(self.keychain, address_parameters, protocol_magics.TESTNET, 0) address = derive_human_readable(self.keychain, address_parameters, protocol_magics.TESTNET_LEGACY, 0)
self.assertEqual(expected, address) self.assertEqual(expected, address)
def test_derive_address(self): def test_derive_address(self):

View File

@ -38,7 +38,12 @@ if TYPE_CHECKING:
from .client import TrezorClient from .client import TrezorClient
from .protobuf import MessageType from .protobuf import MessageType
PROTOCOL_MAGICS = {"mainnet": 764824073, "testnet": 1097911063} PROTOCOL_MAGICS = {
"mainnet": 764824073,
"testnet_preprod": 1,
"testnet_preview": 2,
"testnet_legacy": 1097911063,
}
NETWORK_IDS = {"mainnet": 1, "testnet": 0} NETWORK_IDS = {"mainnet": 1, "testnet": 0}
MAX_CHUNK_SIZE = 1024 MAX_CHUNK_SIZE = 1024

View File

@ -27,6 +27,12 @@ if TYPE_CHECKING:
PATH_HELP = "BIP-32 path to key, e.g. m/44'/1815'/0'/0/0" PATH_HELP = "BIP-32 path to key, e.g. m/44'/1815'/0'/0/0"
TESTNET_CHOICES = {
"preprod": "testnet_preprod",
"preview": "testnet_preview",
"legacy": "testnet_legacy",
}
@click.group(name="cardano") @click.group(name="cardano")
def cli() -> None: def cli() -> None:
@ -46,7 +52,7 @@ def cli() -> None:
"-p", "--protocol-magic", type=int, default=cardano.PROTOCOL_MAGICS["mainnet"] "-p", "--protocol-magic", type=int, default=cardano.PROTOCOL_MAGICS["mainnet"]
) )
@click.option("-N", "--network-id", type=int, default=cardano.NETWORK_IDS["mainnet"]) @click.option("-N", "--network-id", type=int, default=cardano.NETWORK_IDS["mainnet"])
@click.option("-t", "--testnet", is_flag=True) @click.option("-t", "--testnet", type=ChoiceType(TESTNET_CHOICES))
@click.option( @click.option(
"-D", "-D",
"--derivation-type", "--derivation-type",
@ -61,7 +67,7 @@ def sign_tx(
signing_mode: messages.CardanoTxSigningMode, signing_mode: messages.CardanoTxSigningMode,
protocol_magic: int, protocol_magic: int,
network_id: int, network_id: int,
testnet: bool, testnet: str,
derivation_type: messages.CardanoDerivationType, derivation_type: messages.CardanoDerivationType,
include_network_id: bool, include_network_id: bool,
) -> cardano.SignTxResponse: ) -> cardano.SignTxResponse:
@ -69,7 +75,7 @@ def sign_tx(
transaction = json.load(file) transaction = json.load(file)
if testnet: if testnet:
protocol_magic = cardano.PROTOCOL_MAGICS["testnet"] protocol_magic = cardano.PROTOCOL_MAGICS[testnet]
network_id = cardano.NETWORK_IDS["testnet"] network_id = cardano.NETWORK_IDS["testnet"]
inputs = [cardano.parse_input(input) for input in transaction["inputs"]] inputs = [cardano.parse_input(input) for input in transaction["inputs"]]
@ -185,7 +191,7 @@ def sign_tx(
"-p", "--protocol-magic", type=int, default=cardano.PROTOCOL_MAGICS["mainnet"] "-p", "--protocol-magic", type=int, default=cardano.PROTOCOL_MAGICS["mainnet"]
) )
@click.option("-N", "--network-id", type=int, default=cardano.NETWORK_IDS["mainnet"]) @click.option("-N", "--network-id", type=int, default=cardano.NETWORK_IDS["mainnet"])
@click.option("-e", "--testnet", is_flag=True) @click.option("-e", "--testnet", type=ChoiceType(TESTNET_CHOICES))
@click.option( @click.option(
"-D", "-D",
"--derivation-type", "--derivation-type",
@ -207,7 +213,7 @@ def get_address(
protocol_magic: int, protocol_magic: int,
network_id: int, network_id: int,
show_display: bool, show_display: bool,
testnet: bool, testnet: str,
derivation_type: messages.CardanoDerivationType, derivation_type: messages.CardanoDerivationType,
) -> str: ) -> str:
""" """
@ -225,7 +231,7 @@ def get_address(
Byron, enterprise and reward addresses only require the general parameters. Byron, enterprise and reward addresses only require the general parameters.
""" """
if testnet: if testnet:
protocol_magic = cardano.PROTOCOL_MAGICS["testnet"] protocol_magic = cardano.PROTOCOL_MAGICS[testnet]
network_id = cardano.NETWORK_IDS["testnet"] network_id = cardano.NETWORK_IDS["testnet"]
staking_key_hash_bytes = cardano.parse_optional_bytes(staking_key_hash) staking_key_hash_bytes = cardano.parse_optional_bytes(staking_key_hash)