mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 14:58:09 +00:00
core/sign_tx: improve signer selection readability
This commit is contained in:
parent
8b89a30955
commit
ff41e5c304
@ -20,25 +20,31 @@ if not utils.BITCOIN_ONLY:
|
|||||||
from apps.wallet.sign_tx import bitcoinlike, decred, zcash
|
from apps.wallet.sign_tx import bitcoinlike, decred, zcash
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
from typing import Union
|
from typing import Type, Union
|
||||||
|
|
||||||
|
|
||||||
|
BITCOIN_NAMES = ("Bitcoin", "Regtest", "Testnet")
|
||||||
|
|
||||||
|
|
||||||
async def sign_tx(ctx: wire.Context, msg: SignTx, keychain: seed.Keychain) -> TxRequest:
|
async def sign_tx(ctx: wire.Context, msg: SignTx, keychain: seed.Keychain) -> TxRequest:
|
||||||
coin_name = msg.coin_name if msg.coin_name is not None else "Bitcoin"
|
coin_name = msg.coin_name if msg.coin_name is not None else "Bitcoin"
|
||||||
coin = coins.by_name(coin_name)
|
coin = coins.by_name(coin_name)
|
||||||
try:
|
|
||||||
if not utils.BITCOIN_ONLY and coin.decred:
|
if not utils.BITCOIN_ONLY:
|
||||||
signer = decred.Decred(msg, keychain, coin).signer()
|
if coin.decred:
|
||||||
elif not utils.BITCOIN_ONLY and coin.overwintered:
|
signer_class = decred.Decred # type: Type[bitcoin.Bitcoin]
|
||||||
signer = zcash.Overwintered(msg, keychain, coin).signer()
|
elif coin.overwintered:
|
||||||
elif not utils.BITCOIN_ONLY and coin_name not in (
|
signer_class = zcash.Overwintered
|
||||||
"Bitcoin",
|
elif coin_name not in BITCOIN_NAMES:
|
||||||
"Regtest",
|
signer_class = bitcoinlike.Bitcoinlike
|
||||||
"Testnet",
|
|
||||||
):
|
|
||||||
signer = bitcoinlike.Bitcoinlike(msg, keychain, coin).signer()
|
|
||||||
else:
|
else:
|
||||||
signer = bitcoin.Bitcoin(msg, keychain, coin).signer()
|
signer_class = bitcoin.Bitcoin
|
||||||
|
|
||||||
|
else:
|
||||||
|
signer_class = bitcoin.Bitcoin
|
||||||
|
|
||||||
|
try:
|
||||||
|
signer = signer_class(msg, keychain, coin).signer()
|
||||||
except common.SigningError as e:
|
except common.SigningError as e:
|
||||||
raise wire.Error(*e.args)
|
raise wire.Error(*e.args)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user