1
1
use super :: {
2
2
cpi_context:: CompressedCpiContext ,
3
3
data:: { NewAddressParamsPacked , OutputCompressedAccountWithPackedContext } ,
4
- zero_copy:: ZInstructionDataInvokeCpi ,
5
4
} ;
6
5
use crate :: {
7
6
compressed_account:: PackedCompressedAccountWithMerkleContext ,
@@ -21,99 +20,3 @@ pub struct InstructionDataInvokeCpi {
21
20
pub is_compress : bool ,
22
21
pub cpi_context : Option < CompressedCpiContext > ,
23
22
}
24
-
25
- impl < ' a , ' info : ' a > ZInstructionDataInvokeCpi < ' a > {
26
- pub fn combine ( & mut self , other : Vec < ZInstructionDataInvokeCpi < ' info > > ) {
27
- for other in other {
28
- // TODO: support address creation with cpi context
29
- // issue is that we deserialize address creation params as zero copy slice we cannot push into it
30
- // could reenable by passing it as extra argument without losing performance.
31
- // self.new_address_params
32
- // .extend_from_slice(&other.new_address_params);
33
- for i in other. input_compressed_accounts_with_merkle_context . iter ( ) {
34
- self . input_compressed_accounts_with_merkle_context
35
- . push ( ( * i) . clone ( ) ) ;
36
- }
37
- for i in other. output_compressed_accounts . iter ( ) {
38
- self . output_compressed_accounts . push ( ( * i) . clone ( ) ) ;
39
- }
40
- }
41
- }
42
- }
43
-
44
- #[ cfg( test) ]
45
- mod tests {
46
- use std:: vec;
47
-
48
- use light_zero_copy:: borsh:: Deserialize ;
49
-
50
- use super :: * ;
51
- use crate :: {
52
- compressed_account:: PackedCompressedAccountWithMerkleContext ,
53
- instruction_data:: {
54
- data:: { NewAddressParamsPacked , OutputCompressedAccountWithPackedContext } ,
55
- invoke_cpi:: InstructionDataInvokeCpi ,
56
- zero_copy:: ZInstructionDataInvokeCpi ,
57
- } ,
58
- } ;
59
-
60
- // test combine instruction data transfer
61
- #[ test]
62
- fn test_combine_instruction_data_transfer ( ) {
63
- let mut instruction_data_transfer = InstructionDataInvokeCpi {
64
- proof : Some ( CompressedProof {
65
- a : [ 0 ; 32 ] ,
66
- b : [ 0 ; 64 ] ,
67
- c : [ 0 ; 32 ] ,
68
- } ) ,
69
- new_address_params : vec ! [ NewAddressParamsPacked :: default ( ) ] ,
70
- input_compressed_accounts_with_merkle_context : vec ! [
71
- PackedCompressedAccountWithMerkleContext :: default ( ) ,
72
- ] ,
73
- output_compressed_accounts : vec ! [ OutputCompressedAccountWithPackedContext :: default ( ) ] ,
74
- relay_fee : None ,
75
- compress_or_decompress_lamports : Some ( 1 ) ,
76
- is_compress : true ,
77
- cpi_context : None ,
78
- } ;
79
- instruction_data_transfer. input_compressed_accounts_with_merkle_context [ 0 ]
80
- . merkle_context
81
- . leaf_index = 1 ;
82
- instruction_data_transfer. output_compressed_accounts [ 0 ] . merkle_tree_index = 1 ;
83
- let other = InstructionDataInvokeCpi {
84
- proof : Some ( CompressedProof {
85
- a : [ 0 ; 32 ] ,
86
- b : [ 0 ; 64 ] ,
87
- c : [ 0 ; 32 ] ,
88
- } ) ,
89
- input_compressed_accounts_with_merkle_context : vec ! [
90
- PackedCompressedAccountWithMerkleContext :: default ( ) ,
91
- ] ,
92
- output_compressed_accounts : vec ! [ OutputCompressedAccountWithPackedContext :: default ( ) ] ,
93
- relay_fee : None ,
94
- compress_or_decompress_lamports : Some ( 1 ) ,
95
- is_compress : true ,
96
- new_address_params : vec ! [ NewAddressParamsPacked :: default ( ) ] ,
97
- cpi_context : None ,
98
- } ;
99
- let mut vec = Vec :: new ( ) ;
100
- instruction_data_transfer. serialize ( & mut vec) . unwrap ( ) ;
101
- let mut other_vec = Vec :: new ( ) ;
102
- other. serialize ( & mut other_vec) . unwrap ( ) ;
103
- let ( mut instruction_data_transfer, _) =
104
- ZInstructionDataInvokeCpi :: zero_copy_at ( & vec) . unwrap ( ) ;
105
- let ( other, _) = ZInstructionDataInvokeCpi :: zero_copy_at ( & other_vec) . unwrap ( ) ;
106
- instruction_data_transfer. combine ( vec ! [ other] ) ;
107
- assert_eq ! ( instruction_data_transfer. new_address_params. len( ) , 1 ) ;
108
- assert_eq ! (
109
- instruction_data_transfer
110
- . input_compressed_accounts_with_merkle_context
111
- . len( ) ,
112
- 2
113
- ) ;
114
- assert_eq ! (
115
- instruction_data_transfer. output_compressed_accounts. len( ) ,
116
- 2
117
- ) ;
118
- }
119
- }
0 commit comments