Remove keypairs from BankClient
Bring its interface closer to the other clients.
This commit is contained in:
@ -1,4 +1,3 @@
|
||||
use crate::bank::Bank;
|
||||
use crate::bank_client::BankClient;
|
||||
use serde::Serialize;
|
||||
use solana_sdk::instruction::{AccountMeta, Instruction};
|
||||
@ -8,8 +7,8 @@ use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_instruction::SystemInstruction;
|
||||
|
||||
pub fn load_program(
|
||||
bank: &Bank,
|
||||
from_client: &BankClient,
|
||||
bank_client: &BankClient,
|
||||
from_keypair: &Keypair,
|
||||
loader_id: &Pubkey,
|
||||
program: Vec<u8>,
|
||||
) -> Pubkey {
|
||||
@ -17,27 +16,31 @@ pub fn load_program(
|
||||
let program_pubkey = program_keypair.pubkey();
|
||||
|
||||
let instruction = SystemInstruction::new_program_account(
|
||||
&from_client.pubkey(),
|
||||
&from_keypair.pubkey(),
|
||||
&program_pubkey,
|
||||
1,
|
||||
program.len() as u64,
|
||||
loader_id,
|
||||
);
|
||||
from_client.process_instruction(instruction).unwrap();
|
||||
|
||||
let program_client = BankClient::new(bank, program_keypair);
|
||||
bank_client
|
||||
.process_instruction(&from_keypair, instruction)
|
||||
.unwrap();
|
||||
|
||||
let chunk_size = 256; // Size of chunk just needs to fit into tx
|
||||
let mut offset = 0;
|
||||
for chunk in program.chunks(chunk_size) {
|
||||
let instruction =
|
||||
LoaderInstruction::new_write(&program_pubkey, loader_id, offset, chunk.to_vec());
|
||||
program_client.process_instruction(instruction).unwrap();
|
||||
bank_client
|
||||
.process_instruction(&program_keypair, instruction)
|
||||
.unwrap();
|
||||
offset += chunk_size as u32;
|
||||
}
|
||||
|
||||
let instruction = LoaderInstruction::new_finalize(&program_pubkey, loader_id);
|
||||
program_client.process_instruction(instruction).unwrap();
|
||||
bank_client
|
||||
.process_instruction(&program_keypair, instruction)
|
||||
.unwrap();
|
||||
|
||||
program_pubkey
|
||||
}
|
||||
|
Reference in New Issue
Block a user