From 4d04d5113d3264ab101bf34d34322fd6a5185c0a Mon Sep 17 00:00:00 2001 From: Francois Beutin Date: Mon, 15 Jan 2024 17:35:53 +0100 Subject: [PATCH] Extract data needed by plugin from ethUstream.h --- src/ethUstream.h | 30 ++++---------------------- src/eth_plugin_interface.h | 1 - src/tx_content.h | 43 ++++++++++++++++++++++++++++++++++++++ src/utils.c | 1 - src/utils.h | 4 ++++ tools/build_sdk.py | 2 +- 6 files changed, 52 insertions(+), 29 deletions(-) create mode 100644 src/tx_content.h diff --git a/src/ethUstream.h b/src/ethUstream.h index ed5aea3..73cfa40 100644 --- a/src/ethUstream.h +++ b/src/ethUstream.h @@ -15,14 +15,15 @@ * limitations under the License. ********************************************************************************/ -#ifndef _ETHUSTREAM_H_ -#define _ETHUSTREAM_H_ +#pragma once #include #include #include "os.h" #include "cx.h" +#include "utils.h" +#include "tx_content.h" struct txContext_t; @@ -35,10 +36,7 @@ typedef enum customStatus_e { typedef customStatus_e (*ustreamProcess_t)(struct txContext_t *context); -#define TX_FLAG_TYPE 0x01 -#define ADDRESS_LENGTH 20 -#define INT128_LENGTH 16 -#define INT256_LENGTH 32 +#define TX_FLAG_TYPE 0x01 // First variant of every Tx enum. #define RLP_NONE 0 @@ -114,24 +112,6 @@ typedef enum parserStatus_e { USTREAM_CONTINUE // Used internally to signify we can keep on parsing } parserStatus_e; -typedef struct txInt256_t { - uint8_t value[INT256_LENGTH]; - uint8_t length; -} txInt256_t; - -typedef struct txContent_t { - txInt256_t gasprice; // Used as MaxFeePerGas when dealing with EIP1559 transactions. - txInt256_t startgas; // Also known as `gasLimit`. - txInt256_t value; - txInt256_t nonce; - txInt256_t chainID; - uint8_t destination[ADDRESS_LENGTH]; - uint8_t destinationLength; - uint8_t v[8]; - uint8_t vLength; - bool dataPresent; -} txContent_t; - typedef struct txContext_t { uint8_t currentField; cx_sha3_t *sha3; @@ -164,5 +144,3 @@ parserStatus_e processTx(txContext_t *context, parserStatus_e continueTx(txContext_t *context); void copyTxData(txContext_t *context, uint8_t *out, uint32_t length); uint8_t readTxByte(txContext_t *context); - -#endif // _ETHUSTREAM_H_ diff --git a/src/eth_plugin_interface.h b/src/eth_plugin_interface.h index fc8f239..7339128 100644 --- a/src/eth_plugin_interface.h +++ b/src/eth_plugin_interface.h @@ -5,7 +5,6 @@ #include "os.h" #include "cx.h" -#include "ethUstream.h" #include "tokens.h" #include "shared_context.h" diff --git a/src/tx_content.h b/src/tx_content.h new file mode 100644 index 0000000..613700e --- /dev/null +++ b/src/tx_content.h @@ -0,0 +1,43 @@ +/******************************************************************************* + * 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 + +#include +#include + +#include "os.h" +#include "cx.h" +#include "utils.h" + +typedef struct txInt256_t { + uint8_t value[INT256_LENGTH]; + uint8_t length; +} txInt256_t; + +typedef struct txContent_t { + txInt256_t gasprice; // Used as MaxFeePerGas when dealing with EIP1559 transactions. + txInt256_t startgas; // Also known as `gasLimit`. + txInt256_t value; + txInt256_t nonce; + txInt256_t chainID; + uint8_t destination[ADDRESS_LENGTH]; + uint8_t destinationLength; + uint8_t v[8]; + uint8_t vLength; + bool dataPresent; +} txContent_t; diff --git a/src/utils.c b/src/utils.c index 3db24b5..c88d3c2 100644 --- a/src/utils.c +++ b/src/utils.c @@ -18,7 +18,6 @@ #include #include -#include "ethUstream.h" #include "ethUtils.h" #include "uint128.h" #include "uint256.h" diff --git a/src/utils.h b/src/utils.h index 472ea51..caf5246 100644 --- a/src/utils.h +++ b/src/utils.h @@ -22,6 +22,10 @@ #include "uint256.h" +#define ADDRESS_LENGTH 20 +#define INT128_LENGTH 16 +#define INT256_LENGTH 32 + #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) void array_hexstr(char* strbuf, const void* bin, unsigned int len); diff --git a/tools/build_sdk.py b/tools/build_sdk.py index 12f71e1..f61535e 100755 --- a/tools/build_sdk.py +++ b/tools/build_sdk.py @@ -156,7 +156,7 @@ if __name__ == "__main__": headers_to_merge = [ "src/tokens.h", "src/utils.h", - "src/ethUstream.h", + "src/tx_content.h", "src/ethUtils.h", "src/shared_context.h", "src/eth_plugin_internal.h",