Skip to content

Commit 056cada

Browse files
committed
refurbish type defs
1 parent 53ef818 commit 056cada

10 files changed

Lines changed: 214 additions & 151 deletions

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ target_include_directories(app_lib PUBLIC
150150
${CMAKE_CURRENT_SOURCE_DIR}/app/src
151151
${CMAKE_CURRENT_SOURCE_DIR}/app/src/lib
152152
${CMAKE_CURRENT_SOURCE_DIR}/app/src/common
153+
${CMAKE_CURRENT_SOURCE_DIR}/app/src/txdefs
153154
${CMAKE_CURRENT_SOURCE_DIR}/deps/picohash
154155
)
155156

app/src/parser_impl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
parser_error_t _read(parser_context_t *c, parser_tx_t *v) {
2424
UNUSED(c);
2525

26-
//CHECK_ERROR(metadata_read(c, v));
26+
// CHECK_ERROR(metadata_read(c, v));
2727
CHECK_ERROR(unsigned_transaction_read(c, v));
2828

2929
return parser_ok;

app/src/txdefs/bank_txdef.h

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*******************************************************************************
2+
* (c) 2018 - 2023 Zondax AG
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
********************************************************************************/
16+
#pragma once
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
22+
#include <stdbool.h>
23+
#include <stddef.h>
24+
#include <stdint.h>
25+
26+
#include "metadata_txdef.h"
27+
28+
typedef enum {
29+
BANK_CALL_MESSAGE_CREATE_TOKEN,
30+
BANK_CALL_MESSAGE_TRANSFER,
31+
BANK_CALL_MESSAGE_BURN,
32+
BANK_CALL_MESSAGE_MINT,
33+
BANK_CALL_MESSAGE_FREEZE,
34+
} bank_call_message_type_t;
35+
36+
typedef struct {
37+
address_t to;
38+
coins_t coins;
39+
} bank_transfer_t;
40+
41+
typedef struct {
42+
coins_t coins;
43+
} bank_burn_t;
44+
45+
typedef struct {
46+
coins_t coins;
47+
address_t mint_to_address;
48+
} bank_mint_t;
49+
50+
typedef struct {
51+
token_id_t token_id;
52+
} bank_freeze_t;
53+
54+
typedef struct {
55+
bank_call_message_type_t type;
56+
union {
57+
bank_transfer_t transfer;
58+
bank_burn_t burn;
59+
bank_mint_t mint;
60+
bank_freeze_t freeze;
61+
};
62+
} bank_call_message_t;
63+
64+
#ifdef __cplusplus
65+
}
66+
#endif
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,47 @@ extern "C" {
2323
#include <stddef.h>
2424
#include <stdint.h>
2525

26+
#define GAS_DIMENSIONS 2
27+
#define TOKEN_ID_SIZE 32
28+
#define ADDRESS_SIZE 28
29+
#define DEFAULT_SAFE_VEC_LEN 20
30+
2631
typedef struct {
2732
const uint8_t *ptr;
2833
uint16_t len;
2934
} bytes_t;
3035

36+
typedef struct {
37+
uint64_t hi;
38+
uint64_t lo;
39+
} amount_t;
40+
41+
typedef struct {
42+
bytes_t token;
43+
} token_id_t;
44+
45+
typedef struct {
46+
amount_t amount;
47+
token_id_t token_id;
48+
} coins_t;
49+
50+
typedef struct {
51+
uint64_t gas[GAS_DIMENSIONS];
52+
} gas_t;
53+
54+
typedef struct {
55+
amount_t gas[GAS_DIMENSIONS];
56+
} gas_u128_t;
57+
58+
typedef struct {
59+
bytes_t address;
60+
} address_t;
61+
62+
typedef struct {
63+
uint32_t length;
64+
address_t address[DEFAULT_SAFE_VEC_LEN];
65+
} address_list_t;
66+
3167
#ifdef __cplusplus
3268
}
3369
#endif
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extern "C" {
2323
#include <stddef.h>
2424
#include <stdint.h>
2525

26-
#include "parser_txdef_common.h"
26+
#include "common_txdef.h"
2727

2828
#define MAX_FIELDS_QTY 20
2929
#define MAX_VARIANTS_QTY 20

app/src/txdefs/parser_txdef.h

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*******************************************************************************
2+
* (c) 2018 - 2023 Zondax AG
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
********************************************************************************/
16+
#pragma once
17+
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
22+
#include <stdbool.h>
23+
#include <stddef.h>
24+
#include <stdint.h>
25+
26+
#include "bank_txdef.h"
27+
#include "common_txdef.h"
28+
#include "metadata_txdef.h"
29+
#include "paymaster_txdef.h"
30+
31+
typedef enum {
32+
RUNTIME_BANK,
33+
RUNTIME_SEQUENCER_REGISTRY,
34+
RUNTIME_VALUE_SETTER,
35+
RUNTIME_ATTESTER_INCENTIVES,
36+
RUNTIME_PROVER_INCENTIVES,
37+
RUNTIME_ACCOUNTS,
38+
RUNTIME_UNIQUENESS,
39+
RUNTIME_CHAIN_STATE,
40+
RUNTIME_BLOB_STORAGE,
41+
RUNTIME_PAYMASTER,
42+
RUNTIME_EVM,
43+
RUNTIME_ACCESS_PATTERN,
44+
} runtime_type_t;
45+
46+
typedef struct {
47+
runtime_type_t type;
48+
union {
49+
bank_call_message_t bank;
50+
paymaster_call_message_t paymaster;
51+
};
52+
} runtime_t;
53+
54+
typedef struct {
55+
uint64_t max_priority_fee_bips;
56+
amount_t max_fee;
57+
bool has_gas_limit;
58+
gas_t gas_limit;
59+
uint64_t chain_id;
60+
} tx_details_t;
61+
62+
typedef struct {
63+
runtime_t runtime_call;
64+
uint64_t generation;
65+
tx_details_t tx_details;
66+
} unsigned_transaction_t;
67+
68+
typedef struct {
69+
schema_t schema;
70+
unsigned_transaction_t unsigned_transaction;
71+
} parser_tx_t;
72+
73+
#ifdef __cplusplus
74+
}
75+
#endif
Lines changed: 3 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,7 @@ extern "C" {
2323
#include <stddef.h>
2424
#include <stdint.h>
2525

26-
#include "parser_txdef_metadata.h"
27-
28-
#define GAS_DIMENSIONS 2
29-
#define TOKEN_ID_SIZE 32
30-
#define ADDRESS_SIZE 28
31-
#define MAX_AUTHORIZED_UPDATERS 10
32-
#define DEFAULT_SAFE_VEC_LEN 20
33-
34-
typedef enum {
35-
RUNTIME_BANK,
36-
RUNTIME_SEQUENCER_REGISTRY,
37-
RUNTIME_VALUE_SETTER,
38-
RUNTIME_ATTESTER_INCENTIVES,
39-
RUNTIME_PROVER_INCENTIVES,
40-
RUNTIME_ACCOUNTS,
41-
RUNTIME_UNIQUENESS,
42-
RUNTIME_CHAIN_STATE,
43-
RUNTIME_BLOB_STORAGE,
44-
RUNTIME_PAYMASTER,
45-
RUNTIME_EVM,
46-
RUNTIME_ACCESS_PATTERN,
47-
} runtime_type_t;
48-
49-
typedef enum {
50-
BANK_CALL_MESSAGE_CREATE_TOKEN,
51-
BANK_CALL_MESSAGE_TRANSFER,
52-
BANK_CALL_MESSAGE_BURN,
53-
BANK_CALL_MESSAGE_MINT,
54-
BANK_CALL_MESSAGE_FREEZE,
55-
} bank_call_message_type_t;
26+
#include "metadata_txdef.h"
5627

5728
typedef enum {
5829
PAYMASTER_CALL_REGISTER_PAYMASTER,
@@ -70,61 +41,6 @@ typedef enum {
7041
AUTHORIZED_SEQUENCERS_SOME,
7142
} authorized_sequencers_type_t;
7243

73-
typedef struct {
74-
uint64_t hi;
75-
uint64_t lo;
76-
} amount_t;
77-
78-
typedef struct {
79-
bytes_t token;
80-
} token_id_t;
81-
82-
typedef struct {
83-
amount_t amount;
84-
token_id_t token_id;
85-
} coins_t;
86-
87-
typedef struct {
88-
bytes_t address;
89-
} address_t;
90-
91-
typedef struct {
92-
uint64_t gas[GAS_DIMENSIONS];
93-
} gas_t;
94-
95-
typedef struct {
96-
amount_t gas[GAS_DIMENSIONS];
97-
} gas_u128_t;
98-
99-
// CallMessage structs
100-
typedef struct {
101-
address_t to;
102-
coins_t coins;
103-
} transfer_t;
104-
105-
typedef struct {
106-
coins_t coins;
107-
} burn_t;
108-
109-
typedef struct {
110-
coins_t coins;
111-
address_t mint_to_address;
112-
} mint_t;
113-
114-
typedef struct {
115-
token_id_t token_id;
116-
} freeze_t;
117-
118-
typedef struct {
119-
bank_call_message_type_t type;
120-
union {
121-
transfer_t transfer;
122-
burn_t burn;
123-
mint_t mint;
124-
freeze_t freeze;
125-
};
126-
} bank_call_message_t;
127-
12844
typedef struct {
12945
bool has_max_fee;
13046
amount_t max_fee;
@@ -151,11 +67,6 @@ typedef struct {
15167
} pairs[DEFAULT_SAFE_VEC_LEN];
15268
} payee_policy_list_t;
15369

154-
typedef struct {
155-
uint32_t length;
156-
address_t address[DEFAULT_SAFE_VEC_LEN];
157-
} address_list_t;
158-
15970
typedef struct {
16071
authorized_sequencers_type_t type;
16172
union {
@@ -180,7 +91,8 @@ typedef struct {
18091

18192
typedef struct {
18293
address_t payer;
183-
//policy_update_t update;
94+
// TODO: implement this
95+
// policy_update_t update;
18496
} paymaster_call_update_policy_t;
18597

18698
typedef struct {
@@ -192,33 +104,6 @@ typedef struct {
192104
};
193105
} paymaster_call_message_t;
194106

195-
// Runtime structs
196-
typedef struct {
197-
runtime_type_t type;
198-
union {
199-
bank_call_message_t bank;
200-
paymaster_call_message_t paymaster;
201-
};
202-
} runtime_t;
203-
typedef struct {
204-
uint64_t max_priority_fee_bips;
205-
amount_t max_fee;
206-
bool has_gas_limit;
207-
gas_t gas_limit;
208-
uint64_t chain_id;
209-
} tx_details_t;
210-
211-
typedef struct {
212-
runtime_t runtime_call;
213-
uint64_t generation;
214-
tx_details_t tx_details;
215-
} unsigned_transaction_t;
216-
217-
typedef struct {
218-
schema_t schema;
219-
unsigned_transaction_t unsigned_transaction;
220-
} parser_tx_t;
221-
222107
#ifdef __cplusplus
223108
}
224109
#endif

0 commit comments

Comments
 (0)