@@ -9,18 +9,23 @@ use ledger_secure_sdk_sys::{
9
9
const DPATH_STAGE_SIZE : usize = 16 ;
10
10
const ADDRESS_BUF_SIZE : usize = 64 ;
11
11
const AMOUNT_BUF_SIZE : usize = 16 ;
12
+ const DEFAULT_COIN_CONFIG_BUF_SIZE : usize = 16 ;
12
13
13
- pub struct CheckAddressParams {
14
+ pub struct CheckAddressParams < const COIN_CONFIG_BUF_SIZE : usize = DEFAULT_COIN_CONFIG_BUF_SIZE > {
15
+ pub coin_config : [ u8 ; COIN_CONFIG_BUF_SIZE ] ,
16
+ pub coin_config_len : usize ,
14
17
pub dpath : [ u8 ; DPATH_STAGE_SIZE * 4 ] ,
15
18
pub dpath_len : usize ,
16
19
pub ref_address : [ u8 ; ADDRESS_BUF_SIZE ] ,
17
20
pub ref_address_len : usize ,
18
21
pub result : * mut i32 ,
19
22
}
20
23
21
- impl Default for CheckAddressParams {
24
+ impl < const COIN_CONFIG_BUF_SIZE : usize > Default for CheckAddressParams < COIN_CONFIG_BUF_SIZE > {
22
25
fn default ( ) -> Self {
23
26
CheckAddressParams {
27
+ coin_config : [ 0 ; COIN_CONFIG_BUF_SIZE ] ,
28
+ coin_config_len : 0 ,
24
29
dpath : [ 0 ; DPATH_STAGE_SIZE * 4 ] ,
25
30
dpath_len : 0 ,
26
31
ref_address : [ 0 ; ADDRESS_BUF_SIZE ] ,
@@ -30,16 +35,20 @@ impl Default for CheckAddressParams {
30
35
}
31
36
}
32
37
33
- pub struct PrintableAmountParams {
38
+ pub struct PrintableAmountParams < const COIN_CONFIG_BUF_SIZE : usize = DEFAULT_COIN_CONFIG_BUF_SIZE > {
39
+ pub coin_config : [ u8 ; COIN_CONFIG_BUF_SIZE ] ,
40
+ pub coin_config_len : usize ,
34
41
pub amount : [ u8 ; AMOUNT_BUF_SIZE ] ,
35
42
pub amount_len : usize ,
36
43
pub amount_str : * mut i8 ,
37
44
pub is_fee : bool ,
38
45
}
39
46
40
- impl Default for PrintableAmountParams {
47
+ impl < const COIN_CONFIG_BUF_SIZE : usize > Default for PrintableAmountParams < COIN_CONFIG_BUF_SIZE > {
41
48
fn default ( ) -> Self {
42
49
PrintableAmountParams {
50
+ coin_config : [ 0 ; COIN_CONFIG_BUF_SIZE ] ,
51
+ coin_config_len : 0 ,
43
52
amount : [ 0 ; AMOUNT_BUF_SIZE ] ,
44
53
amount_len : 0 ,
45
54
amount_str : core:: ptr:: null_mut ( ) ,
@@ -48,7 +57,9 @@ impl Default for PrintableAmountParams {
48
57
}
49
58
}
50
59
51
- pub struct CreateTxParams {
60
+ pub struct CreateTxParams < const COIN_CONFIG_BUF_SIZE : usize = DEFAULT_COIN_CONFIG_BUF_SIZE > {
61
+ pub coin_config : [ u8 ; COIN_CONFIG_BUF_SIZE ] ,
62
+ pub coin_config_len : usize ,
52
63
pub amount : [ u8 ; AMOUNT_BUF_SIZE ] ,
53
64
pub amount_len : usize ,
54
65
pub fee_amount : [ u8 ; AMOUNT_BUF_SIZE ] ,
@@ -58,9 +69,11 @@ pub struct CreateTxParams {
58
69
pub result : * mut u8 ,
59
70
}
60
71
61
- impl Default for CreateTxParams {
72
+ impl < const COIN_CONFIG_BUF_SIZE : usize > Default for CreateTxParams < COIN_CONFIG_BUF_SIZE > {
62
73
fn default ( ) -> Self {
63
74
CreateTxParams {
75
+ coin_config : [ 0 ; COIN_CONFIG_BUF_SIZE ] ,
76
+ coin_config_len : 0 ,
64
77
amount : [ 0 ; AMOUNT_BUF_SIZE ] ,
65
78
amount_len : 0 ,
66
79
fee_amount : [ 0 ; AMOUNT_BUF_SIZE ] ,
@@ -72,7 +85,9 @@ impl Default for CreateTxParams {
72
85
}
73
86
}
74
87
75
- pub fn get_check_address_params ( arg0 : u32 ) -> CheckAddressParams {
88
+ pub fn get_check_address_params < const COIN_CONFIG_BUF_SIZE : usize > (
89
+ arg0 : u32 ,
90
+ ) -> CheckAddressParams < COIN_CONFIG_BUF_SIZE > {
76
91
debug_print ( "=> get_check_address_params\n " ) ;
77
92
78
93
let mut libarg: libargs_t = libargs_t:: default ( ) ;
@@ -88,7 +103,18 @@ pub fn get_check_address_params(arg0: u32) -> CheckAddressParams {
88
103
let params: check_address_parameters_t =
89
104
unsafe { * ( libarg. __bindgen_anon_1 . check_address as * const check_address_parameters_t ) } ;
90
105
91
- let mut check_address_params: CheckAddressParams = Default :: default ( ) ;
106
+ let mut check_address_params: CheckAddressParams < COIN_CONFIG_BUF_SIZE > = Default :: default ( ) ;
107
+
108
+ debug_print ( "==> GET_COIN_CONFIG_LENGTH\n " ) ;
109
+ check_address_params. coin_config_len = params. coin_configuration_length as usize ;
110
+
111
+ debug_print ( "==> GET_COIN_CONFIG \n " ) ;
112
+ unsafe {
113
+ params. coin_configuration . copy_to_nonoverlapping (
114
+ check_address_params. coin_config . as_mut_ptr ( ) ,
115
+ check_address_params. coin_config_len ,
116
+ ) ;
117
+ }
92
118
93
119
debug_print ( "==> GET_DPATH_LENGTH\n " ) ;
94
120
check_address_params. dpath_len =
@@ -117,7 +143,9 @@ pub fn get_check_address_params(arg0: u32) -> CheckAddressParams {
117
143
check_address_params
118
144
}
119
145
120
- pub fn get_printable_amount_params ( arg0 : u32 ) -> PrintableAmountParams {
146
+ pub fn get_printable_amount_params < const COIN_CONFIG_BUF_SIZE : usize > (
147
+ arg0 : u32 ,
148
+ ) -> PrintableAmountParams < COIN_CONFIG_BUF_SIZE > {
121
149
debug_print ( "=> get_printable_amount_params\n " ) ;
122
150
123
151
let mut libarg: libargs_t = libargs_t:: default ( ) ;
@@ -134,7 +162,19 @@ pub fn get_printable_amount_params(arg0: u32) -> PrintableAmountParams {
134
162
* ( libarg. __bindgen_anon_1 . get_printable_amount as * const get_printable_amount_parameters_t )
135
163
} ;
136
164
137
- let mut printable_amount_params: PrintableAmountParams = Default :: default ( ) ;
165
+ let mut printable_amount_params: PrintableAmountParams < COIN_CONFIG_BUF_SIZE > =
166
+ Default :: default ( ) ;
167
+
168
+ debug_print ( "==> GET_COIN_CONFIG_LENGTH\n " ) ;
169
+ printable_amount_params. coin_config_len = params. coin_configuration_length as usize ;
170
+
171
+ debug_print ( "==> GET_COIN_CONFIG \n " ) ;
172
+ unsafe {
173
+ params. coin_configuration . copy_to_nonoverlapping (
174
+ printable_amount_params. coin_config . as_mut_ptr ( ) ,
175
+ printable_amount_params. coin_config_len ,
176
+ ) ;
177
+ }
138
178
139
179
debug_print ( "==> GET_IS_FEE\n " ) ;
140
180
printable_amount_params. is_fee = params. is_fee == true ;
@@ -162,7 +202,9 @@ extern "C" {
162
202
fn c_boot_std ( ) ;
163
203
}
164
204
165
- pub fn sign_tx_params ( arg0 : u32 ) -> CreateTxParams {
205
+ pub fn sign_tx_params < const COIN_CONFIG_BUF_SIZE : usize > (
206
+ arg0 : u32 ,
207
+ ) -> CreateTxParams < COIN_CONFIG_BUF_SIZE > {
166
208
debug_print ( "=> sign_tx_params\n " ) ;
167
209
168
210
let mut libarg: libargs_t = libargs_t:: default ( ) ;
@@ -179,7 +221,18 @@ pub fn sign_tx_params(arg0: u32) -> CreateTxParams {
179
221
* ( libarg. __bindgen_anon_1 . create_transaction as * const create_transaction_parameters_t )
180
222
} ;
181
223
182
- let mut create_tx_params: CreateTxParams = Default :: default ( ) ;
224
+ let mut create_tx_params: CreateTxParams < COIN_CONFIG_BUF_SIZE > = Default :: default ( ) ;
225
+
226
+ debug_print ( "==> GET_COIN_CONFIG_LENGTH\n " ) ;
227
+ create_tx_params. coin_config_len = params. coin_configuration_length as usize ;
228
+
229
+ debug_print ( "==> GET_COIN_CONFIG \n " ) ;
230
+ unsafe {
231
+ params. coin_configuration . copy_to_nonoverlapping (
232
+ create_tx_params. coin_config . as_mut_ptr ( ) ,
233
+ create_tx_params. coin_config_len ,
234
+ ) ;
235
+ }
183
236
184
237
debug_print ( "==> GET_AMOUNT\n " ) ;
185
238
create_tx_params. amount_len = AMOUNT_BUF_SIZE . min ( params. amount_length as usize ) ;
0 commit comments