Trait Environment

Source
pub trait Environment {
Show 21 methods // Required methods fn payer(&self) -> Keypair; fn execute_transaction( &mut self, txs: Transaction, ) -> EncodedConfirmedTransactionWithStatusMeta; fn get_latest_blockhash(&self) -> Hash; fn get_rent_excemption(&self, data: usize) -> u64; fn get_account(&self, pubkey: Pubkey) -> Option<Account>; // Provided methods fn get_recent_blockhash(&self) -> Hash { ... } fn tx_with_instructions( &self, instructions: &[Instruction], signers: &[&Keypair], ) -> Transaction { ... } fn execute_as_transaction( &mut self, instructions: &[Instruction], signers: &[&Keypair], ) -> EncodedConfirmedTransactionWithStatusMeta { ... } fn execute_as_transaction_debug( &mut self, instructions: &[Instruction], signers: &[&Keypair], ) -> EncodedConfirmedTransactionWithStatusMeta { ... } fn create_account( &mut self, keypair: &Keypair, lamports: u64, space: usize, owner: Pubkey, ) { ... } fn create_account_rent_excempt( &mut self, keypair: &Keypair, space: usize, owner: Pubkey, ) { ... } fn create_token_mint( &mut self, mint: &Keypair, authority: Pubkey, freeze_authority: Option<Pubkey>, decimals: u8, ) { ... } fn mint_tokens( &mut self, mint: Pubkey, authority: &Keypair, account: Pubkey, amount: u64, ) { ... } fn create_token_account(&mut self, account: &Keypair, mint: Pubkey) { ... } fn create_associated_token_account( &mut self, owner: &Keypair, mint: Pubkey, ) -> Pubkey { ... } fn get_or_create_associated_token_account( &mut self, owner: &Keypair, mint: Pubkey, ) -> Pubkey { ... } fn create_account_with_data(&mut self, account: &Keypair, data: Vec<u8>) { ... } fn deploy_program<P: AsRef<Path>>(&mut self, program_path: P) -> Pubkey { ... } fn get_unpacked_account<T: Pack>(&self, pubkey: Pubkey) -> Option<T> { ... } fn get_deserialized_account<T: BorshDeserialize>( &self, pubkey: Pubkey, ) -> Option<T> { ... } fn get_serde_deserialized_account<'a, T: DeserializeOwned>( &self, pubkey: Pubkey, ) -> Option<T> { ... }
}
Expand description

A generic Environment trait. Provides the possibility of writing generic exploits that work both remote and local, for easy debugging.

Required Methods§

Source

fn payer(&self) -> Keypair

Returns the keypair used to pay for all transactions. All transaction fees and rent costs are payed for by this keypair.

Source

fn execute_transaction( &mut self, txs: Transaction, ) -> EncodedConfirmedTransactionWithStatusMeta

Executes the batch of transactions in the right order and waits for them to be confirmed. The execution results are returned.

Source

fn get_latest_blockhash(&self) -> Hash

Fetch the latest blockhash, for construction of transactions.

Source

fn get_rent_excemption(&self, data: usize) -> u64

Fetch the amount of lamports needed for an account of the given size to be rent excempt.

Source

fn get_account(&self, pubkey: Pubkey) -> Option<Account>

Fetch an account. None if the account does not exist.

Provided Methods§

Source

fn get_recent_blockhash(&self) -> Hash

👎Deprecated since 0.2.0: Please use get_latest_blockhash() instead

Fetch a recent blockhash, for construction of transactions.

Source

fn tx_with_instructions( &self, instructions: &[Instruction], signers: &[&Keypair], ) -> Transaction

Assemble the given instructions into a transaction and sign it. All transactions constructed by this method are signed and payed for by the payer.

Source

fn execute_as_transaction( &mut self, instructions: &[Instruction], signers: &[&Keypair], ) -> EncodedConfirmedTransactionWithStatusMeta

Assemble the given instructions into a transaction and sign it. All transactions executed by this method are signed and payed for by the payer.

Source

fn execute_as_transaction_debug( &mut self, instructions: &[Instruction], signers: &[&Keypair], ) -> EncodedConfirmedTransactionWithStatusMeta

Assemble the given instructions into a transaction and sign it. All transactions executed by this method are signed and payed for by the payer. Prints the transaction before sending it.

Source

fn create_account( &mut self, keypair: &Keypair, lamports: u64, space: usize, owner: Pubkey, )

Executes a transaction constructing an empty account with the specified amount of space and lamports, owned by the provided program.

Source

fn create_account_rent_excempt( &mut self, keypair: &Keypair, space: usize, owner: Pubkey, )

Executes a transaction constructing an empty rent-excempt account with the specified amount of space, owned by the provided program.

Source

fn create_token_mint( &mut self, mint: &Keypair, authority: Pubkey, freeze_authority: Option<Pubkey>, decimals: u8, )

Executes a transaction constructing a token mint. The account needs to be empty and belong to system for this to work.

Source

fn mint_tokens( &mut self, mint: Pubkey, authority: &Keypair, account: Pubkey, amount: u64, )

Executes a transaction that mints tokens from a mint to an account belonging to that mint.

Source

fn create_token_account(&mut self, account: &Keypair, mint: Pubkey)

Executes a transaction constructing a token account of the specified mint. The account needs to be empty and belong to system for this to work. Prefer to use [create_associated_token_account] if you don’t need the provided account to contain the token account.

Source

fn create_associated_token_account( &mut self, owner: &Keypair, mint: Pubkey, ) -> Pubkey

Executes a transaction constructing the associated token account of the specified mint belonging to the owner. This will fail if the account already exists.

Source

fn get_or_create_associated_token_account( &mut self, owner: &Keypair, mint: Pubkey, ) -> Pubkey

Executes a transaction constructing the associated token account of the specified mint belonging to the owner.

Source

fn create_account_with_data(&mut self, account: &Keypair, data: Vec<u8>)

Executes a transaction creating and filling the given account with the given data. The account is required to be empty and will be owned by bpf_loader afterwards.

Source

fn deploy_program<P: AsRef<Path>>(&mut self, program_path: P) -> Pubkey

Executes a transaction deploying a program from a file if it does not already exist. The keypair is derived from the file contents.

Source

fn get_unpacked_account<T: Pack>(&self, pubkey: Pubkey) -> Option<T>

Gets and unpacks an account. None if the account does not exist.

Source

fn get_deserialized_account<T: BorshDeserialize>( &self, pubkey: Pubkey, ) -> Option<T>

Gets and deserializes an account. None if the account does not exist.

Source

fn get_serde_deserialized_account<'a, T: DeserializeOwned>( &self, pubkey: Pubkey, ) -> Option<T>

Gets and deserializes an account. None if the account does not exist.

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§