@@ -36,7 +36,7 @@ impl InsertNullifierInput {
36
36
KnownLayout , IntoBytes , Immutable , Copy , Clone , FromBytes , PartialEq , Debug , Unaligned ,
37
37
) ]
38
38
pub struct AppendLeavesInput {
39
- pub tree_account_index : u8 ,
39
+ pub account_index : u8 ,
40
40
pub leaf : [ u8 ; 32 ] ,
41
41
}
42
42
#[ repr( C ) ]
@@ -60,26 +60,33 @@ pub struct MerkleTreeSequenceNumber {
60
60
}
61
61
62
62
#[ derive( Debug , Clone ) ]
63
- pub struct AppendNullifyCreateAddressInputsIndexer < ' a > {
64
- meta : Ref < & ' a [ u8 ] , AppendNullifyCreateAddressInputsMeta > ,
63
+ pub struct InsertIntoQueuesInstructionData < ' a > {
64
+ meta : Ref < & ' a [ u8 ] , InsertIntoQueuesInstructionDataMeta > ,
65
65
pub leaves : ZeroCopySlice < ' a , u8 , AppendLeavesInput , false > ,
66
66
pub nullifiers : ZeroCopySlice < ' a , u8 , InsertNullifierInput , false > ,
67
67
pub addresses : ZeroCopySlice < ' a , u8 , InsertAddressInput , false > ,
68
68
pub sequence_numbers : ZeroCopySlice < ' a , u8 , MerkleTreeSequenceNumber , false > ,
69
69
pub output_leaf_indices : ZeroCopySlice < ' a , u8 , U32 , false > ,
70
70
}
71
- impl Deref for AppendNullifyCreateAddressInputsIndexer < ' _ > {
72
- type Target = AppendNullifyCreateAddressInputsMeta ;
71
+
72
+ impl InsertIntoQueuesInstructionData < ' _ > {
73
+ pub fn is_invoked_by_program ( & self ) -> bool {
74
+ self . meta . is_invoked_by_program == 1
75
+ }
76
+ }
77
+
78
+ impl Deref for InsertIntoQueuesInstructionData < ' _ > {
79
+ type Target = InsertIntoQueuesInstructionDataMeta ;
73
80
74
81
fn deref ( & self ) -> & Self :: Target {
75
82
& self . meta
76
83
}
77
84
}
78
85
79
- impl < ' a > Deserialize < ' a > for AppendNullifyCreateAddressInputsIndexer < ' a > {
86
+ impl < ' a > Deserialize < ' a > for InsertIntoQueuesInstructionData < ' a > {
80
87
type Output = Self ;
81
88
fn zero_copy_at ( bytes : & ' a [ u8 ] ) -> std:: result:: Result < ( Self , & ' a [ u8 ] ) , ZeroCopyError > {
82
- let ( meta, bytes) = Ref :: < & [ u8 ] , AppendNullifyCreateAddressInputsMeta > :: from_prefix ( bytes) ?;
89
+ let ( meta, bytes) = Ref :: < & [ u8 ] , InsertIntoQueuesInstructionDataMeta > :: from_prefix ( bytes) ?;
83
90
84
91
let ( leaves, bytes) = ZeroCopySlice :: < u8 , AppendLeavesInput , false > :: from_bytes_at ( bytes) ?;
85
92
@@ -94,7 +101,7 @@ impl<'a> Deserialize<'a> for AppendNullifyCreateAddressInputsIndexer<'a> {
94
101
let output_leaf_indices =
95
102
ZeroCopySlice :: < u8 , zerocopy:: little_endian:: U32 , false > :: from_bytes ( bytes) ?;
96
103
Ok ( (
97
- AppendNullifyCreateAddressInputsIndexer {
104
+ InsertIntoQueuesInstructionData {
98
105
meta,
99
106
leaves,
100
107
nullifiers,
@@ -111,7 +118,7 @@ impl<'a> Deserialize<'a> for AppendNullifyCreateAddressInputsIndexer<'a> {
111
118
#[ derive(
112
119
FromBytes , IntoBytes , KnownLayout , Immutable , Copy , Clone , PartialEq , Debug , Unaligned ,
113
120
) ]
114
- pub struct AppendNullifyCreateAddressInputsMeta {
121
+ pub struct InsertIntoQueuesInstructionDataMeta {
115
122
is_invoked_by_program : u8 ,
116
123
pub bump : u8 ,
117
124
pub num_queues : u8 ,
@@ -122,16 +129,16 @@ pub struct AppendNullifyCreateAddressInputsMeta {
122
129
}
123
130
124
131
#[ derive( Debug ) ]
125
- pub struct AppendNullifyCreateAddressInputs < ' a > {
126
- meta : Ref < & ' a mut [ u8 ] , AppendNullifyCreateAddressInputsMeta > ,
132
+ pub struct InsertIntoQueuesInstructionDataMut < ' a > {
133
+ meta : Ref < & ' a mut [ u8 ] , InsertIntoQueuesInstructionDataMeta > ,
127
134
pub leaves : ZeroCopySliceMut < ' a , u8 , AppendLeavesInput , false > ,
128
135
pub nullifiers : ZeroCopySliceMut < ' a , u8 , InsertNullifierInput , false > ,
129
136
pub addresses : ZeroCopySliceMut < ' a , u8 , InsertAddressInput , false > ,
130
137
pub sequence_numbers : ZeroCopySliceMut < ' a , u8 , MerkleTreeSequenceNumber , false > ,
131
138
pub output_leaf_indices : ZeroCopySliceMut < ' a , u8 , U32 , false > ,
132
139
}
133
140
134
- impl < ' a > AppendNullifyCreateAddressInputs < ' a > {
141
+ impl < ' a > InsertIntoQueuesInstructionDataMut < ' a > {
135
142
pub fn is_invoked_by_program ( & self ) -> bool {
136
143
self . meta . is_invoked_by_program == 1
137
144
}
@@ -146,7 +153,7 @@ impl<'a> AppendNullifyCreateAddressInputs<'a> {
146
153
addresses_capacity : u8 ,
147
154
num_output_trees : u8 ,
148
155
) -> usize {
149
- size_of :: < AppendNullifyCreateAddressInputsMeta > ( )
156
+ size_of :: < InsertIntoQueuesInstructionDataMeta > ( )
150
157
+ ZeroCopySliceMut :: < u8 , AppendLeavesInput , false > :: required_size_for_capacity (
151
158
leaves_capacity,
152
159
)
@@ -170,7 +177,7 @@ impl<'a> AppendNullifyCreateAddressInputs<'a> {
170
177
num_output_trees : u8 ,
171
178
) -> std:: result:: Result < Self , ZeroCopyError > {
172
179
let ( meta, bytes) =
173
- Ref :: < & mut [ u8 ] , AppendNullifyCreateAddressInputsMeta > :: from_prefix ( bytes) ?;
180
+ Ref :: < & mut [ u8 ] , InsertIntoQueuesInstructionDataMeta > :: from_prefix ( bytes) ?;
174
181
let ( leaves, bytes) =
175
182
ZeroCopySliceMut :: < u8 , AppendLeavesInput , false > :: new_at ( leaves_capacity, bytes) ?;
176
183
let ( nullifiers, bytes) = ZeroCopySliceMut :: < u8 , InsertNullifierInput , false > :: new_at (
@@ -185,7 +192,7 @@ impl<'a> AppendNullifyCreateAddressInputs<'a> {
185
192
bytes,
186
193
) ?;
187
194
let output_leaf_indices = ZeroCopySliceMut :: < u8 , U32 , false > :: new ( leaves_capacity, bytes) ?;
188
- Ok ( AppendNullifyCreateAddressInputs {
195
+ Ok ( InsertIntoQueuesInstructionDataMut {
189
196
meta,
190
197
leaves,
191
198
nullifiers,
@@ -196,38 +203,89 @@ impl<'a> AppendNullifyCreateAddressInputs<'a> {
196
203
}
197
204
}
198
205
199
- impl Deref for AppendNullifyCreateAddressInputs < ' _ > {
200
- type Target = AppendNullifyCreateAddressInputsMeta ;
206
+ impl Deref for InsertIntoQueuesInstructionDataMut < ' _ > {
207
+ type Target = InsertIntoQueuesInstructionDataMeta ;
201
208
202
209
fn deref ( & self ) -> & Self :: Target {
203
210
& self . meta
204
211
}
205
212
}
206
213
207
- impl DerefMut for AppendNullifyCreateAddressInputs < ' _ > {
214
+ impl DerefMut for InsertIntoQueuesInstructionDataMut < ' _ > {
208
215
fn deref_mut ( & mut self ) -> & mut Self :: Target {
209
216
& mut self . meta
210
217
}
211
218
}
212
219
213
- pub fn deserialize_insert_into_queues (
214
- bytes : & mut [ u8 ] ,
215
- ) -> std:: result:: Result < AppendNullifyCreateAddressInputs < ' _ > , ZeroCopyError > {
216
- let ( meta, bytes) = Ref :: < & mut [ u8 ] , AppendNullifyCreateAddressInputsMeta > :: from_prefix ( bytes) ?;
217
- let ( leaves, bytes) = ZeroCopySliceMut :: < u8 , AppendLeavesInput , false > :: from_bytes_at ( bytes) ?;
218
- let ( nullifiers, bytes) =
219
- ZeroCopySliceMut :: < u8 , InsertNullifierInput , false > :: from_bytes_at ( bytes) ?;
220
- let ( addresses, bytes) =
221
- ZeroCopySliceMut :: < u8 , InsertAddressInput , false > :: from_bytes_at ( bytes) ?;
222
- let ( sequence_numbers, bytes) =
223
- ZeroCopySliceMut :: < u8 , MerkleTreeSequenceNumber , false > :: from_bytes_at ( bytes) ?;
224
- let output_leaf_indices = ZeroCopySliceMut :: < u8 , U32 , false > :: from_bytes ( bytes) ?;
225
- Ok ( AppendNullifyCreateAddressInputs {
226
- meta,
227
- leaves,
228
- nullifiers,
229
- addresses,
230
- sequence_numbers,
231
- output_leaf_indices,
232
- } )
220
+ #[ test]
221
+ fn test_rnd_insert_into_queues_ix_data ( ) {
222
+ use rand:: { rngs:: StdRng , thread_rng, Rng , SeedableRng } ;
223
+ let seed = thread_rng ( ) . gen ( ) ;
224
+ println ! ( "seed {}" , seed) ;
225
+ let mut rng = StdRng :: seed_from_u64 ( seed) ;
226
+ let num_iters = 1000 ;
227
+
228
+ for _ in 0 ..num_iters {
229
+ let leaves_capacity: u8 = rng. gen ( ) ;
230
+ let nullifiers_capacity: u8 = rng. gen ( ) ;
231
+ let addresses_capacity: u8 = rng. gen ( ) ;
232
+ let num_output_trees: u8 = rng. gen ( ) ;
233
+ let size = InsertIntoQueuesInstructionDataMut :: required_size_for_capacity (
234
+ leaves_capacity,
235
+ nullifiers_capacity,
236
+ addresses_capacity,
237
+ num_output_trees,
238
+ ) ;
239
+ let mut bytes = vec ! [ 0u8 ; size] ;
240
+ let mut new_data = InsertIntoQueuesInstructionDataMut :: new (
241
+ & mut bytes,
242
+ leaves_capacity,
243
+ nullifiers_capacity,
244
+ addresses_capacity,
245
+ num_output_trees,
246
+ )
247
+ . unwrap ( ) ;
248
+ * new_data. meta = InsertIntoQueuesInstructionDataMeta {
249
+ is_invoked_by_program : rng. gen ( ) ,
250
+ bump : rng. gen ( ) ,
251
+ num_queues : rng. gen ( ) ,
252
+ num_output_queues : rng. gen ( ) ,
253
+ start_output_appends : rng. gen ( ) ,
254
+ num_address_queues : rng. gen ( ) ,
255
+ tx_hash : rng. gen ( ) ,
256
+ } ;
257
+ for i in 0 ..leaves_capacity {
258
+ new_data. leaves [ i as usize ] = AppendLeavesInput {
259
+ account_index : rng. gen ( ) ,
260
+ leaf : rng. gen ( ) ,
261
+ } ;
262
+ }
263
+ for i in 0 ..nullifiers_capacity {
264
+ new_data. nullifiers [ i as usize ] = InsertNullifierInput {
265
+ account_hash : rng. gen ( ) ,
266
+ leaf_index : rng. gen :: < u32 > ( ) . into ( ) ,
267
+ prove_by_index : rng. gen ( ) ,
268
+ tree_index : rng. gen ( ) ,
269
+ queue_index : rng. gen ( ) ,
270
+ } ;
271
+ }
272
+ for i in 0 ..addresses_capacity {
273
+ new_data. addresses [ i as usize ] = InsertAddressInput {
274
+ address : rng. gen ( ) ,
275
+ tree_index : rng. gen ( ) ,
276
+ queue_index : rng. gen ( ) ,
277
+ } ;
278
+ }
279
+ let nullifiers = new_data. nullifiers . to_vec ( ) ;
280
+ let leaves = new_data. leaves . to_vec ( ) ;
281
+ let addresses = new_data. addresses . to_vec ( ) ;
282
+ let meta = * new_data. meta ;
283
+ let zero_copy = InsertIntoQueuesInstructionData :: zero_copy_at ( & bytes)
284
+ . unwrap ( )
285
+ . 0 ;
286
+ assert_eq ! ( meta, * zero_copy. meta) ;
287
+ assert_eq ! ( leaves. as_slice( ) , zero_copy. leaves. as_slice( ) ) ;
288
+ assert_eq ! ( nullifiers. as_slice( ) , zero_copy. nullifiers. as_slice( ) ) ;
289
+ assert_eq ! ( addresses. as_slice( ) , zero_copy. addresses. as_slice( ) ) ;
290
+ }
233
291
}
0 commit comments