Skip to content

Commit

Permalink
feat(cardano): drep ui
Browse files Browse the repository at this point in the history
  • Loading branch information
jaskp committed Nov 23, 2023
1 parent 9c7a680 commit a6ac340
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions core/src/apps/cardano/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ButtonRequestType,
CardanoAddressType,
CardanoCertificateType,
CardanoDRepType,
CardanoNativeScriptType,
)
from trezor.strings import format_amount
Expand Down Expand Up @@ -559,6 +560,10 @@ async def confirm_certificate(
assert certificate.deposit is not None # validate_certificate
props.append(("Deposit:", format_coin_amount(certificate.deposit, network_id)))

elif certificate.type == CardanoCertificateType.VOTE_DELEGATION:
assert certificate.drep is not None # validate_certificate
props.append(_format_drep(certificate.drep))

await confirm_properties(
"confirm_certificate",
"Confirm transaction",
Expand Down Expand Up @@ -734,6 +739,28 @@ def _format_stake_credential(
raise ValueError


def _format_drep(drep: messages.CardanoDRep) -> tuple[str, str]:
if drep.type == CardanoDRepType.KEY_HASH:
assert drep.key_hash is not None # validate_drep
return (
"Delegating to key hash:",
bech32.encode(bech32.HRP_KEY_HASH, drep.key_hash),
)
elif drep.type == CardanoDRepType.SCRIPT_HASH:
assert drep.script_hash is not None # validate_drep
return (
"Delegating to script:",
bech32.encode(bech32.HRP_SCRIPT_HASH, drep.script_hash),
)
elif drep.type == CardanoDRepType.ABSTAIN:
return ("Delegating to:", "Abstain")
elif drep.type == CardanoDRepType.NO_CONFIDENCE:
return ("Delegating to:", "No Confidence")
else:
# should be unreachable unless there's a bug in validation
raise ValueError


async def confirm_cvote_registration_delegation(
public_key: str,
weight: int,
Expand Down

0 comments on commit a6ac340

Please sign in to comment.