Skip to content

Commit 4d6feea

Browse files
Merge pull request #520 from LedgerHQ/fbe/redo_file_architecture_clean
Fbe/redo file architecture clean
2 parents df6a781 + bc76a31 commit 4d6feea

File tree

99 files changed

+1124
-1023
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1124
-1023
lines changed

.github/workflows/sdk-generation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
persist-credentials: false
2727

2828
- name: Build new SDK
29-
run: python tools/build_sdk.py
29+
run: ./tools/build_sdk.sh
3030

3131
- name: Extract branch name
3232
shell: bash

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ ifeq ($(CHAIN),ethereum)
277277
endif
278278

279279
# rebuild SDK
280-
$(shell python3 tools/build_sdk.py)
280+
$(shell ./tools/build_sdk.sh)
281281

282282
# check if a difference is noticed (fail if it happens in CI build)
283283
ifneq ($(shell git status | grep 'ethereum-plugin-sdk'),)

src_common/ethUstream.c renamed to src/ethUstream.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include <string.h>
2020

2121
#include "ethUstream.h"
22-
#include "ethUtils.h"
23-
#include "utils.h"
22+
#include "rlp_utils.h"
23+
#include "common_utils.h"
2424

2525
#define MAX_INT256 32
2626
#define MAX_ADDRESS 20

src_common/ethUstream.h renamed to src/ethUstream.h

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@
1515
* limitations under the License.
1616
********************************************************************************/
1717

18-
#ifndef _ETHUSTREAM_H_
19-
#define _ETHUSTREAM_H_
18+
#pragma once
2019

2120
#include <stdbool.h>
2221
#include <stdint.h>
2322

2423
#include "os.h"
2524
#include "cx.h"
25+
#include "common_utils.h"
26+
#include "tx_content.h"
2627

2728
struct txContext_t;
2829

