diff --git a/app/src/apdu_handler.c b/app/src/apdu_handler.c index d0c6af9..d62056c 100644 --- a/app/src/apdu_handler.c +++ b/app/src/apdu_handler.c @@ -25,11 +25,11 @@ #include "app_main.h" #include "coin.h" #include "crypto.h" +#include "parser_txdef.h" #include "tx.h" #include "view.h" #include "view_internal.h" #include "zxmacros.h" -#include "parser_txdef.h" static bool tx_initialized = false; @@ -149,14 +149,12 @@ __Z_INLINE void handleSignHash(volatile uint32_t *flags, volatile uint32_t *tx, *flags |= IO_ASYNCH_REPLY; } - __Z_INLINE void handleSignTransaction(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx) { zemu_log("handleSignTransaction\n"); if (!process_chunk(tx, rx)) { THROW(APDU_CODE_OK); } - const char *error_msg = tx_parse(tx_type_transaction); CHECK_APP_CANARY() if (error_msg != NULL) { diff --git a/app/src/common/tx.h b/app/src/common/tx.h index 40f57d7..b85579f 100644 --- a/app/src/common/tx.h +++ b/app/src/common/tx.h @@ -17,8 +17,8 @@ #include "coin.h" #include "os.h" -#include "zxerror.h" #include "parser_txdef.h" +#include "zxerror.h" void tx_initialize(); diff --git a/app/src/crypto.c b/app/src/crypto.c index a41e622..5d71170 100644 --- a/app/src/crypto.c +++ b/app/src/crypto.c @@ -19,9 +19,9 @@ #include "coin.h" #include "crypto_helper.h" #include "cx.h" +#include "parser_txdef.h" #include "zxformat.h" #include "zxmacros.h" -#include "parser_txdef.h" uint32_t hdPath[HDPATH_LEN_DEFAULT]; @@ -63,7 +63,8 @@ zxerr_t crypto_extractPublicKey(uint8_t *pubKey, uint16_t pubKeyLen) { return error; } -zxerr_t crypto_sign(uint8_t *signature, uint16_t signatureMaxlen, const uint8_t *message, uint16_t messageLen, tx_type_t tx_type) { +zxerr_t crypto_sign(uint8_t *signature, uint16_t signatureMaxlen, const uint8_t *message, uint16_t messageLen, + tx_type_t tx_type) { if (signature == NULL || message == NULL || signatureMaxlen < ED25519_SIGNATURE_SIZE || messageLen == 0) { return zxerr_invalid_crypto_settings; } diff --git a/app/src/crypto.h b/app/src/crypto.h index 70f9eab..e49bfad 100644 --- a/app/src/crypto.h +++ b/app/src/crypto.h @@ -24,14 +24,15 @@ extern "C" { #include #include "coin.h" -#include "zxerror.h" #include "parser_txdef.h" +#include "zxerror.h" extern uint32_t hdPath[HDPATH_LEN_DEFAULT]; zxerr_t crypto_fillAddress(uint8_t *buffer, uint16_t bufferLen, uint16_t *addrResponseLen); -zxerr_t crypto_sign(uint8_t *signature, uint16_t signatureMaxlen, const uint8_t *message, uint16_t messageLen, tx_type_t tx_type); +zxerr_t crypto_sign(uint8_t *signature, uint16_t signatureMaxlen, const uint8_t *message, uint16_t messageLen, + tx_type_t tx_type); #ifdef __cplusplus } diff --git a/app/src/items.c b/app/src/items.c index 50bb05c..880b7be 100644 --- a/app/src/items.c +++ b/app/src/items.c @@ -369,8 +369,8 @@ static items_error_t items_computeHash(tx_type_t tx_type) { tx_hash_t *hash_obj = parser_getParserHashObj(); base64_encode(base64_hash, 44, (uint8_t *)hash_obj->tx, hash_obj->hash_len); } else { - if (blake2b_hash((uint8_t *)parser_getParserJsonObj()->json.buffer, parser_getParserJsonObj()->json.bufferLen, hash) != - zxerr_ok) { + if (blake2b_hash((uint8_t *)parser_getParserJsonObj()->json.buffer, parser_getParserJsonObj()->json.bufferLen, + hash) != zxerr_ok) { return items_error; } diff --git a/app/src/items.h b/app/src/items.h index ee49ddf..d9162e1 100644 --- a/app/src/items.h +++ b/app/src/items.h @@ -20,8 +20,8 @@ #include "items_defs.h" #include "json_parser.h" #include "parser_common.h" -#include "zxtypes.h" #include "parser_txdef.h" +#include "zxtypes.h" items_error_t items_initItems(); items_error_t items_storeItems(tx_type_t tx_type); diff --git a/app/src/items_format.h b/app/src/items_format.h index 6d3f60e..521f437 100644 --- a/app/src/items_format.h +++ b/app/src/items_format.h @@ -23,7 +23,8 @@ #define WARNING_TEXT \ "UNSAFE TRANSACTION. This transaction's code was not recognized and does not limit capabilities for all signers. " \ "Signing this transaction may make arbitrary actions on the chain including loss of all funds." -#define HASH_WARNING_TEXT "Blind Signing a Transaction Hash is a very unusual operation. Do not continue unless you know what you are doing" +#define HASH_WARNING_TEXT \ + "Blind Signing a Transaction Hash is a very unusual operation. Do not continue unless you know what you are doing" #define CAUTION_TEXT "'meta' field of transaction not recognized" #define TX_TOO_LARGE_TEXT \ "Transaction too large for Ledger to display. PROCEED WITH GREAT CAUTION. Do you want to continue?" diff --git a/app/src/parser.c b/app/src/parser.c index 6db4b8d..407137e 100644 --- a/app/src/parser.c +++ b/app/src/parser.c @@ -32,21 +32,17 @@ tx_json_t tx_obj_json; tx_hash_t tx_obj_hash; -char +char #if defined(TARGET_NANOS) -// For nanos, jsonTemplate does not fit in RAM. -__attribute__((section(".text"))) + // For nanos, jsonTemplate does not fit in RAM. + __attribute__((section(".text"))) #endif -jsonTemplate[1200] = {0}; + jsonTemplate[1200] = {0}; uint16_t jsonTemplateLen; -char *parser_get_json_template_buffer() { - return jsonTemplate; -} +char *parser_get_json_template_buffer() { return jsonTemplate; } -uint16_t parser_get_json_template_buffer_len() { - return jsonTemplateLen; -} +uint16_t parser_get_json_template_buffer_len() { return jsonTemplateLen; } parser_error_t parser_init_context(parser_context_t *ctx, const uint8_t *buffer, uint16_t bufferSize) { ctx->offset = 0; @@ -75,11 +71,11 @@ parser_error_t parser_parse(parser_context_t *ctx, const uint8_t *data, size_t d } else if (tx_type == tx_type_transaction) { parser_createJsonTemplate(ctx, jsonTemplate, sizeof(jsonTemplate), &jsonTemplateLen); ctx->json = &tx_obj_json; - ctx->buffer = (const uint8_t *) jsonTemplate; + ctx->buffer = (const uint8_t *)jsonTemplate; ctx->bufferLen = jsonTemplateLen; CHECK_ERROR(_read_json_tx(ctx)); - } + } ITEMS_TO_PARSER_ERROR(items_initItems()) ITEMS_TO_PARSER_ERROR(items_storeItems(tx_type)) diff --git a/app/src/parser_impl.c b/app/src/parser_impl.c index 6652caa..54b900a 100644 --- a/app/src/parser_impl.c +++ b/app/src/parser_impl.c @@ -16,43 +16,43 @@ #include "parser_impl.h" +#include "crypto.h" #include "crypto_helper.h" #include "items.h" -#include "crypto.h" #include "zxformat.h" -#define TRANSFER_FORMAT \ +#define TRANSFER_FORMAT \ "{\"networkId\":\"%.*s\",\"payload\":{\"exec\":{\"data\":{},\"code\":\"(%.*s.transfer " \ "\\\"k:%.*s\\\" \\\"k:%.*s\\\" %.*s)\"}},\"signers\":[{\"pubKey\":\"%.*s\",\"clist\":[" \ - "{\"args\":[\"k:%.*s\",\"k:%.*s\",%.*s],\"name\":\"%.*s.TRANSFER\"}," \ - "{\"args\":[],\"name\":\"coin.GAS\"}]}],\"meta\":{\"creationTime\":%.*s," \ - "\"ttl\":%.*s,\"gasLimit\":%.*s,\"chainId\":\"%.*s\",\"gasPrice\":%.*s," \ + "{\"args\":[\"k:%.*s\",\"k:%.*s\",%.*s],\"name\":\"%.*s.TRANSFER\"}," \ + "{\"args\":[],\"name\":\"coin.GAS\"}]}],\"meta\":{\"creationTime\":%.*s," \ + "\"ttl\":%.*s,\"gasLimit\":%.*s,\"chainId\":\"%.*s\",\"gasPrice\":%.*s," \ "\"sender\":\"k:%.*s\"},\"nonce\":\"%.*s\"}" -#define TRANSFER_CREATE_FORMAT \ +#define TRANSFER_CREATE_FORMAT \ "{\"networkId\":\"%.*s\",\"payload\":{\"exec\":{\"data\":{\"ks\":{\"pred\":\"keys-all\"," \ - "\"keys\":[\"%.*s\"]}},\"code\":\"(%.*s.transfer-create \\\"k:%.*s\\\" \\\"k:%.*s\\\" " \ - "(read-keyset \\\"ks\\\") %.*s)\"}},\"signers\":[{\"pubKey\":\"%.*s\",\"clist\":[" \ - "{\"args\":[\"k:%.*s\",\"k:%.*s\",%.*s],\"name\":\"%.*s.TRANSFER\"}," \ - "{\"args\":[],\"name\":\"coin.GAS\"}]}],\"meta\":{\"creationTime\":%.*s," \ - "\"ttl\":%.*s,\"gasLimit\":%.*s,\"chainId\":\"%.*s\",\"gasPrice\":%.*s," \ + "\"keys\":[\"%.*s\"]}},\"code\":\"(%.*s.transfer-create \\\"k:%.*s\\\" \\\"k:%.*s\\\" " \ + "(read-keyset \\\"ks\\\") %.*s)\"}},\"signers\":[{\"pubKey\":\"%.*s\",\"clist\":[" \ + "{\"args\":[\"k:%.*s\",\"k:%.*s\",%.*s],\"name\":\"%.*s.TRANSFER\"}," \ + "{\"args\":[],\"name\":\"coin.GAS\"}]}],\"meta\":{\"creationTime\":%.*s," \ + "\"ttl\":%.*s,\"gasLimit\":%.*s,\"chainId\":\"%.*s\",\"gasPrice\":%.*s," \ "\"sender\":\"k:%.*s\"},\"nonce\":\"%.*s\"}" -#define TRANSFER_CROSSCHAIN_FORMAT \ - "{\"networkId\":\"%.*s\",\"payload\":{\"exec\":{\"data\":{\"ks\":{\"pred\":\"keys-all\"," \ - "\"keys\":[\"%.*s\"]}},\"code\":\"(%.*s.transfer-crosschain \\\"k:%.*s\\\" \\\"k:%.*s\\\" " \ +#define TRANSFER_CROSSCHAIN_FORMAT \ + "{\"networkId\":\"%.*s\",\"payload\":{\"exec\":{\"data\":{\"ks\":{\"pred\":\"keys-all\"," \ + "\"keys\":[\"%.*s\"]}},\"code\":\"(%.*s.transfer-crosschain \\\"k:%.*s\\\" \\\"k:%.*s\\\" " \ "(read-keyset \\\"ks\\\") \\\"%.*s\\\" %.*s)\"}},\"signers\":[{\"pubKey\":\"%.*s\",\"clist\":[" \ - "{\"args\":[\"k:%.*s\",\"k:%.*s\",%.*s,\"%.*s\"],\"name\":\"%.*s.TRANSFER_XCHAIN\"}," \ - "{\"args\":[],\"name\":\"coin.GAS\"}]}],\"meta\":{\"creationTime\":%.*s," \ - "\"ttl\":%.*s,\"gasLimit\":%.*s,\"chainId\":\"%.*s\",\"gasPrice\":%.*s," \ + "{\"args\":[\"k:%.*s\",\"k:%.*s\",%.*s,\"%.*s\"],\"name\":\"%.*s.TRANSFER_XCHAIN\"}," \ + "{\"args\":[],\"name\":\"coin.GAS\"}]}],\"meta\":{\"creationTime\":%.*s," \ + "\"ttl\":%.*s,\"gasLimit\":%.*s,\"chainId\":\"%.*s\",\"gasPrice\":%.*s," \ "\"sender\":\"k:%.*s\"},\"nonce\":\"%.*s\"}" #if defined(TARGET_NANOS) -#define INCREMENT_POINTER_NVM(inc) { \ - if (ptr + inc > jsonTemplate + jsonTemplateSize) \ - return parser_unexpected_buffer_end; \ - ptr += inc; \ -} +#define INCREMENT_POINTER_NVM(inc) \ + { \ + if (ptr + inc > jsonTemplate + jsonTemplateSize) return parser_unexpected_buffer_end; \ + ptr += inc; \ + } #endif #define RECIPIENT_POS 0 @@ -70,9 +70,13 @@ static parser_error_t parser_readSingleByte(parser_context_t *ctx, uint8_t *byte); static parser_error_t parser_readBytes(parser_context_t *ctx, uint8_t **bytes, uint16_t len); -static parser_error_t parser_formatTxTransfer(char *jsonTemplate, uint16_t jsonTemplateSize, uint16_t *jsonTemplateLen, uint16_t address_len, char *address, chunk_t *chunks); -static parser_error_t parser_formatTxTransferCreate(char *jsonTemplate, uint16_t jsonTemplateSize, uint16_t *jsonTemplateLen, uint16_t address_len, char *address, chunk_t *chunks); -static parser_error_t parser_formatTxTransferCrosschain(char *jsonTemplate, uint16_t jsonTemplateSize, uint16_t *jsonTemplateLen, uint16_t address_len, char *address, chunk_t *chunks); +static parser_error_t parser_formatTxTransfer(char *jsonTemplate, uint16_t jsonTemplateSize, uint16_t *jsonTemplateLen, + uint16_t address_len, char *address, chunk_t *chunks); +static parser_error_t parser_formatTxTransferCreate(char *jsonTemplate, uint16_t jsonTemplateSize, uint16_t *jsonTemplateLen, + uint16_t address_len, char *address, chunk_t *chunks); +static parser_error_t parser_formatTxTransferCrosschain(char *jsonTemplate, uint16_t jsonTemplateSize, + uint16_t *jsonTemplateLen, uint16_t address_len, char *address, + chunk_t *chunks); tx_json_t *parser_json_obj; tx_hash_t *parser_hash_obj; @@ -103,7 +107,7 @@ parser_error_t _read_hash_tx(parser_context_t *c) { tx_json_t *parser_getParserJsonObj() { return parser_json_obj; } tx_hash_t *parser_getParserHashObj() { return parser_hash_obj; } - + parser_error_t parser_findPubKeyInClist(uint16_t key_token_index) { parsed_json_t *json_all = &parser_json_obj->json; uint16_t token_index = 0; @@ -257,8 +261,9 @@ bool items_isNullField(uint16_t json_token_index) { return (MEMCMP("null", json_all->buffer + token->start, token->end - token->start) == 0); } - -parser_error_t parser_createJsonTemplate(parser_context_t *ctx, char *jsonTemplate, uint16_t jsonTemplateSize, uint16_t *jsonTemplateLen) { + +parser_error_t parser_createJsonTemplate(parser_context_t *ctx, char *jsonTemplate, uint16_t jsonTemplateSize, + uint16_t *jsonTemplateLen) { // read tx_type uint8_t tx_type = 0; parser_readSingleByte(ctx, &tx_type); @@ -286,7 +291,8 @@ parser_error_t parser_createJsonTemplate(parser_context_t *ctx, char *jsonTempla uint32_t address_len = array_to_hexstr(address, sizeof(address), pubkey, PUB_KEY_LENGTH); #else // Dummy address for cpp_test - uint32_t address_len = snprintf(address, sizeof(address), "%s", "1234567890123456789012345678901234567890123456789012345678901234"); + uint32_t address_len = + snprintf(address, sizeof(address), "%s", "1234567890123456789012345678901234567890123456789012345678901234"); #endif switch (tx_type) { @@ -329,34 +335,25 @@ static parser_error_t parser_readBytes(parser_context_t *ctx, uint8_t **bytes, u return parser_ok; } -static parser_error_t parser_formatTxTransfer(char *jsonTemplate, uint16_t jsonTemplateSize, uint16_t *jsonTemplateLen, uint16_t address_len, char *address, chunk_t *chunks) { +static parser_error_t parser_formatTxTransfer(char *jsonTemplate, uint16_t jsonTemplateSize, uint16_t *jsonTemplateLen, + uint16_t address_len, char *address, chunk_t *chunks) { char namespace_and_module[30] = {0}; if (chunks[NAMESPACE_POS].len > 0 && chunks[MODULE_POS].len > 0) { - snprintf(namespace_and_module, sizeof(namespace_and_module), "%.*s.%.*s", chunks[NAMESPACE_POS].len, chunks[NAMESPACE_POS].data, chunks[MODULE_POS].len, chunks[MODULE_POS].data); + snprintf(namespace_and_module, sizeof(namespace_and_module), "%.*s.%.*s", chunks[NAMESPACE_POS].len, + chunks[NAMESPACE_POS].data, chunks[MODULE_POS].len, chunks[MODULE_POS].data); } else { snprintf(namespace_and_module, sizeof(namespace_and_module), "%s", "coin"); } #if !defined(TARGET_NANOS) - snprintf(jsonTemplate, jsonTemplateSize, TRANSFER_FORMAT, - chunks[NETWORK_POS].len, chunks[NETWORK_POS].data, - strlen(namespace_and_module), namespace_and_module, - address_len, address, - chunks[RECIPIENT_POS].len, chunks[RECIPIENT_POS].data, - chunks[AMOUNT_POS].len, chunks[AMOUNT_POS].data, - address_len, address, - address_len, address, - chunks[RECIPIENT_POS].len, chunks[RECIPIENT_POS].data, - chunks[AMOUNT_POS].len, chunks[AMOUNT_POS].data, - strlen(namespace_and_module), namespace_and_module, - chunks[CREATION_TIME_POS].len, chunks[CREATION_TIME_POS].data, - chunks[TTL_POS].len, chunks[TTL_POS].data, - chunks[GAS_LIMIT_POS].len, chunks[GAS_LIMIT_POS].data, - chunks[CHAIN_ID_POS].len, chunks[CHAIN_ID_POS].data, - chunks[GAS_PRICE_POS].len, chunks[GAS_PRICE_POS].data, - address_len, address, - chunks[NONCE_POS].len, chunks[NONCE_POS].data - ); + snprintf(jsonTemplate, jsonTemplateSize, TRANSFER_FORMAT, chunks[NETWORK_POS].len, chunks[NETWORK_POS].data, + (int)strlen(namespace_and_module), namespace_and_module, address_len, address, chunks[RECIPIENT_POS].len, + chunks[RECIPIENT_POS].data, chunks[AMOUNT_POS].len, chunks[AMOUNT_POS].data, address_len, address, address_len, + address, chunks[RECIPIENT_POS].len, chunks[RECIPIENT_POS].data, chunks[AMOUNT_POS].len, chunks[AMOUNT_POS].data, + (int)strlen(namespace_and_module), namespace_and_module, chunks[CREATION_TIME_POS].len, + chunks[CREATION_TIME_POS].data, chunks[TTL_POS].len, chunks[TTL_POS].data, chunks[GAS_LIMIT_POS].len, + chunks[GAS_LIMIT_POS].data, chunks[CHAIN_ID_POS].len, chunks[CHAIN_ID_POS].data, chunks[GAS_PRICE_POS].len, + chunks[GAS_PRICE_POS].data, address_len, address, chunks[NONCE_POS].len, chunks[NONCE_POS].data); *jsonTemplateLen = strlen(jsonTemplate); #else @@ -442,35 +439,26 @@ static parser_error_t parser_formatTxTransfer(char *jsonTemplate, uint16_t jsonT return parser_ok; } -static parser_error_t parser_formatTxTransferCreate(char *jsonTemplate, uint16_t jsonTemplateSize, uint16_t *jsonTemplateLen, uint16_t address_len, char *address, chunk_t *chunks) { +static parser_error_t parser_formatTxTransferCreate(char *jsonTemplate, uint16_t jsonTemplateSize, uint16_t *jsonTemplateLen, + uint16_t address_len, char *address, chunk_t *chunks) { char namespace_and_module[30] = {0}; if (chunks[NAMESPACE_POS].len > 0 && chunks[MODULE_POS].len > 0) { - snprintf(namespace_and_module, sizeof(namespace_and_module), "%.*s.%.*s", chunks[NAMESPACE_POS].len, chunks[NAMESPACE_POS].data, chunks[MODULE_POS].len, chunks[MODULE_POS].data); + snprintf(namespace_and_module, sizeof(namespace_and_module), "%.*s.%.*s", chunks[NAMESPACE_POS].len, + chunks[NAMESPACE_POS].data, chunks[MODULE_POS].len, chunks[MODULE_POS].data); } else { snprintf(namespace_and_module, sizeof(namespace_and_module), "%s", "coin"); } #if !defined(TARGET_NANOS) - snprintf(jsonTemplate, jsonTemplateSize, TRANSFER_CREATE_FORMAT, - chunks[NETWORK_POS].len, chunks[NETWORK_POS].data, - chunks[RECIPIENT_POS].len, chunks[RECIPIENT_POS].data, - strlen(namespace_and_module), namespace_and_module, - address_len, address, - chunks[RECIPIENT_POS].len, chunks[RECIPIENT_POS].data, - chunks[AMOUNT_POS].len, chunks[AMOUNT_POS].data, - address_len, address, - address_len, address, - chunks[RECIPIENT_POS].len, chunks[RECIPIENT_POS].data, - chunks[AMOUNT_POS].len, chunks[AMOUNT_POS].data, - strlen(namespace_and_module), namespace_and_module, - chunks[CREATION_TIME_POS].len, chunks[CREATION_TIME_POS].data, - chunks[TTL_POS].len, chunks[TTL_POS].data, - chunks[GAS_LIMIT_POS].len, chunks[GAS_LIMIT_POS].data, - chunks[CHAIN_ID_POS].len, chunks[CHAIN_ID_POS].data, - chunks[GAS_PRICE_POS].len, chunks[GAS_PRICE_POS].data, - address_len, address, - chunks[NONCE_POS].len, chunks[NONCE_POS].data - ); + snprintf(jsonTemplate, jsonTemplateSize, TRANSFER_CREATE_FORMAT, chunks[NETWORK_POS].len, chunks[NETWORK_POS].data, + chunks[RECIPIENT_POS].len, chunks[RECIPIENT_POS].data, (int)strlen(namespace_and_module), namespace_and_module, + address_len, address, chunks[RECIPIENT_POS].len, chunks[RECIPIENT_POS].data, chunks[AMOUNT_POS].len, + chunks[AMOUNT_POS].data, address_len, address, address_len, address, chunks[RECIPIENT_POS].len, + chunks[RECIPIENT_POS].data, chunks[AMOUNT_POS].len, chunks[AMOUNT_POS].data, (int)strlen(namespace_and_module), + namespace_and_module, chunks[CREATION_TIME_POS].len, chunks[CREATION_TIME_POS].data, chunks[TTL_POS].len, + chunks[TTL_POS].data, chunks[GAS_LIMIT_POS].len, chunks[GAS_LIMIT_POS].data, chunks[CHAIN_ID_POS].len, + chunks[CHAIN_ID_POS].data, chunks[GAS_PRICE_POS].len, chunks[GAS_PRICE_POS].data, address_len, address, + chunks[NONCE_POS].len, chunks[NONCE_POS].data); *jsonTemplateLen = strlen(jsonTemplate); #else @@ -558,36 +546,27 @@ static parser_error_t parser_formatTxTransferCreate(char *jsonTemplate, uint16_t return parser_ok; } -static parser_error_t parser_formatTxTransferCrosschain(char *jsonTemplate, uint16_t jsonTemplateSize, uint16_t *jsonTemplateLen, uint16_t address_len, char *address, chunk_t *chunks) { +static parser_error_t parser_formatTxTransferCrosschain(char *jsonTemplate, uint16_t jsonTemplateSize, + uint16_t *jsonTemplateLen, uint16_t address_len, char *address, + chunk_t *chunks) { char namespace_and_module[30] = {0}; if (chunks[NAMESPACE_POS].len > 0 && chunks[MODULE_POS].len > 0) { - snprintf(namespace_and_module, sizeof(namespace_and_module), "%.*s.%.*s", chunks[NAMESPACE_POS].len, chunks[NAMESPACE_POS].data, chunks[MODULE_POS].len, chunks[MODULE_POS].data); + snprintf(namespace_and_module, sizeof(namespace_and_module), "%.*s.%.*s", chunks[NAMESPACE_POS].len, + chunks[NAMESPACE_POS].data, chunks[MODULE_POS].len, chunks[MODULE_POS].data); } else { snprintf(namespace_and_module, sizeof(namespace_and_module), "%s", "coin"); } #if !defined(TARGET_NANOS) - snprintf(jsonTemplate, jsonTemplateSize, TRANSFER_CROSSCHAIN_FORMAT, - chunks[NETWORK_POS].len, chunks[NETWORK_POS].data, - chunks[RECIPIENT_POS].len, chunks[RECIPIENT_POS].data, - strlen(namespace_and_module), namespace_and_module, - address_len, address, - chunks[RECIPIENT_POS].len, chunks[RECIPIENT_POS].data, - chunks[RECIPIENT_CHAIN_POS].len, chunks[RECIPIENT_CHAIN_POS].data, - chunks[AMOUNT_POS].len, chunks[AMOUNT_POS].data, - address_len, address, - address_len, address, - chunks[RECIPIENT_POS].len, chunks[RECIPIENT_POS].data, - chunks[AMOUNT_POS].len, chunks[AMOUNT_POS].data, - chunks[RECIPIENT_CHAIN_POS].len, chunks[RECIPIENT_CHAIN_POS].data, - strlen(namespace_and_module), namespace_and_module, - chunks[CREATION_TIME_POS].len, chunks[CREATION_TIME_POS].data, - chunks[TTL_POS].len, chunks[TTL_POS].data, - chunks[GAS_LIMIT_POS].len, chunks[GAS_LIMIT_POS].data, - chunks[CHAIN_ID_POS].len, chunks[CHAIN_ID_POS].data, - chunks[GAS_PRICE_POS].len, chunks[GAS_PRICE_POS].data, - address_len, address, - chunks[NONCE_POS].len, chunks[NONCE_POS].data - ); + snprintf(jsonTemplate, jsonTemplateSize, TRANSFER_CROSSCHAIN_FORMAT, chunks[NETWORK_POS].len, chunks[NETWORK_POS].data, + chunks[RECIPIENT_POS].len, chunks[RECIPIENT_POS].data, (int)strlen(namespace_and_module), namespace_and_module, + address_len, address, chunks[RECIPIENT_POS].len, chunks[RECIPIENT_POS].data, chunks[RECIPIENT_CHAIN_POS].len, + chunks[RECIPIENT_CHAIN_POS].data, chunks[AMOUNT_POS].len, chunks[AMOUNT_POS].data, address_len, address, + address_len, address, chunks[RECIPIENT_POS].len, chunks[RECIPIENT_POS].data, chunks[AMOUNT_POS].len, + chunks[AMOUNT_POS].data, chunks[RECIPIENT_CHAIN_POS].len, chunks[RECIPIENT_CHAIN_POS].data, + (int)strlen(namespace_and_module), namespace_and_module, chunks[CREATION_TIME_POS].len, + chunks[CREATION_TIME_POS].data, chunks[TTL_POS].len, chunks[TTL_POS].data, chunks[GAS_LIMIT_POS].len, + chunks[GAS_LIMIT_POS].data, chunks[CHAIN_ID_POS].len, chunks[CHAIN_ID_POS].data, chunks[GAS_PRICE_POS].len, + chunks[GAS_PRICE_POS].data, address_len, address, chunks[NONCE_POS].len, chunks[NONCE_POS].data); *jsonTemplateLen = strlen(jsonTemplate); #else @@ -646,7 +625,8 @@ static parser_error_t parser_formatTxTransferCrosschain(char *jsonTemplate, uint INCREMENT_POINTER_NVM(11) MEMCPY_NV((void *)ptr, namespace_and_module, strlen(namespace_and_module)); INCREMENT_POINTER_NVM(strlen(namespace_and_module)) - MEMCPY_NV((void *)ptr, (void *)".TRANSFER_XCHAIN\"},{\"args\":[],\"name\":\"coin.GAS\"}]}],\"meta\":{\"creationTime\":", 75); + MEMCPY_NV((void *)ptr, + (void *)".TRANSFER_XCHAIN\"},{\"args\":[],\"name\":\"coin.GAS\"}]}],\"meta\":{\"creationTime\":", 75); INCREMENT_POINTER_NVM(75) MEMCPY_NV((void *)ptr, chunks[CREATION_TIME_POS].data, chunks[CREATION_TIME_POS].len); INCREMENT_POINTER_NVM(chunks[CREATION_TIME_POS].len) diff --git a/app/src/parser_impl.h b/app/src/parser_impl.h index 493fd5e..094071c 100644 --- a/app/src/parser_impl.h +++ b/app/src/parser_impl.h @@ -70,7 +70,8 @@ parser_error_t parser_validateMetaField(); parser_error_t parser_getTxName(uint16_t token_index); parser_error_t parser_getValidClist(uint16_t *clist_token_index, uint16_t *num_args); bool items_isNullField(uint16_t json_token_index); -parser_error_t parser_createJsonTemplate(parser_context_t *ctx, char *jsonTemplate, uint16_t jsonTemplateSize, uint16_t *jsonTemplateLen); +parser_error_t parser_createJsonTemplate(parser_context_t *ctx, char *jsonTemplate, uint16_t jsonTemplateSize, + uint16_t *jsonTemplateLen); #ifdef __cplusplus } diff --git a/app/src/parser_txdef.h b/app/src/parser_txdef.h index a7da46f..89de1c3 100644 --- a/app/src/parser_txdef.h +++ b/app/src/parser_txdef.h @@ -25,11 +25,7 @@ extern "C" { #include "coin.h" -typedef enum tx_type_t { - tx_type_json, - tx_type_hash, - tx_type_transaction -} tx_type_t; +typedef enum tx_type_t { tx_type_json, tx_type_hash, tx_type_transaction } tx_type_t; typedef struct { // Buffer to the original tx blob