Trait Lamports

Source
pub trait Lamports<'info>: AsRef<AccountInfo<'info>> {
    // Provided methods
    fn get_lamports(&self) -> u64 { ... }
    fn add_lamports(&self, amount: u64) -> Result<&Self, Error> { ... }
    fn sub_lamports(&self, amount: u64) -> Result<&Self, Error> { ... }
}
Expand description

Lamports related utility methods for accounts.

Provided Methods§

Source

fn get_lamports(&self) -> u64

Get the lamports of the account.

Source

fn add_lamports(&self, amount: u64) -> Result<&Self, Error>

Add lamports to the account.

This method is useful for transfering lamports from a PDA.

§Requirements
  1. The account must be marked mut.
  2. The total lamports before the transaction must equal to total lamports after the transaction.
  3. lamports field of the account info should not currently be borrowed.

See Lamports::sub_lamports for subtracting lamports.

Source

fn sub_lamports(&self, amount: u64) -> Result<&Self, Error>

Subtract lamports from the account.

This method is useful for transfering lamports from a PDA.

§Requirements
  1. The account must be owned by the executing program.
  2. The account must be marked mut.
  3. The total lamports before the transaction must equal to total lamports after the transaction.
  4. lamports field of the account info should not currently be borrowed.

See Lamports::add_lamports for adding lamports.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'info, T> Lamports<'info> for T
where T: AsRef<AccountInfo<'info>>,