@@ -89,6 +89,7 @@ pub struct LightAccount<
89
89
owner : & ' a Pubkey ,
90
90
pub account : A ,
91
91
account_info : CompressedAccountInfo ,
92
+ empty_data : bool ,
92
93
}
93
94
94
95
impl < ' a , A : AnchorSerialize + AnchorDeserialize + LightDiscriminator + DataHasher + Default >
@@ -112,6 +113,7 @@ impl<'a, A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + DataHashe
112
113
input : None ,
113
114
output : Some ( output_account_info) ,
114
115
} ,
116
+ empty_data : false ,
115
117
}
116
118
}
117
119
@@ -156,6 +158,7 @@ impl<'a, A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + DataHashe
156
158
input : Some ( input_account_info) ,
157
159
output : Some ( output_account_info) ,
158
160
} ,
161
+ empty_data : false ,
159
162
} )
160
163
}
161
164
@@ -188,6 +191,7 @@ impl<'a, A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + DataHashe
188
191
input : Some ( input_account_info) ,
189
192
output : None ,
190
193
} ,
194
+ empty_data : false ,
191
195
} )
192
196
}
193
197
@@ -260,7 +264,8 @@ impl<'a, A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + DataHashe
260
264
/// Remove the data from this account by setting it to default.
261
265
/// This is used when decompressing to ensure the compressed account is properly zeroed.
262
266
pub fn remove_data ( & mut self ) {
263
- self . account = A :: default ( ) ;
267
+ self . account = A :: default ( ) ; // TODO: remove
268
+ self . empty_data = true ;
264
269
}
265
270
266
271
/// 1. Serializes the account data and sets the output data hash.
@@ -270,11 +275,17 @@ impl<'a, A: AnchorSerialize + AnchorDeserialize + LightDiscriminator + DataHashe
270
275
/// that should only be called once per instruction.
271
276
pub fn to_account_info ( mut self ) -> Result < CompressedAccountInfo , LightSdkError > {
272
277
if let Some ( output) = self . account_info . output . as_mut ( ) {
273
- output. data_hash = self . account . hash :: < Poseidon > ( ) ?;
274
- output. data = self
275
- . account
276
- . try_to_vec ( )
277
- . map_err ( |_| LightSdkError :: Borsh ) ?;
278
+ if self . empty_data {
279
+ // TODO: check if this is right
280
+ output. data_hash = [ 0 ; 32 ] ;
281
+ output. data = Vec :: new ( ) ;
282
+ } else {
283
+ output. data_hash = self . account . hash :: < Poseidon > ( ) ?;
284
+ output. data = self
285
+ . account
286
+ . try_to_vec ( )
287
+ . map_err ( |_| LightSdkError :: Borsh ) ?;
288
+ }
278
289
}
279
290
Ok ( self . account_info )
280
291
}
0 commit comments