From 9cd261c81a1b94cead04af6d09c68284d0e37851 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Tue, 13 Nov 2018 16:50:10 +0100 Subject: [PATCH] layout: parse and show OMNI transactions --- firmware/layout2.c | 44 +++++++++++++++++++++++++++++++++++++++++- firmware/layout2.h | 2 +- firmware/transaction.c | 6 +++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/firmware/layout2.c b/firmware/layout2.c index 111ccb9ec4..dbc36c7bb3 100644 --- a/firmware/layout2.c +++ b/firmware/layout2.c @@ -320,7 +320,49 @@ void layoutConfirmOutput(const CoinInfo *coin, const TxOutputType *out) render_address_dialog(coin, address, _("Confirm sending"), str_out, extra_line); } -bool is_valid_ascii(const uint8_t *data, uint32_t size) +void layoutConfirmOmni(const uint8_t *data, uint32_t size) +{ + const char *desc; + char str_out[32]; + const uint32_t tx_type = *(const uint32_t *)(data + 4); + if (tx_type == 0x00000000 && size == 20) { // OMNI simple send + desc = _("Simple send of "); + const uint32_t currency = *(const uint32_t *)(data + 8); + const char *suffix = "UNKN"; + switch (currency) { + case 1: + suffix = "OMNI"; + break; + case 2: + suffix = "tOMNI"; + break; + case 3: + suffix = "MAID"; + break; + case 31: + suffix = "USDT"; + break; + } + const uint64_t amount = *(const uint64_t *)(data + 12); + bn_format_uint64(amount, NULL, suffix, BITCOIN_DIVISIBILITY, 0, false, str_out, sizeof(str_out)); + } else { + desc = _("Unknown transaction"); + str_out[0] = 0; + } + layoutDialogSwipe(&bmp_icon_question, + _("Cancel"), + _("Confirm"), + NULL, + _("Confirm OMNI Transaction:"), + NULL, + desc, + NULL, + str_out, + NULL + ); +} + +static bool is_valid_ascii(const uint8_t *data, uint32_t size) { for (uint32_t i = 0; i < size; i++) { if (data[i] < ' ' || data[i] > '~') { diff --git a/firmware/layout2.h b/firmware/layout2.h index cfeec1e1b9..954832bdf9 100644 --- a/firmware/layout2.h +++ b/firmware/layout2.h @@ -44,6 +44,7 @@ void layoutProgressSwipe(const char *desc, int permil); void layoutScreensaver(void); void layoutHome(void); void layoutConfirmOutput(const CoinInfo *coin, const TxOutputType *out); +void layoutConfirmOmni(const uint8_t *data, uint32_t size); void layoutConfirmOpReturn(const uint8_t *data, uint32_t size); void layoutConfirmTx(const CoinInfo *coin, uint64_t amount_out, uint64_t amount_fee); void layoutFeeOverThreshold(const CoinInfo *coin, uint64_t fee); @@ -73,6 +74,5 @@ void layoutCosiCommitSign(const uint32_t *address_n, size_t address_n_count, con const char **split_message(const uint8_t *msg, uint32_t len, uint32_t rowlen); const char **split_message_hex(const uint8_t *msg, uint32_t len); -bool is_valid_ascii(const uint8_t *data, uint32_t size); #endif diff --git a/firmware/transaction.c b/firmware/transaction.c index f5b9fb5b77..e7d9e91c60 100644 --- a/firmware/transaction.c +++ b/firmware/transaction.c @@ -200,7 +200,11 @@ int compile_output(const CoinInfo *coin, const HDNode *root, TxOutputType *in, T return 0; // failed to compile output } if (needs_confirm) { - layoutConfirmOpReturn(in->op_return_data.bytes, in->op_return_data.size); + if (in->op_return_data.size >= 8 && memcmp(in->op_return_data.bytes, "omni", 4) == 0) { // OMNI transaction + layoutConfirmOmni(in->op_return_data.bytes, in->op_return_data.size); + } else { + layoutConfirmOpReturn(in->op_return_data.bytes, in->op_return_data.size); + } if (!protectButton(ButtonRequestType_ButtonRequest_ConfirmOutput, false)) { return -1; // user aborted }