From ce2df92741a0789ee90ad58e50d21332c2e86b3e Mon Sep 17 00:00:00 2001 From: Alexandre Paillier Date: Tue, 15 Feb 2022 14:11:22 +0100 Subject: [PATCH] New common function to get the NFT contract address --- src_common/ethUtils.c | 6 ++++++ src_common/ethUtils.h | 4 ++++ src_plugins/erc1155/erc1155_ui.c | 20 +++----------------- src_plugins/erc721/erc721_ui.c | 21 +++------------------ 4 files changed, 16 insertions(+), 35 deletions(-) diff --git a/src_common/ethUtils.c b/src_common/ethUtils.c index eb9ddf6..d3c71b0 100644 --- a/src_common/ethUtils.c +++ b/src_common/ethUtils.c @@ -237,6 +237,12 @@ void getEthDisplayableAddress(uint8_t *in, getEthAddressStringFromBinary(in, out + 2, sha3, chainId); } +uint8_t *getNftContractAddress(const ethQueryContractUI_t *const msg) { + // In case of no PROVIDE_NFT_INFO, we already have the address from the SET_PLUGIN + return ((msg->item1) ? ((uint8_t *) msg->item1->nft.contractAddress) + : msg->pluginSharedRO->txContent->destination); +} + bool adjustDecimals(char *src, uint32_t srcLength, char *target, diff --git a/src_common/ethUtils.h b/src_common/ethUtils.h index 2f66b29..af88517 100644 --- a/src_common/ethUtils.h +++ b/src_common/ethUtils.h @@ -22,6 +22,8 @@ #include "cx.h" #include "chainConfig.h" +#include "eth_plugin_interface.h" + /** * @brief Decode an RLP encoded field - see * https://github.com/ethereum/wiki/wiki/RLP @@ -57,6 +59,8 @@ void getEthDisplayableAddress(uint8_t *in, cx_sha3_t *sha3, uint64_t chainId); +uint8_t *getNftContractAddress(const ethQueryContractUI_t *const msg); + bool adjustDecimals(char *src, uint32_t srcLength, char *target, diff --git a/src_plugins/erc1155/erc1155_ui.c b/src_plugins/erc1155/erc1155_ui.c index 57d6014..e2679d4 100644 --- a/src_plugins/erc1155/erc1155_ui.c +++ b/src_plugins/erc1155/erc1155_ui.c @@ -3,8 +3,6 @@ #include "erc1155_plugin.h" static void set_approval_for_all_ui(ethQueryContractUI_t *msg, erc1155_context_t *context) { - uint8_t *nft_addr; - switch (msg->screenIndex) { case 0: if (context->approved) { @@ -28,10 +26,7 @@ static void set_approval_for_all_ui(ethQueryContractUI_t *msg, erc1155_context_t break; case 2: strlcpy(msg->title, "NFT Address", msg->titleLength); - // In case of no PROVIDE_NFT_INFO, we already have the address from the SET_PLUGIN - nft_addr = ((msg->item1) ? ((uint8_t *) msg->item1->nft.contractAddress) - : msg->pluginSharedRO->txContent->destination); - getEthDisplayableAddress(nft_addr, + getEthDisplayableAddress(getNftContractAddress(msg), msg->msg, msg->msgLength, &global_sha3, @@ -45,8 +40,6 @@ static void set_approval_for_all_ui(ethQueryContractUI_t *msg, erc1155_context_t } static void set_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t *context) { - uint8_t *nft_addr; - switch (msg->screenIndex) { case 0: strlcpy(msg->title, "To", msg->titleLength); @@ -66,10 +59,7 @@ static void set_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t *contex break; case 2: strlcpy(msg->title, "NFT Address", msg->titleLength); - // In case of no PROVIDE_NFT_INFO, we already have the address from the SET_PLUGIN - nft_addr = ((msg->item1) ? ((uint8_t *) msg->item1->nft.contractAddress) - : msg->pluginSharedRO->txContent->destination); - getEthDisplayableAddress(nft_addr, + getEthDisplayableAddress(getNftContractAddress(msg), msg->msg, msg->msgLength, &global_sha3, @@ -95,7 +85,6 @@ static void set_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t *contex static void set_batch_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t *context) { char quantity_str[48]; - uint8_t *nft_addr; switch (msg->screenIndex) { case 0: @@ -116,10 +105,7 @@ static void set_batch_transfer_ui(ethQueryContractUI_t *msg, erc1155_context_t * break; case 2: strlcpy(msg->title, "NFT Address", msg->titleLength); - // In case of no PROVIDE_NFT_INFO, we already have the address from the SET_PLUGIN - nft_addr = ((msg->item1) ? ((uint8_t *) msg->item1->nft.contractAddress) - : msg->pluginSharedRO->txContent->destination); - getEthDisplayableAddress(nft_addr, + getEthDisplayableAddress(getNftContractAddress(msg), msg->msg, msg->msgLength, &global_sha3, diff --git a/src_plugins/erc721/erc721_ui.c b/src_plugins/erc721/erc721_ui.c index fb8db17..ce0c4f5 100644 --- a/src_plugins/erc721/erc721_ui.c +++ b/src_plugins/erc721/erc721_ui.c @@ -3,8 +3,6 @@ #include "erc721_plugin.h" static void set_approval_ui(ethQueryContractUI_t *msg, erc721_context_t *context) { - uint8_t *nft_addr; - switch (msg->screenIndex) { case 0: strlcpy(msg->title, "Allow", msg->titleLength); @@ -24,10 +22,7 @@ static void set_approval_ui(ethQueryContractUI_t *msg, erc721_context_t *context break; case 2: strlcpy(msg->title, "NFT Address", msg->titleLength); - // In case of no PROVIDE_NFT_INFO, we already have the address from the SET_PLUGIN - nft_addr = ((msg->item1) ? ((uint8_t *) msg->item1->nft.contractAddress) - : msg->pluginSharedRO->txContent->destination); - getEthDisplayableAddress(nft_addr, + getEthDisplayableAddress(getNftContractAddress(msg), msg->msg, msg->msgLength, &global_sha3, @@ -48,8 +43,6 @@ static void set_approval_ui(ethQueryContractUI_t *msg, erc721_context_t *context } static void set_approval_for_all_ui(ethQueryContractUI_t *msg, erc721_context_t *context) { - uint8_t *nft_addr; - switch (msg->screenIndex) { case 0: if (context->approved) { @@ -73,10 +66,7 @@ static void set_approval_for_all_ui(ethQueryContractUI_t *msg, erc721_context_t break; case 2: strlcpy(msg->title, "NFT Address", msg->titleLength); - // In case of no PROVIDE_NFT_INFO, we already have the address from the SET_PLUGIN - nft_addr = ((msg->item1) ? ((uint8_t *) msg->item1->nft.contractAddress) - : msg->pluginSharedRO->txContent->destination); - getEthDisplayableAddress(nft_addr, + getEthDisplayableAddress(getNftContractAddress(msg), msg->msg, msg->msgLength, &global_sha3, @@ -90,8 +80,6 @@ static void set_approval_for_all_ui(ethQueryContractUI_t *msg, erc721_context_t } static void set_transfer_ui(ethQueryContractUI_t *msg, erc721_context_t *context) { - uint8_t *nft_addr; - switch (msg->screenIndex) { case 0: strlcpy(msg->title, "To", msg->titleLength); @@ -111,10 +99,7 @@ static void set_transfer_ui(ethQueryContractUI_t *msg, erc721_context_t *context break; case 2: strlcpy(msg->title, "NFT Address", msg->titleLength); - // In case of no PROVIDE_NFT_INFO, we already have the address from the SET_PLUGIN - nft_addr = ((msg->item1) ? ((uint8_t *) msg->item1->nft.contractAddress) - : msg->pluginSharedRO->txContent->destination); - getEthDisplayableAddress(nft_addr, + getEthDisplayableAddress(getNftContractAddress(msg), msg->msg, msg->msgLength, &global_sha3,