@@ -35,10 +36,7 @@ typedef enum customStatus_e {
3536

3637
typedef customStatus_e (*ustreamProcess_t)(struct txContext_t *context);
3738

38-
#define TX_FLAG_TYPE 0x01
39-
#define ADDRESS_LENGTH 20
40-
#define INT128_LENGTH 16
41-
#define INT256_LENGTH 32
39+
#define TX_FLAG_TYPE 0x01
4240

4341
// First variant of every Tx enum.
4442
#define RLP_NONE 0
@@ -114,24 +112,6 @@ typedef enum parserStatus_e {
114112
USTREAM_CONTINUE // Used internally to signify we can keep on parsing
115113
} parserStatus_e;
116114

117-
typedef struct txInt256_t {
118-
uint8_t value[INT256_LENGTH];
119-
uint8_t length;
120-
} txInt256_t;
121-
122-
typedef struct txContent_t {
123-
txInt256_t gasprice; // Used as MaxFeePerGas when dealing with EIP1559 transactions.
124-
txInt256_t startgas; // Also known as `gasLimit`.
125-
txInt256_t value;
126-
txInt256_t nonce;
127-
txInt256_t chainID;
128-
uint8_t destination[ADDRESS_LENGTH];
129-
uint8_t destinationLength;
130-
uint8_t v[8];
131-
uint8_t vLength;
132-
bool dataPresent;
133-
} txContent_t;
134-
135115
typedef struct txContext_t {
136116
uint8_t currentField;
137117
cx_sha3_t *sha3;
@@ -164,5 +144,3 @@ parserStatus_e processTx(txContext_t *context,
164144
parserStatus_e continueTx(txContext_t *context);
165145
void copyTxData(txContext_t *context, uint8_t *out, uint32_t length);
166146
uint8_t readTxByte(txContext_t *context);
167-
168-
#endif // _ETHUSTREAM_H_

src/eth_plugin_handler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include <string.h>
22
#include "eth_plugin_handler.h"
33
#include "eth_plugin_internal.h"
4+
#include "plugin_utils.h"
45
#include "shared_context.h"
56
#include "network.h"
6-
#include "ethUtils.h"
77

88
void eth_plugin_prepare_init(ethPluginInitContract_t *init,
99
const uint8_t *selector,

src/eth_plugin_handler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#define NO_EXTRA_INFO(ctx, idx) \
77
(allzeroes(&(ctx.transactionContext.extraInfo[idx]), sizeof(extraInfo_t)))
88

9+
#define NO_NFT_METADATA (NO_EXTRA_INFO(tmpCtx, 1))
10+
911
void eth_plugin_prepare_init(ethPluginInitContract_t *init,
1012
const uint8_t *selector,
1113
uint32_t dataSize);

src/eth_plugin_internal.c

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,11 @@
11
#include <string.h>
22
#include "eth_plugin_internal.h"
3-
#include "ethUtils.h" // allzeroes
3+
#include "plugin_utils.h"
44

55
bool erc20_plugin_available_check(void);
66

77
void erc20_plugin_call(int message, void* parameters);
88

9-
void copy_address(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size) {
10-
uint8_t copy_size = MIN(dst_size, ADDRESS_LENGTH);
11-
memmove(dst, parameter + PARAMETER_LENGTH - copy_size, copy_size);
12-
}
13-
14-
void copy_parameter(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size) {
15-
uint8_t copy_size = MIN(dst_size, PARAMETER_LENGTH);
16-
memmove(dst, parameter, copy_size);
17-
}
18-
19-
bool U2BE_from_parameter(const uint8_t* parameter, uint16_t* value) {
20-
if (allzeroes(parameter, PARAMETER_LENGTH - sizeof(uint16_t))) {
21-
*value = U2BE(parameter, PARAMETER_LENGTH - sizeof(uint16_t));
22-
return true;
23-
}
24-
25-
return false;
26-
}
27-
28-
bool U4BE_from_parameter(const uint8_t* parameter, uint32_t* value) {
29-
if (allzeroes(parameter, PARAMETER_LENGTH - sizeof(uint32_t))) {
30-
*value = U4BE(parameter, PARAMETER_LENGTH - sizeof(uint32_t));
31-
return true;
32-
}
33-
34-
return false;
35-
}
36-
379
#ifdef HAVE_STARKWARE
3810
void starkware_plugin_call(int message, void* parameters);
3911
#endif

src/eth_plugin_internal.h

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
1-
#ifndef _ETH_PLUGIN_INTERNAL_H_
2-
#define _ETH_PLUGIN_INTERNAL_H_
1+
#pragma once
32

43
#include <stdint.h>
54
#include <stdbool.h>
5+
#include "shared_context.h"
66
#include "eth_plugin_interface.h"
77

8-
#define SELECTOR_SIZE 4
9-
#define PARAMETER_LENGTH 32
10-
11-
void copy_address(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size);
12-
13-
void copy_parameter(uint8_t* dst, const uint8_t* parameter, uint8_t dst_size);
14-
158
void erc721_plugin_call(int message, void* parameters);
169
void erc1155_plugin_call(int message, void* parameters);
1710

18-
// Get the value from the beginning of the parameter (right to left) and check if the rest of it is
19-
// zero
20-
bool U2BE_from_parameter(const uint8_t* parameter, uint16_t* value);
21-
bool U4BE_from_parameter(const uint8_t* parameter, uint32_t* value);
22-
2311
typedef bool (*PluginAvailableCheck)(void);
2412
typedef void (*PluginCall)(int, void*);
2513

@@ -49,5 +37,3 @@ extern const uint8_t* const STARKWARE_SELECTORS[NUM_STARKWARE_SELECTORS];
4937
#endif
5038

5139
extern internalEthPlugin_t const INTERNAL_ETH_PLUGINS[];
52-
53-
#endif // _ETH_PLUGIN_INTERNAL_H_

src/tokens.c renamed to src/extra_tokens.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#ifdef HAVE_TOKENS_EXTRA_LIST
1919

20-
#include "tokens.h"
20+
#include "extra_tokens.h"
2121

2222
const tokenDefinition_t TOKENS_EXTRA[NUM_TOKENS_EXTRA] = {
2323

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/*****************************************************************************
2-
* Ledger Plugin SDK
3-
* (c) 2023 Ledger SAS
1+
/*******************************************************************************
2+
* Ledger Ethereum App
3+
* (c) 2016-2019 Ledger
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -13,16 +13,14 @@
1313
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
16-
*****************************************************************************/
16+
********************************************************************************/
1717

18-
#include "plugin_utils.h"
18+
#pragma once
1919

20-
bool find_selector(uint32_t selector, const uint32_t *array, size_t size, size_t *idx) {
21-
for (size_t i = 0; i < size; ++i) {
22-
if (selector == array[i]) {
23-
if (idx != NULL) *idx = i;
24-
return true;
25-
}
26-
}
27-
return false;
28-
}
20+
#ifdef HAVE_TOKENS_EXTRA_LIST
21+
22+
#define NUM_TOKENS_EXTRA 8
23+
24+
extern tokenDefinition_t const TOKENS_EXTRA[NUM_TOKENS_EXTRA];
25+
26+
#endif

0 commit comments

Comments
 (0)