pub struct LamportSnapshot { /* private fields */ }Expand description
Snapshot of lamport balances for two accounts before a CPI.
Captures the source and destination balances so that after the CPI completes, we can verify the expected transfer occurred.
Implementations§
Source§impl LamportSnapshot
impl LamportSnapshot
Sourcepub fn capture(source: &AccountView, destination: &AccountView) -> Self
pub fn capture(source: &AccountView, destination: &AccountView) -> Self
Capture the current lamport balances of source and destination.
Sourcepub fn verify_transfer(
&self,
source: &AccountView,
destination: &AccountView,
amount: u64,
) -> ProgramResult
pub fn verify_transfer( &self, source: &AccountView, destination: &AccountView, amount: u64, ) -> ProgramResult
Verify that exactly amount lamports moved from source to destination.
Checks:
- Source decreased by exactly
amount - Destination increased by exactly
amount - No overflow/underflow occurred
Sourcepub fn verify_deduction(
&self,
source: &AccountView,
amount: u64,
) -> ProgramResult
pub fn verify_deduction( &self, source: &AccountView, amount: u64, ) -> ProgramResult
Verify that the source decreased by exactly amount (one-sided check).
Use this when the destination is a program-controlled escrow or fee account where you only care about the deduction.
Sourcepub fn verify_unchanged(
&self,
source: &AccountView,
destination: &AccountView,
) -> ProgramResult
pub fn verify_unchanged( &self, source: &AccountView, destination: &AccountView, ) -> ProgramResult
Verify that neither balance changed (no-op CPI or read-only call).
Sourcepub fn source_before(&self) -> u64
pub fn source_before(&self) -> u64
Get the pre-CPI source balance.
Sourcepub fn destination_before(&self) -> u64
pub fn destination_before(&self) -> u64
Get the pre-CPI destination balance.
Trait Implementations§
Source§impl Clone for LamportSnapshot
impl Clone for LamportSnapshot
Source§fn clone(&self) -> LamportSnapshot
fn clone(&self) -> LamportSnapshot
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LamportSnapshot
impl Debug for LamportSnapshot
impl Copy for LamportSnapshot
Auto Trait Implementations§
impl Freeze for LamportSnapshot
impl RefUnwindSafe for LamportSnapshot
impl Send for LamportSnapshot
impl Sync for LamportSnapshot
impl Unpin for LamportSnapshot
impl UnsafeUnpin for LamportSnapshot
impl UnwindSafe for LamportSnapshot
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more