Introducing Scripts
A sequence of instructions. A client compiles the script and then uses the compiled script to construction a transaction. Then it adds a adds a blockhash, signs the transaction, and sends it off for processing.
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
use crate::bank::Bank;
|
||||
use solana_sdk::signature::Keypair;
|
||||
use solana_sdk::transaction::{Transaction, TransactionError};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_instruction::SystemInstruction;
|
||||
use solana_sdk::transaction::{Script, Transaction, TransactionError};
|
||||
|
||||
pub struct BankClient<'a> {
|
||||
bank: &'a Bank,
|
||||
@ -12,8 +14,23 @@ impl<'a> BankClient<'a> {
|
||||
Self { bank, keypair }
|
||||
}
|
||||
|
||||
pub fn process_transaction(&self, tx: &mut Transaction) -> Result<(), TransactionError> {
|
||||
pub fn pubkey(&self) -> Pubkey {
|
||||
self.keypair.pubkey()
|
||||
}
|
||||
|
||||
pub fn process_transaction(&self, mut tx: Transaction) -> Result<(), TransactionError> {
|
||||
tx.sign(&[&self.keypair], self.bank.last_blockhash());
|
||||
self.bank.process_transaction(tx)
|
||||
self.bank.process_transaction(&mut tx)
|
||||
}
|
||||
|
||||
/// Create and process a transaction.
|
||||
pub fn process_script(&self, script: Script) -> Result<(), TransactionError> {
|
||||
self.process_transaction(Transaction::new(script))
|
||||
}
|
||||
|
||||
/// Transfer lamports to pubkey
|
||||
pub fn transfer(&self, lamports: u64, pubkey: &Pubkey) -> Result<(), TransactionError> {
|
||||
let move_instruction = SystemInstruction::new_move(&self.pubkey(), pubkey, lamports);
|
||||
self.process_script(vec![move_instruction])
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user