Refactoring helper to get printable eth address from hex
This commit is contained in:
@@ -212,12 +212,11 @@ void erc20_plugin_call(int message, void *parameters) {
|
||||
strlcpy(msg->msg, context->contract_name, msg->msgLength);
|
||||
} else {
|
||||
strlcpy(msg->title, "Address", msg->titleLength);
|
||||
msg->msg[0] = '0';
|
||||
msg->msg[1] = 'x';
|
||||
getEthAddressStringFromBinary(context->destinationAddress,
|
||||
msg->msg + 2,
|
||||
msg->pluginSharedRW->sha3,
|
||||
chainConfig);
|
||||
getEthDisplayableAddress(context->destinationAddress,
|
||||
msg->msg,
|
||||
msg->msgLength,
|
||||
msg->pluginSharedRW->sha3,
|
||||
chainConfig);
|
||||
}
|
||||
|
||||
msg->result = ETH_PLUGIN_RESULT_OK;
|
||||
|
||||
@@ -5,8 +5,11 @@
|
||||
#include "ethUtils.h"
|
||||
#include "utils.h"
|
||||
|
||||
void starkware_print_stark_key(uint8_t *starkKey, char *destination);
|
||||
void starkware_print_eth_address(uint8_t *address, char *destination);
|
||||
void getEthDisplayableAddress(uint8_t *in,
|
||||
char *out,
|
||||
size_t out_len,
|
||||
cx_sha3_t *sha3,
|
||||
chain_config_t *chain_config);
|
||||
|
||||
typedef struct erc721_parameters_t {
|
||||
uint8_t selectorIndex;
|
||||
@@ -119,19 +122,27 @@ void erc721_plugin_call(int message, void *parameters) {
|
||||
switch (msg->screenIndex) {
|
||||
case 0:
|
||||
strlcpy(msg->title, "Contract Name", msg->titleLength);
|
||||
starkware_print_eth_address(tmpContent.txContent.destination, msg->msg);
|
||||
getEthDisplayableAddress(tmpContent.txContent.destination,
|
||||
msg->msg,
|
||||
msg->msgLength,
|
||||
&global_sha3,
|
||||
chainConfig);
|
||||
msg->result = ETH_PLUGIN_RESULT_OK;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
strlcpy(msg->title, "NFT Contract", msg->titleLength);
|
||||
starkware_print_eth_address(context->address, msg->msg);
|
||||
getEthDisplayableAddress(context->address,
|
||||
msg->msg,
|
||||
msg->msgLength,
|
||||
&global_sha3,
|
||||
chainConfig);
|
||||
msg->result = ETH_PLUGIN_RESULT_OK;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
strlcpy(msg->title, "TokenID", msg->titleLength);
|
||||
starkware_print_stark_key(context->tokenId, msg->msg);
|
||||
snprintf(msg->msg, 70, "0x%.*H", 32, context->tokenId);
|
||||
msg->result = ETH_PLUGIN_RESULT_OK;
|
||||
break;
|
||||
|
||||
|
||||
@@ -32,19 +32,6 @@ typedef struct eth2_deposit_parameters_t {
|
||||
char deposit_address[ETH2_DEPOSIT_PUBKEY_LENGTH];
|
||||
} eth2_deposit_parameters_t;
|
||||
|
||||
// Fills the `out` buffer with the lowercase string representation of the pubkey passed in as binary
|
||||
// format by `in`. Does not check the size, so expects `out` to be big enough to hold the string
|
||||
// representation. Returns the length of string (counting the null terminating character).
|
||||
static int getEthDisplayableAddress(char *out, uint8_t *in, cx_sha3_t *sha3) {
|
||||
out[0] = '0';
|
||||
out[1] = 'x';
|
||||
getEthAddressStringFromBinary(in, out + 2, sha3, chainConfig);
|
||||
|
||||
uint8_t destinationLen = strlen(out) + 1; // Adding one to account for \0.
|
||||
|
||||
return destinationLen;
|
||||
}
|
||||
|
||||
void eth2_plugin_call(int message, void *parameters) {
|
||||
switch (message) {
|
||||
case ETH_PLUGIN_INIT_CONTRACT: {
|
||||
@@ -130,9 +117,11 @@ void eth2_plugin_call(int message, void *parameters) {
|
||||
|
||||
// Use a temporary buffer to store the string representation.
|
||||
char tmp[ETH2_DEPOSIT_PUBKEY_LENGTH];
|
||||
getEthDisplayableAddress(tmp,
|
||||
(uint8_t *) context->deposit_address,
|
||||
msg->pluginSharedRW->sha3);
|
||||
getEthDisplayableAddress((uint8_t *) context->deposit_address,
|
||||
tmp,
|
||||
sizeof(tmp),
|
||||
msg->pluginSharedRW->sha3,
|
||||
chainConfig);
|
||||
|
||||
// Copy back the string to the global variable.
|
||||
strlcpy(context->deposit_address, tmp, ETH2_DEPOSIT_PUBKEY_LENGTH);
|
||||
|
||||
@@ -279,18 +279,6 @@ void starkware_print_stark_key(uint8_t *starkKey, char *destination) {
|
||||
snprintf(destination, 70, "0x%.*H", 32, starkKey);
|
||||
}
|
||||
|
||||
// TODO : rewrite as independant code
|
||||
void starkware_print_eth_address(uint8_t *address, char *destination, size_t destinationLength) {
|
||||
if (destinationLength < 43) {
|
||||
strlcpy(destination, "ERROR", destinationLength);
|
||||
return;
|
||||
}
|
||||
destination[0] = '0';
|
||||
destination[1] = 'x';
|
||||
getEthAddressStringFromBinary(address, destination + 2, &global_sha3, chainConfig);
|
||||
destination[42] = '\0';
|
||||
}
|
||||
|
||||
// TODO : rewrite as independant code
|
||||
void starkware_print_amount(uint8_t *amountData,
|
||||
char *destination,
|
||||
@@ -348,7 +336,11 @@ void starkware_print_asset_contract(char *destination, size_t destinationLength)
|
||||
if (dataContext.tokenContext.quantumIndex != MAX_TOKEN) {
|
||||
tokenDefinition_t *token =
|
||||
&tmpCtx.transactionContext.tokens[dataContext.tokenContext.quantumIndex];
|
||||
starkware_print_eth_address(token->address, destination, destinationLength);
|
||||
getEthDisplayableAddress(token->address,
|
||||
destination,
|
||||
destinationLength,
|
||||
&global_sha3,
|
||||
chainConfig);
|
||||
} else {
|
||||
strlcpy(destination, "UNKNOWN", destinationLength);
|
||||
}
|
||||
@@ -708,9 +700,11 @@ void starkware_plugin_call(int message, void *parameters) {
|
||||
if (is_deversify_contract(tmpContent.txContent.destination)) {
|
||||
strlcpy(msg->msg, "DeversiFi", msg->msgLength);
|
||||
} else {
|
||||
starkware_print_eth_address(tmpContent.txContent.destination,
|
||||
msg->msg,
|
||||
msg->msgLength);
|
||||
getEthDisplayableAddress(tmpContent.txContent.destination,
|
||||
msg->msg,
|
||||
msg->msgLength,
|
||||
&global_sha3,
|
||||
chainConfig);
|
||||
}
|
||||
msg->result = ETH_PLUGIN_RESULT_OK;
|
||||
break;
|
||||
@@ -720,7 +714,11 @@ void starkware_plugin_call(int message, void *parameters) {
|
||||
case STARKWARE_REGISTER_AND_DEPOSIT_TOKEN:
|
||||
case STARKWARE_REGISTER_AND_DEPOSIT_ETH:
|
||||
strlcpy(msg->title, "From ETH Address", msg->titleLength);
|
||||
starkware_print_eth_address(context->amount, msg->msg, msg->msgLength);
|
||||
getEthDisplayableAddress(context->amount,
|
||||
msg->msg,
|
||||
msg->msgLength,
|
||||
&global_sha3,
|
||||
chainConfig);
|
||||
break;
|
||||
case STARKWARE_ESCAPE:
|
||||
strlcpy(msg->title, "Amount", msg->titleLength);
|
||||
@@ -784,7 +782,11 @@ void starkware_plugin_call(int message, void *parameters) {
|
||||
case STARKWARE_WITHDRAW_TO:
|
||||
case STARKWARE_WITHDRAW_NFT_TO:
|
||||
strlcpy(msg->title, "To ETH Address", msg->titleLength);
|
||||
starkware_print_eth_address(context->amount, msg->msg, msg->msgLength);
|
||||
getEthDisplayableAddress(context->amount,
|
||||
msg->msg,
|
||||
msg->msgLength,
|
||||
&global_sha3,
|
||||
chainConfig);
|
||||
break;
|
||||
case STARKWARE_WITHDRAW_AND_MINT:
|
||||
strlcpy(msg->title, "Asset Contract", msg->titleLength);
|
||||
|
||||
Reference in New Issue
Block a user