1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

core+legacy: fix display of non-divisible OMNI amounts

This commit is contained in:
Pavol Rusnak 2019-07-26 12:56:44 +02:00
parent 5684983b3c
commit c288514a4f
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
2 changed files with 16 additions and 5 deletions

View File

@ -2,7 +2,12 @@ from ustruct import unpack
from trezor.utils import format_amount
currencies = {1: "OMNI", 2: "tOMNI", 3: "MAID", 31: "USDT"}
currencies = {
1: ("OMNI", True),
2: ("tOMNI", True),
3: ("MAID", False),
31: ("USDT", True),
}
def is_valid(data: bytes) -> bool:
@ -15,9 +20,10 @@ def parse(data: bytes) -> bool:
tx_version, tx_type = unpack(">HH", data[4:8])
if tx_version == 0 and tx_type == 0 and len(data) == 20: # OMNI simple send
currency, amount = unpack(">IQ", data[8:20])
suffix, divisible = currencies.get(currency, ("UNKN", False))
return "Simple send of %s %s" % (
format_amount(amount, 8),
currencies.get(currency, "UNKN"),
format_amount(amount, 8 if divisible else 0),
suffix,
)
else:
# unknown OMNI transaction

View File

@ -361,25 +361,30 @@ void layoutConfirmOmni(const uint8_t *data, uint32_t size) {
desc = _("Simple send of ");
REVERSE32(*(const uint32_t *)(data + 8), currency);
const char *suffix = " UNKN";
bool divisible = false;
switch (currency) {
case 1:
suffix = " OMNI";
divisible = true;
break;
case 2:
suffix = " tOMNI";
divisible = true;
break;
case 3:
suffix = " MAID";
divisible = false;
break;
case 31:
suffix = " USDT";
divisible = true;
break;
}
uint64_t amount_be, amount;
memcpy(&amount_be, data + 12, sizeof(uint64_t));
REVERSE64(amount_be, amount);
bn_format_uint64(amount, NULL, suffix, BITCOIN_DIVISIBILITY, 0, false,
str_out, sizeof(str_out));
bn_format_uint64(amount, NULL, suffix, divisible ? BITCOIN_DIVISIBILITY : 0,
0, false, str_out, sizeof(str_out));
} else {
desc = _("Unknown transaction");
str_out[0] = 0;