@@ -283,13 +283,15 @@ pub mod let_me_buy {
283283 ) ;
284284
285285 // Find and remove the product
286- let products = & mut ctx. accounts . receipts . products ;
287- let index = products
286+ let index = ctx
287+ . accounts
288+ . receipts
289+ . products
288290 . iter ( )
289291 . position ( |p| p. name == product_name)
290292 . ok_or ( StoreErrorCode :: ProductNotFound ) ?;
291293
292- products. remove ( index) ;
294+ ctx . accounts . receipts . products . remove ( index) ;
293295
294296 Ok ( ( ) )
295297 }
@@ -320,6 +322,24 @@ pub mod let_me_buy {
320322 }
321323}
322324
325+ #[ account]
326+ #[ derive( InitSpace ) ]
327+ pub struct Receipts {
328+ #[ max_len( 20 ) ]
329+ pub receipts : Vec < Receipt > ,
330+ pub total_purchases : u64 ,
331+ #[ max_len( 32 ) ]
332+ pub store_name : String ,
333+ pub authority : Pubkey ,
334+ #[ max_len( 20 ) ]
335+ pub products : Vec < Products > ,
336+ #[ max_len( 32 ) ]
337+ pub telegram_channel_id : String ,
338+ pub bump : u8 ,
339+ #[ max_len( 128 ) ]
340+ pub details : String ,
341+ }
342+
323343#[ derive( Accounts ) ]
324344#[ instruction( store_name: String ) ]
325345pub struct Initialize < ' info > {
@@ -331,7 +351,7 @@ pub struct Initialize<'info> {
331351 bump,
332352 constraint = store_name. len( ) <= 32 @ StoreErrorCode :: StringTooLong
333353 ) ]
334- pub receipts : Account < ' info , Receipts > ,
354+ pub receipts : Box < Account < ' info , Receipts > > ,
335355 #[ account( mut ) ]
336356 pub authority : Signer < ' info > ,
337357 pub system_program : Program < ' info , System > ,
@@ -345,7 +365,7 @@ pub struct UpdateTelegramChannel<'info> {
345365 seeds = [ b"receipts" , store_name. as_bytes( ) ] ,
346366 bump
347367 ) ]
348- pub receipts : Account < ' info , Receipts > ,
368+ pub receipts : Box < Account < ' info , Receipts > > ,
349369 #[ account( mut ) ]
350370 pub authority : Signer < ' info > ,
351371}
@@ -358,7 +378,7 @@ pub struct UpdateDetails<'info> {
358378 seeds = [ b"receipts" , store_name. as_bytes( ) ] ,
359379 bump
360380 ) ]
361- pub receipts : Account < ' info , Receipts > ,
381+ pub receipts : Box < Account < ' info , Receipts > > ,
362382 #[ account( mut ) ]
363383 pub authority : Signer < ' info > ,
364384}
@@ -374,7 +394,7 @@ pub struct AddProduct<'info> {
374394 realloc:: payer = authority,
375395 realloc:: zero = false
376396 ) ]
377- pub receipts : Account < ' info , Receipts > ,
397+ pub receipts : Box < Account < ' info , Receipts > > ,
378398 #[ account( mut ) ]
379399 pub authority : Signer < ' info > ,
380400 pub mint : Account < ' info , Mint > ,
@@ -389,7 +409,7 @@ pub struct MakePurchase<'info> {
389409 seeds = [ b"receipts" , store_name. as_bytes( ) ] ,
390410 bump
391411 ) ]
392- pub receipts : Account < ' info , Receipts > ,
412+ pub receipts : Box < Account < ' info , Receipts > > ,
393413 #[ account( mut ) ]
394414 pub signer : Signer < ' info > ,
395415 #[ account( mut ) ]
@@ -418,7 +438,7 @@ pub struct MarkAsDelivered<'info> {
418438 seeds = [ b"receipts" , store_name. as_bytes( ) ] ,
419439 bump
420440 ) ]
421- pub receipts : Account < ' info , Receipts > ,
441+ pub receipts : Box < Account < ' info , Receipts > > ,
422442 #[ account( mut ) ]
423443 pub authority : Signer < ' info > ,
424444}
@@ -434,7 +454,7 @@ pub struct DeleteProduct<'info> {
434454 realloc:: payer = authority,
435455 realloc:: zero = false
436456 ) ]
437- pub receipts : Account < ' info , Receipts > ,
457+ pub receipts : Box < Account < ' info , Receipts > > ,
438458 #[ account( mut ) ]
439459 pub authority : Signer < ' info > ,
440460 pub system_program : Program < ' info , System > ,
@@ -449,29 +469,11 @@ pub struct DeleteStore<'info> {
449469 bump,
450470 close = authority
451471 ) ]
452- pub receipts : Account < ' info , Receipts > ,
472+ pub receipts : Box < Account < ' info , Receipts > > ,
453473 #[ account( mut ) ]
454474 pub authority : Signer < ' info > ,
455475}
456476
457- #[ account]
458- #[ derive( InitSpace ) ]
459- pub struct Receipts {
460- #[ max_len( 20 ) ]
461- pub receipts : Vec < Receipt > ,
462- pub total_purchases : u64 ,
463- #[ max_len( 32 ) ]
464- pub store_name : String ,
465- pub authority : Pubkey ,
466- #[ max_len( 20 ) ]
467- pub products : Vec < Products > ,
468- #[ max_len( 32 ) ]
469- pub telegram_channel_id : String ,
470- pub bump : u8 ,
471- #[ max_len( 128 ) ]
472- pub details : String ,
473- }
474-
475477#[ derive( AnchorSerialize , AnchorDeserialize , Clone , Default , InitSpace ) ]
476478pub struct Products {
477479 pub price : u64 ,
0 commit comments