Add pointer to msg_sender in Eth_plugin_finalize (#170)
* Add some PRINTF debug statements and fir additional screens init * Memzero struture and use two pointers less * Clang-format * Use ADDRESS_LENGTH where possible; Add printf statements when failing to compare contracts * clang-format * Remove 'token1' and 'token2' locals * Fix typo * apply clang-format * Add bip32path to sharedRO for plugins * Change getEthAddressStringFromKey to accept char instead of uint8_t * Update ethereum plugin sdk * Add BYPASS_SIGNATURES compilation option * Remove bip32path and pathLength from sharedRO; add msg_sender pointer to pluginFinalize.address * clang format eth_plugin_interface * Update submodule * Set address BEFORE making the finalize call * Update SDK Co-authored-by: TamtamHero <10632523+TamtamHero@users.noreply.github.com>
This commit is contained in:
@@ -21,12 +21,8 @@ void eth_plugin_prepare_finalize(ethPluginFinalize_t *finalize) {
|
||||
memset((uint8_t *) finalize, 0, sizeof(ethPluginFinalize_t));
|
||||
}
|
||||
|
||||
void eth_plugin_prepare_provide_token(ethPluginProvideToken_t *provideToken,
|
||||
tokenDefinition_t *token1,
|
||||
tokenDefinition_t *token2) {
|
||||
void eth_plugin_prepare_provide_token(ethPluginProvideToken_t *provideToken) {
|
||||
memset((uint8_t *) provideToken, 0, sizeof(ethPluginProvideToken_t));
|
||||
provideToken->token1 = token1;
|
||||
provideToken->token2 = token2;
|
||||
}
|
||||
|
||||
void eth_plugin_prepare_query_contract_ID(ethQueryContractID_t *queryContractID,
|
||||
@@ -67,11 +63,19 @@ eth_plugin_result_t eth_plugin_perform_init(uint8_t *contractAddress,
|
||||
if (memcmp(contractAddress,
|
||||
dataContext.tokenContext.contract_address,
|
||||
sizeof(dataContext.tokenContext.contract_address)) != 0) {
|
||||
PRINTF("Got contract: %.*H\n", ADDRESS_LENGTH, contractAddress);
|
||||
PRINTF("Expected contract: %.*H\n",
|
||||
ADDRESS_LENGTH,
|
||||
dataContext.tokenContext.contract_address);
|
||||
os_sched_exit(0);
|
||||
}
|
||||
if (memcmp(init->selector,
|
||||
dataContext.tokenContext.method_selector,
|
||||
sizeof(dataContext.tokenContext.method_selector)) != 0) {
|
||||
PRINTF("Got selector: %.*H\n", SELECTOR_SIZE, init->selector);
|
||||
PRINTF("Expected selector: %.*H\n",
|
||||
SELECTOR_SIZE,
|
||||
dataContext.tokenContext.method_selector);
|
||||
os_sched_exit(0);
|
||||
}
|
||||
PRINTF("External plugin will be used\n");
|
||||
@@ -145,6 +149,7 @@ eth_plugin_result_t eth_plugin_call(int method, void *parameter) {
|
||||
|
||||
switch (method) {
|
||||
case ETH_PLUGIN_INIT_CONTRACT:
|
||||
PRINTF("-- PLUGIN INIT CONTRACT --\n");
|
||||
((ethPluginInitContract_t *) parameter)->interfaceVersion =
|
||||
ETH_PLUGIN_INTERFACE_VERSION_1;
|
||||
((ethPluginInitContract_t *) parameter)->result = ETH_PLUGIN_RESULT_UNAVAILABLE;
|
||||
@@ -157,6 +162,7 @@ eth_plugin_result_t eth_plugin_call(int method, void *parameter) {
|
||||
((ethPluginInitContract_t *) parameter)->alias = dataContext.tokenContext.pluginName;
|
||||
break;
|
||||
case ETH_PLUGIN_PROVIDE_PARAMETER:
|
||||
PRINTF("-- PLUGIN PROVIDE PARAMETER --\n");
|
||||
((ethPluginProvideParameter_t *) parameter)->result = ETH_PLUGIN_RESULT_UNAVAILABLE;
|
||||
((ethPluginProvideParameter_t *) parameter)->pluginSharedRW = &pluginRW;
|
||||
((ethPluginProvideParameter_t *) parameter)->pluginSharedRO = &pluginRO;
|
||||
@@ -164,6 +170,7 @@ eth_plugin_result_t eth_plugin_call(int method, void *parameter) {
|
||||
(uint8_t *) &dataContext.tokenContext.pluginContext;
|
||||
break;
|
||||
case ETH_PLUGIN_FINALIZE:
|
||||
PRINTF("-- PLUGIN FINALIZE --\n");
|
||||
((ethPluginFinalize_t *) parameter)->result = ETH_PLUGIN_RESULT_UNAVAILABLE;
|
||||
((ethPluginFinalize_t *) parameter)->pluginSharedRW = &pluginRW;
|
||||
((ethPluginFinalize_t *) parameter)->pluginSharedRO = &pluginRO;
|
||||
@@ -171,6 +178,7 @@ eth_plugin_result_t eth_plugin_call(int method, void *parameter) {
|
||||
(uint8_t *) &dataContext.tokenContext.pluginContext;
|
||||
break;
|
||||
case ETH_PLUGIN_PROVIDE_TOKEN:
|
||||
PRINTF("-- PLUGIN PROVIDE TOKEN --\n");
|
||||
((ethPluginProvideToken_t *) parameter)->result = ETH_PLUGIN_RESULT_UNAVAILABLE;
|
||||
((ethPluginProvideToken_t *) parameter)->pluginSharedRW = &pluginRW;
|
||||
((ethPluginProvideToken_t *) parameter)->pluginSharedRO = &pluginRO;
|
||||
@@ -178,6 +186,7 @@ eth_plugin_result_t eth_plugin_call(int method, void *parameter) {
|
||||
(uint8_t *) &dataContext.tokenContext.pluginContext;
|
||||
break;
|
||||
case ETH_PLUGIN_QUERY_CONTRACT_ID:
|
||||
PRINTF("-- PLUGIN QUERY CONTRACT ID --\n");
|
||||
((ethQueryContractID_t *) parameter)->result = ETH_PLUGIN_RESULT_UNAVAILABLE;
|
||||
((ethQueryContractID_t *) parameter)->pluginSharedRW = &pluginRW;
|
||||
((ethQueryContractID_t *) parameter)->pluginSharedRO = &pluginRO;
|
||||
@@ -185,6 +194,7 @@ eth_plugin_result_t eth_plugin_call(int method, void *parameter) {
|
||||
(uint8_t *) &dataContext.tokenContext.pluginContext;
|
||||
break;
|
||||
case ETH_PLUGIN_QUERY_CONTRACT_UI:
|
||||
PRINTF("-- PLUGIN QUERY CONTRACT UI --\n");
|
||||
((ethQueryContractUI_t *) parameter)->pluginSharedRW = &pluginRW;
|
||||
((ethQueryContractUI_t *) parameter)->pluginSharedRO = &pluginRO;
|
||||
((ethQueryContractUI_t *) parameter)->pluginContext =
|
||||
@@ -230,7 +240,6 @@ eth_plugin_result_t eth_plugin_call(int method, void *parameter) {
|
||||
PRINTF("method: %d\n", method);
|
||||
switch (method) {
|
||||
case ETH_PLUGIN_INIT_CONTRACT:
|
||||
PRINTF("parameter result: %d\n", ((ethPluginInitContract_t *) parameter)->result);
|
||||
switch (((ethPluginInitContract_t *) parameter)->result) {
|
||||
case ETH_PLUGIN_RESULT_OK:
|
||||
break;
|
||||
@@ -263,6 +272,7 @@ eth_plugin_result_t eth_plugin_call(int method, void *parameter) {
|
||||
}
|
||||
break;
|
||||
case ETH_PLUGIN_PROVIDE_TOKEN:
|
||||
PRINTF("RESULT: %d\n", ((ethPluginProvideToken_t *) parameter)->result);
|
||||
switch (((ethPluginProvideToken_t *) parameter)->result) {
|
||||
case ETH_PLUGIN_RESULT_OK:
|
||||
case ETH_PLUGIN_RESULT_FALLBACK:
|
||||
@@ -279,7 +289,7 @@ eth_plugin_result_t eth_plugin_call(int method, void *parameter) {
|
||||
}
|
||||
break;
|
||||
case ETH_PLUGIN_QUERY_CONTRACT_UI:
|
||||
if (((ethQueryContractUI_t *) parameter)->result <= ETH_PLUGIN_RESULT_OK) {
|
||||
if (((ethQueryContractUI_t *) parameter)->result <= ETH_PLUGIN_RESULT_UNSUCCESSFUL) {
|
||||
return ETH_PLUGIN_RESULT_UNAVAILABLE;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -7,9 +7,7 @@ void eth_plugin_prepare_provide_parameter(ethPluginProvideParameter_t *providePa
|
||||
uint8_t *parameter,
|
||||
uint32_t parameterOffset);
|
||||
void eth_plugin_prepare_finalize(ethPluginFinalize_t *finalize);
|
||||
void eth_plugin_prepare_provide_token(ethPluginProvideToken_t *provideToken,
|
||||
tokenDefinition_t *token1,
|
||||
tokenDefinition_t *token2);
|
||||
void eth_plugin_prepare_provide_token(ethPluginProvideToken_t *provideToken);
|
||||
void eth_plugin_prepare_query_contract_ID(ethQueryContractID_t *queryContractID,
|
||||
char *name,
|
||||
uint32_t nameLength,
|
||||
|
||||
@@ -104,7 +104,8 @@ typedef struct ethPluginFinalize_t {
|
||||
uint8_t *tokenLookup2;
|
||||
|
||||
uint8_t *amount; // set an uint256 pointer if uiType is UI_AMOUNT_ADDRESS
|
||||
uint8_t *address; // set to a 20 bytes address pointer if uiType is UI_AMOUNT_ADDRESS
|
||||
uint8_t *address; // set to the destination address if uiType is UI_AMOUNT_ADDRESS. Set to the
|
||||
// user's address if uiType is UI_TYPE_GENERIC
|
||||
|
||||
uint8_t uiType;
|
||||
uint8_t numScreens; // ignored if uiType is UI_AMOUNT_ADDRESS
|
||||
|
||||
@@ -23,7 +23,9 @@ void plugin_ui_get_id() {
|
||||
strings.tmp.tmp2,
|
||||
sizeof(strings.tmp.tmp2));
|
||||
// Query the original contract for ID if it's not an internal alias
|
||||
if (!eth_plugin_call(ETH_PLUGIN_QUERY_CONTRACT_ID, (void *) &pluginQueryContractID)) {
|
||||
eth_plugin_result_t status =
|
||||
eth_plugin_call(ETH_PLUGIN_QUERY_CONTRACT_ID, (void *) &pluginQueryContractID);
|
||||
if (status != ETH_PLUGIN_RESULT_OK) {
|
||||
PRINTF("Plugin query contract ID call failed\n");
|
||||
io_seproxyhal_touch_tx_cancel(NULL);
|
||||
}
|
||||
@@ -37,8 +39,10 @@ void plugin_ui_get_item() {
|
||||
sizeof(strings.tmp.tmp),
|
||||
strings.tmp.tmp2,
|
||||
sizeof(strings.tmp.tmp2));
|
||||
if (!eth_plugin_call(ETH_PLUGIN_QUERY_CONTRACT_UI, (void *) &pluginQueryContractUI)) {
|
||||
PRINTF("Plugin query contract UI call failed\n");
|
||||
eth_plugin_result_t status =
|
||||
eth_plugin_call(ETH_PLUGIN_QUERY_CONTRACT_UI, (void *) &pluginQueryContractUI);
|
||||
if (status != ETH_PLUGIN_RESULT_OK) {
|
||||
PRINTF("Plugin query contract UI call failed, got: %d\n", status);
|
||||
io_seproxyhal_touch_tx_cancel(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,7 +394,7 @@ void handleGetWalletId(volatile unsigned int *tx) {
|
||||
THROW(0x9000);
|
||||
}
|
||||
|
||||
#endif // HAVE_WALLET_ID_SDK
|
||||
#endif // HAVE_WALLET_ID_SDK
|
||||
|
||||
void handleApdu(unsigned int *flags, unsigned int *tx) {
|
||||
unsigned short sw = 0;
|
||||
@@ -409,7 +409,7 @@ void handleApdu(unsigned int *flags, unsigned int *tx) {
|
||||
return;
|
||||
}
|
||||
|
||||
#endif // HAVE_WALLET_ID_SDK
|
||||
#endif // HAVE_WALLET_ID_SDK
|
||||
|
||||
#ifdef HAVE_STARKWARE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user