fix(cardano): display reward addresses for withdrawals

vdovhanych/arm-emu-deploy
David Misiak 2 years ago committed by matejcik
parent 9f9535abb3
commit f0e230642b

@ -24,7 +24,7 @@ from trezor.ui.layouts import (
from apps.common.paths import address_n_to_str
from . import seed
from .address import derive_human_readable_address
from .address import derive_human_readable_address, encode_human_readable_address
from .helpers import bech32, protocol_magics
from .helpers.utils import (
format_account_number,
@ -619,16 +619,23 @@ async def confirm_stake_pool_registration_final(
async def confirm_withdrawal(
ctx: wire.Context, withdrawal: CardanoTxWithdrawal
ctx: wire.Context, withdrawal: CardanoTxWithdrawal, reward_address_bytes: bytes
) -> None:
address_type_name = "script reward" if withdrawal.script_hash else "reward"
reward_address = encode_human_readable_address(reward_address_bytes)
props: list[PropertyType] = [
("Confirm withdrawal", None),
_format_stake_credential(
withdrawal.path, withdrawal.script_hash, withdrawal.key_hash
),
("Amount:", format_coin_amount(withdrawal.amount)),
(f"Confirm withdrawal for {address_type_name} address:", reward_address),
]
if withdrawal.path:
props.append(
_format_stake_credential(
withdrawal.path, withdrawal.script_hash, withdrawal.key_hash
)
)
props.append(("Amount:", format_coin_amount(withdrawal.amount)))
await confirm_properties(
ctx,
"confirm_withdrawal",

@ -623,7 +623,7 @@ async def _process_withdrawals(
if withdrawals_count == 0:
return
previous_reward_address: bytes = b""
previous_reward_address_bytes: bytes = b""
for _ in range(withdrawals_count):
withdrawal: CardanoTxWithdrawal = await ctx.call(
CardanoTxItemAck(), CardanoTxWithdrawal
@ -635,16 +635,16 @@ async def _process_withdrawals(
protocol_magic,
network_id,
account_path_checker,
previous_reward_address,
previous_reward_address_bytes,
)
reward_address = _derive_withdrawal_reward_address_bytes(
reward_address_bytes = _derive_withdrawal_reward_address_bytes(
keychain, withdrawal, protocol_magic, network_id
)
previous_reward_address = reward_address
previous_reward_address_bytes = reward_address_bytes
await confirm_withdrawal(ctx, withdrawal)
await confirm_withdrawal(ctx, withdrawal, reward_address_bytes)
withdrawals_dict.add(reward_address, withdrawal.amount)
withdrawals_dict.add(reward_address_bytes, withdrawal.amount)
async def _process_auxiliary_data(
@ -1032,7 +1032,7 @@ def _validate_withdrawal(
protocol_magic: int,
network_id: int,
account_path_checker: AccountPathChecker,
previous_reward_address: bytes,
previous_reward_address_bytes: bytes,
) -> None:
validate_stake_credential(
withdrawal.path,
@ -1045,10 +1045,12 @@ def _validate_withdrawal(
if not 0 <= withdrawal.amount < LOVELACE_MAX_SUPPLY:
raise INVALID_WITHDRAWAL
reward_address = _derive_withdrawal_reward_address_bytes(
reward_address_bytes = _derive_withdrawal_reward_address_bytes(
keychain, withdrawal, protocol_magic, network_id
)
if not cbor.are_canonically_ordered(previous_reward_address, reward_address):
if not cbor.are_canonically_ordered(
previous_reward_address_bytes, reward_address_bytes
):
raise INVALID_WITHDRAWAL
account_path_checker.add_withdrawal(withdrawal)

Loading…
Cancel
Save