New common function to get the NFT contract address

This commit is contained in:
Alexandre Paillier
2022-02-15 14:11:22 +01:00
parent 2e63a428b2
commit ce2df92741
4 changed files with 16 additions and 35 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,

View File

@@ -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,