From ca9d5c9c779b9a94c619ea0a40fac94b1db83d79 Mon Sep 17 00:00:00 2001 From: Francois Beutin Date: Mon, 15 Jan 2024 19:08:19 +0100 Subject: [PATCH] Remove data needed by plugins from shared_context file --- src/caller_api.h | 34 ++++++++++++++++++++++++++++++++++ src/eth_plugin_interface.h | 1 - src/extra_info.h | 9 +++++++++ src/shared_context.h | 24 +++++------------------- src/swap_lib_calls.h | 1 + src/utils.h | 2 ++ src_nbgl/ui_approve_tx.c | 1 + src_nbgl/ui_idle.c | 1 + tools/build_sdk.py | 3 ++- 9 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 src/caller_api.h create mode 100644 src/extra_info.h diff --git a/src/caller_api.h b/src/caller_api.h new file mode 100644 index 0000000..7f769be --- /dev/null +++ b/src/caller_api.h @@ -0,0 +1,34 @@ +/******************************************************************************* + * Ledger Ethereum App + * (c) 2016-2019 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ + +#pragma once + +#ifdef HAVE_NBGL +#include "ux.h" +#endif + +typedef enum { CALLER_TYPE_CLONE, CALLER_TYPE_PLUGIN } e_caller_type; + +typedef struct caller_app_t { + const char *name; +#ifdef HAVE_NBGL + const nbgl_icon_details_t *icon; +#endif + char type; // does not have to be set by the caller app +} caller_app_t; + +extern caller_app_t *caller_app; diff --git a/src/eth_plugin_interface.h b/src/eth_plugin_interface.h index 7339128..6e7b435 100644 --- a/src/eth_plugin_interface.h +++ b/src/eth_plugin_interface.h @@ -6,7 +6,6 @@ #include "os.h" #include "cx.h" #include "tokens.h" -#include "shared_context.h" /************************************************************************************************* * Comments provided in this file are quick reminders on the usage of the plugin interface * diff --git a/src/extra_info.h b/src/extra_info.h new file mode 100644 index 0000000..1221ef3 --- /dev/null +++ b/src/extra_info.h @@ -0,0 +1,9 @@ +#pragma once + +#include "tokens.h" +#include "nft.h" + +typedef union extraInfo_t { + tokenDefinition_t token; + nftInfo_t nft; +} extraInfo_t; diff --git a/src/shared_context.h b/src/shared_context.h index 08e48d6..c3d6cf6 100644 --- a/src/shared_context.h +++ b/src/shared_context.h @@ -3,8 +3,13 @@ #include #include + +#include "os.h" +#include "cx.h" #include "ethUstream.h" #include "tokens.h" +#include "extra_info.h" +#include "tx_content.h" #include "chainConfig.h" #include "nft.h" #ifdef HAVE_NBGL @@ -13,8 +18,6 @@ #define MAX_BIP32_PATH 10 -#define WEI_TO_ETHER 18 - #define SELECTOR_LENGTH 4 #define PLUGIN_ID_LENGTH 30 @@ -95,11 +98,6 @@ typedef struct publicKeyContext_t { bool getChaincode; } publicKeyContext_t; -typedef union extraInfo_t { - tokenDefinition_t token; - nftInfo_t nft; -} extraInfo_t; - typedef struct transactionContext_t { bip32_path_t bip32; uint8_t hash[INT256_LENGTH]; @@ -226,16 +224,6 @@ typedef enum { extern pluginType_t pluginType; -typedef enum { CALLER_TYPE_CLONE, CALLER_TYPE_PLUGIN } e_caller_type; - -typedef struct caller_app_t { - const char *name; -#ifdef HAVE_NBGL - const nbgl_icon_details_t *icon; -#endif - char type; // does not have to be set by the caller app -} caller_app_t; - extern uint8_t appState; #ifdef HAVE_STARKWARE extern bool quantumSet; @@ -244,8 +232,6 @@ extern bool quantumSet; extern uint32_t eth2WithdrawalIndex; #endif -extern caller_app_t *caller_app; - void reset_app_context(void); const uint8_t *parseBip32(const uint8_t *dataBuffer, uint8_t *dataLength, bip32_path_t *bip32); diff --git a/src/swap_lib_calls.h b/src/swap_lib_calls.h index 2870347..c4675e3 100644 --- a/src/swap_lib_calls.h +++ b/src/swap_lib_calls.h @@ -10,6 +10,7 @@ #include "chainConfig.h" #include "shared_context.h" #include "stdint.h" +#include "caller_api.h" #define RUN_APPLICATION 1 diff --git a/src/utils.h b/src/utils.h index d66c4a0..c70cf5a 100644 --- a/src/utils.h +++ b/src/utils.h @@ -24,6 +24,8 @@ #include "cx.h" #include "uint256.h" +#define WEI_TO_ETHER 18 + #define ADDRESS_LENGTH 20 #define INT128_LENGTH 16 #define INT256_LENGTH 32 diff --git a/src_nbgl/ui_approve_tx.c b/src_nbgl/ui_approve_tx.c index 6d04570..7e2f59d 100644 --- a/src_nbgl/ui_approve_tx.c +++ b/src_nbgl/ui_approve_tx.c @@ -6,6 +6,7 @@ #include "ui_signing.h" #include "plugins.h" #include "domain_name.h" +#include "caller_api.h" #include "network_icons.h" #include "network.h" diff --git a/src_nbgl/ui_idle.c b/src_nbgl/ui_idle.c index faa47ca..56f559e 100644 --- a/src_nbgl/ui_idle.c +++ b/src_nbgl/ui_idle.c @@ -3,6 +3,7 @@ #include "ui_nbgl.h" #include "nbgl_use_case.h" #include "glyphs.h" +#include "caller_api.h" #include "network.h" char g_stax_shared_buffer[SHARED_BUFFER_SIZE] = {0}; diff --git a/tools/build_sdk.py b/tools/build_sdk.py index 3b5c68b..c3ad100 100755 --- a/tools/build_sdk.py +++ b/tools/build_sdk.py @@ -157,9 +157,10 @@ if __name__ == "__main__": "src/tokens.h", "src/utils.h", "src/tx_content.h", - "src/shared_context.h", "src/eth_plugin_internal.h", "src/nft.h", + "src/extra_info.h", + "src/caller_api.h", ] nodes_to_extract = { "#define": ["MAX_TICKER_LEN",