Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ impl<'info> InitializeTransferSPL<'info> {
CpiContext::new(self.token_program.to_account_info(), cpi_accounts)
}

// REVIEW: should be claim_rent_from_sender
pub fn cliam_rent_from_sender(&self) -> Result<()> {
let rent = Rent::get()?;
let recipient_token_account_rent = rent.minimum_balance(TokenAccount::LEN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pub struct RedeemFundsSOL<'info> {
}

impl<'info> RedeemFundsSOL<'info> {
// REVIEW: I assume the secret is randomly generated, otherwise it would be better to use a hash and a salt
pub fn verify_secret(&self, secret: &str) -> Result<()> {
let provided_hash = {
let mut hasher = Sha256::new();
Expand All @@ -140,6 +141,7 @@ impl<'info> RedeemFundsSOL<'info> {
}

pub fn transfer_sol_to_recipient(&self, amount: u64) -> Result<()> {
// REVIEW: you have to use the system program to transfer lamports, like you did in the initialize_transfer_spl instruction
**self.recipient.to_account_info().try_borrow_mut_lamports()? += amount;
**self.escrow_account.to_account_info().try_borrow_mut_lamports()? -= amount;
Ok(())
Expand All @@ -166,6 +168,7 @@ pub fn redeem_funds_sol(ctx: Context<RedeemFundsSOL>, secret: String) -> Result<

ctx.accounts.escrow_account.is_redeemed = true;
ctx.accounts.transfer_sol_to_recipient(ctx.accounts.escrow_account.amount)?;
// REVIEW: after the transfer, the escrow account should be deleted
// ctx.accounts.refund_remaining_lamports_to_sender()?;

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct RefundFundsSPL<'info> {
}

impl<'info> RefundFundsSPL<'info> {
// REVIEW: I assume the secret is randomly generated, otherwise it would be better to use a hash and a salt
pub fn verify_secret(&self, secret: &str) -> Result<()> {
let provided_hash = {
let mut hasher = Sha256::new();
Expand Down Expand Up @@ -122,6 +123,7 @@ impl<'info> RefundFundsSOL<'info> {
}

pub fn transfer_sol_back_to_sender(&self, amount: u64) -> Result<()> {
// REVIEW: this also does not work because you need to call the system program to transfer lamports
**self.sender.to_account_info().try_borrow_mut_lamports()? += amount;
**self
.escrow_account
Expand Down