Skip to content

Commit 07e3f70

Browse files
committed
Update lib.rs
1 parent 365259a commit 07e3f70

1 file changed

Lines changed: 0 additions & 111 deletions

File tree

programs/let-me-buy/src/lib.rs

Lines changed: 0 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ pub enum StoreErrorCode {
4343
VectorLimitReached,
4444
#[msg("InvalidStoreName")]
4545
InvalidStoreName,
46-
#[msg("ArithmeticOverflow")]
47-
ArithmeticOverflow,
4846
}
4947

5048
fn validate_store_name(name: &str) -> Result<()> {
@@ -68,8 +66,6 @@ fn validate_store_name(name: &str) -> Result<()> {
6866

6967
#[program]
7068
pub mod let_me_buy {
71-
use anchor_lang::solana_program::{program::invoke, system_instruction};
72-
7369
use super::*;
7470

7571
pub fn initialize(ctx: Context<Initialize>, store_name: String) -> Result<()> {
@@ -318,83 +314,6 @@ pub mod let_me_buy {
318314

319315
Ok(())
320316
}
321-
322-
pub fn realloc_store(ctx: Context<ReallocStore>, store_name: String) -> Result<()> {
323-
// Verify authority
324-
require!(
325-
ctx.accounts.receipts.owner == ctx.program_id,
326-
StoreErrorCode::InvalidAuthority
327-
);
328-
329-
let new_size = 8 + Receipts::INIT_SPACE + 1000;
330-
331-
// Calculate the new account size
332-
// let new_size = 8 + // discriminator
333-
// (std::mem::size_of::<Receipt>() * 20) + // receipts array
334-
// 4 + // receipts_count
335-
// 8 + // total_purchases
336-
// 4 + 32 + // store_name
337-
// 32 + // authority
338-
// (std::mem::size_of::<Products>() * 20) + // products array
339-
// 4 + // products_count
340-
// 4 + 32 + // telegram_channel_id
341-
// 1 + // bump
342-
// 4 + 128; // details
343-
344-
let receipts_info = &ctx.accounts.receipts;
345-
let payer = &ctx.accounts.authority;
346-
let system_program = &ctx.accounts.system_program;
347-
348-
// Calculate required lamports for the new size
349-
let rent = Rent::get()?;
350-
let new_minimum_balance = rent.minimum_balance(new_size);
351-
let lamports_diff = new_minimum_balance.saturating_sub(receipts_info.lamports());
352-
353-
// Transfer additional lamports if needed
354-
if lamports_diff > 0 {
355-
invoke(
356-
&system_instruction::transfer(payer.key, receipts_info.key, lamports_diff),
357-
&[
358-
payer.to_account_info(),
359-
receipts_info.to_account_info(),
360-
system_program.to_account_info(),
361-
],
362-
)?;
363-
}
364-
365-
// Reallocate the account without zeroing
366-
receipts_info.realloc(new_size, false)?;
367-
368-
msg!(
369-
"Successfully reallocated store account to new size: {}",
370-
new_size
371-
);
372-
Ok(())
373-
}
374-
375-
pub fn close_store(ctx: Context<CloseStore>, store_name: String) -> Result<()> {
376-
let receipts_info = &ctx.accounts.receipts;
377-
let authority_info = &ctx.accounts.authority;
378-
379-
// Get the current lamports
380-
let current_lamports = receipts_info.lamports();
381-
382-
// Transfer all lamports to the authority (closing the account)
383-
**receipts_info.try_borrow_mut_lamports()? = 0;
384-
**authority_info.try_borrow_mut_lamports()? = authority_info
385-
.lamports()
386-
.checked_add(current_lamports)
387-
.ok_or(error!(StoreErrorCode::ArithmeticOverflow))?;
388-
389-
// Clear the account data
390-
let mut data = receipts_info.try_borrow_mut_data()?;
391-
for byte in data.iter_mut() {
392-
*byte = 0;
393-
}
394-
395-
msg!("Successfully closed store account");
396-
Ok(())
397-
}
398317
}
399318

400319
#[account]
@@ -549,36 +468,6 @@ pub struct DeleteStore<'info> {
549468
pub authority: Signer<'info>,
550469
}
551470

552-
#[derive(Accounts)]
553-
#[instruction(store_name: String)]
554-
pub struct ReallocStore<'info> {
555-
/// CHECK: Account is a PDA that we verify in the instruction
556-
#[account(
557-
mut,
558-
seeds = [b"receipts", store_name.as_bytes()],
559-
bump,
560-
)]
561-
pub receipts: AccountInfo<'info>,
562-
#[account(mut)]
563-
pub authority: Signer<'info>,
564-
pub system_program: Program<'info, System>,
565-
}
566-
567-
#[derive(Accounts)]
568-
#[instruction(store_name: String)]
569-
pub struct CloseStore<'info> {
570-
/// CHECK: Account is a PDA that we verify in the instruction
571-
#[account(
572-
mut,
573-
seeds = [b"receipts", store_name.as_bytes()],
574-
bump,
575-
)]
576-
pub receipts: AccountInfo<'info>,
577-
#[account(mut)]
578-
pub authority: Signer<'info>,
579-
pub system_program: Program<'info, System>,
580-
}
581-
582471
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default, InitSpace)]
583472
pub struct Products {
584473
pub price: u64,

0 commit comments

Comments
 (0)