2018-12-04 15:18:35 -08:00
|
|
|
//! The `loader_transaction` module provides functionality for loading and calling a program
|
2018-10-16 09:43:49 -07:00
|
|
|
|
2018-12-04 15:18:35 -08:00
|
|
|
use hash::Hash;
|
|
|
|
use loader_instruction::LoaderInstruction;
|
|
|
|
use pubkey::Pubkey;
|
|
|
|
use signature::Keypair;
|
|
|
|
use transaction::Transaction;
|
2018-10-16 09:43:49 -07:00
|
|
|
|
|
|
|
pub trait LoaderTransaction {
|
2018-11-06 15:44:54 -07:00
|
|
|
fn loader_write(
|
2018-10-16 09:43:49 -07:00
|
|
|
from_keypair: &Keypair,
|
|
|
|
loader: Pubkey,
|
|
|
|
offset: u32,
|
|
|
|
bytes: Vec<u8>,
|
|
|
|
last_id: Hash,
|
2018-11-05 09:36:22 -07:00
|
|
|
fee: u64,
|
2018-10-16 09:43:49 -07:00
|
|
|
) -> Self;
|
|
|
|
|
2018-11-06 15:44:54 -07:00
|
|
|
fn loader_finalize(from_keypair: &Keypair, loader: Pubkey, last_id: Hash, fee: u64) -> Self;
|
2018-10-16 09:43:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
impl LoaderTransaction for Transaction {
|
2018-11-06 15:44:54 -07:00
|
|
|
fn loader_write(
|
2018-10-16 09:43:49 -07:00
|
|
|
from_keypair: &Keypair,
|
|
|
|
loader: Pubkey,
|
|
|
|
offset: u32,
|
|
|
|
bytes: Vec<u8>,
|
|
|
|
last_id: Hash,
|
2018-11-05 09:36:22 -07:00
|
|
|
fee: u64,
|
2018-10-16 09:43:49 -07:00
|
|
|
) -> Self {
|
|
|
|
let instruction = LoaderInstruction::Write { offset, bytes };
|
2018-11-06 06:50:00 -07:00
|
|
|
Transaction::new(from_keypair, &[], loader, &instruction, last_id, fee)
|
2018-10-16 09:43:49 -07:00
|
|
|
}
|
|
|
|
|
2018-11-06 15:44:54 -07:00
|
|
|
fn loader_finalize(from_keypair: &Keypair, loader: Pubkey, last_id: Hash, fee: u64) -> Self {
|
2018-10-16 09:43:49 -07:00
|
|
|
let instruction = LoaderInstruction::Finalize;
|
2018-11-06 06:50:00 -07:00
|
|
|
Transaction::new(from_keypair, &[], loader, &instruction, last_id, fee)
|
2018-10-16 09:43:49 -07:00
|
|
|
}
|
|
|
|
}
|