@@ -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,20 @@ 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
116
+ . coin_config_len
117
+ . min ( COIN_CONFIG_BUF_SIZE ) ,
118
+ ) ;
119
+ }
92
120
93
121
debug_print ( "==> GET_DPATH_LENGTH\n " ) ;
94
122
check_address_params. dpath_len =
@@ -117,7 +145,9 @@ pub fn get_check_address_params(arg0: u32) -> CheckAddressParams {
117
145
check_address_params
118
146
}
119
147
120
- pub fn get_printable_amount_params ( arg0 : u32 ) -> PrintableAmountParams {
148
+ pub fn get_printable_amount_params < const COIN_CONFIG_BUF_SIZE : usize > (
149
+ arg0 : u32 ,
150
+ ) -> PrintableAmountParams < COIN_CONFIG_BUF_SIZE > {
121
151
debug_print ( "=> get_printable_amount_params\n " ) ;
122
152
123
153
let mut libarg: libargs_t = libargs_t:: default ( ) ;
@@ -134,7 +164,21 @@ pub fn get_printable_amount_params(arg0: u32) -> PrintableAmountParams {
134
164
* ( libarg. __bindgen_anon_1 . get_printable_amount as * const get_printable_amount_parameters_t )
135
165
} ;
136
166
137
- let mut printable_amount_params: PrintableAmountParams = Default :: default ( ) ;
167
+ let mut printable_amount_params: PrintableAmountParams < COIN_CONFIG_BUF_SIZE > =
168
+ Default :: default ( ) ;
169
+
170
+ debug_print ( "==> GET_COIN_CONFIG_LENGTH\n " ) ;
171
+ printable_amount_params. coin_config_len = params. coin_configuration_length as usize ;
172
+
173
+ debug_print ( "==> GET_COIN_CONFIG \n " ) ;
174
+ unsafe {
175
+ params. coin_configuration . copy_to_nonoverlapping (
176
+ printable_amount_params. coin_config . as_mut_ptr ( ) ,
177
+ printable_amount_params
178
+ . coin_config_len
179
+ . min ( COIN_CONFIG_BUF_SIZE ) ,
180
+ ) ;
181
+ }
138
182
139
183
debug_print ( "==> GET_IS_FEE\n " ) ;
140
184
printable_amount_params. is_fee = params. is_fee == true ;
@@ -162,7 +206,9 @@ extern "C" {
162
206
fn c_boot_std ( ) ;
163
207
}
164
208
165
- pub fn sign_tx_params ( arg0 : u32 ) -> CreateTxParams {
209
+ pub fn sign_tx_params < const COIN_CONFIG_BUF_SIZE : usize > (
210
+ arg0 : u32 ,
211
+ ) -> CreateTxParams < COIN_CONFIG_BUF_SIZE > {
166
212
debug_print ( "=> sign_tx_params\n " ) ;
167
213
168
214
let mut libarg: libargs_t = libargs_t:: default ( ) ;
@@ -179,7 +225,18 @@ pub fn sign_tx_params(arg0: u32) -> CreateTxParams {
179
225
* ( libarg. __bindgen_anon_1 . create_transaction as * const create_transaction_parameters_t )
180
226
} ;
181
227
182
- let mut create_tx_params: CreateTxParams = Default :: default ( ) ;
228
+ let mut create_tx_params: CreateTxParams < COIN_CONFIG_BUF_SIZE > = Default :: default ( ) ;
229
+
230
+ debug_print ( "==> GET_COIN_CONFIG_LENGTH\n " ) ;
231
+ create_tx_params. coin_config_len = params. coin_configuration_length as usize ;
232
+
233
+ debug_print ( "==> GET_COIN_CONFIG \n " ) ;
234
+ unsafe {
235
+ params. coin_configuration . copy_to_nonoverlapping (
236
+ create_tx_params. coin_config . as_mut_ptr ( ) ,
237
+ create_tx_params. coin_config_len . min ( COIN_CONFIG_BUF_SIZE ) ,
238
+ ) ;
239
+ }
183
240
184
241
debug_print ( "==> GET_AMOUNT\n " ) ;
185
242
create_tx_params. amount_len = AMOUNT_BUF_SIZE . min ( params. amount_length as usize ) ;
0 commit comments