Provide entire elf to bpf_loader
This commit is contained in:
@@ -6,7 +6,6 @@ use bincode::serialize;
|
|||||||
use bs58;
|
use bs58;
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use elf;
|
|
||||||
use ring::rand::SystemRandom;
|
use ring::rand::SystemRandom;
|
||||||
use ring::signature::Ed25519KeyPair;
|
use ring::signature::Ed25519KeyPair;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
@@ -21,7 +20,7 @@ use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
|||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::Write;
|
use std::io::{Read, Write};
|
||||||
use std::net::{Ipv4Addr, SocketAddr};
|
use std::net::{Ipv4Addr, SocketAddr};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@@ -29,7 +28,6 @@ use std::thread::sleep;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::{error, fmt, mem};
|
use std::{error, fmt, mem};
|
||||||
|
|
||||||
const PLATFORM_SECTION_C: &str = ".text.entrypoint";
|
|
||||||
const USERDATA_CHUNK_SIZE: usize = 256;
|
const USERDATA_CHUNK_SIZE: usize = 256;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
#[derive(Debug, PartialEq)]
|
||||||
@@ -411,23 +409,22 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
|
|||||||
}
|
}
|
||||||
|
|
||||||
let last_id = get_last_id(&rpc_client)?;
|
let last_id = get_last_id(&rpc_client)?;
|
||||||
let program = Keypair::new();
|
let program_id = Keypair::new();
|
||||||
let program_userdata = elf::File::open_path(program_location)
|
let mut file = File::open(program_location).map_err(|err| {
|
||||||
.map_err(|_| {
|
WalletError::DynamicProgramError(
|
||||||
WalletError::DynamicProgramError("Could not parse program file".to_string())
|
format!("Unable to open program file: {}", err).to_string(),
|
||||||
})?
|
)
|
||||||
.get_section(PLATFORM_SECTION_C)
|
})?;
|
||||||
.ok_or_else(|| {
|
let mut program_userdata = Vec::new();
|
||||||
WalletError::DynamicProgramError(
|
file.read_to_end(&mut program_userdata).map_err(|err| {
|
||||||
"Could not find entrypoint in program file".to_string(),
|
WalletError::DynamicProgramError(
|
||||||
)
|
format!("Unable to read program file: {}", err).to_string(),
|
||||||
})?
|
)
|
||||||
.data
|
})?;
|
||||||
.clone();
|
|
||||||
|
|
||||||
let mut tx = Transaction::system_create(
|
let mut tx = Transaction::system_create(
|
||||||
&config.id,
|
&config.id,
|
||||||
program.pubkey(),
|
program_id.pubkey(),
|
||||||
last_id,
|
last_id,
|
||||||
1,
|
1,
|
||||||
program_userdata.len() as u64,
|
program_userdata.len() as u64,
|
||||||
@@ -441,14 +438,14 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
|
|||||||
let mut offset = 0;
|
let mut offset = 0;
|
||||||
for chunk in program_userdata.chunks(USERDATA_CHUNK_SIZE) {
|
for chunk in program_userdata.chunks(USERDATA_CHUNK_SIZE) {
|
||||||
let mut tx = Transaction::loader_write(
|
let mut tx = Transaction::loader_write(
|
||||||
&program,
|
&program_id,
|
||||||
bpf_loader::id(),
|
bpf_loader::id(),
|
||||||
offset,
|
offset,
|
||||||
chunk.to_vec(),
|
chunk.to_vec(),
|
||||||
last_id,
|
last_id,
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
send_and_confirm_tx(&rpc_client, &mut tx, &program).map_err(|_| {
|
send_and_confirm_tx(&rpc_client, &mut tx, &program_id).map_err(|_| {
|
||||||
WalletError::DynamicProgramError(format!(
|
WalletError::DynamicProgramError(format!(
|
||||||
"Program write failed at offset {:?}",
|
"Program write failed at offset {:?}",
|
||||||
offset
|
offset
|
||||||
@@ -458,18 +455,18 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
|
|||||||
}
|
}
|
||||||
|
|
||||||
let last_id = get_last_id(&rpc_client)?;
|
let last_id = get_last_id(&rpc_client)?;
|
||||||
let mut tx = Transaction::loader_finalize(&program, bpf_loader::id(), last_id, 0);
|
let mut tx = Transaction::loader_finalize(&program_id, bpf_loader::id(), last_id, 0);
|
||||||
send_and_confirm_tx(&rpc_client, &mut tx, &program).map_err(|_| {
|
send_and_confirm_tx(&rpc_client, &mut tx, &program_id).map_err(|_| {
|
||||||
WalletError::DynamicProgramError("Program finalize transaction failed".to_string())
|
WalletError::DynamicProgramError("Program finalize transaction failed".to_string())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let mut tx = Transaction::system_spawn(&program, last_id, 0);
|
let mut tx = Transaction::system_spawn(&program_id, last_id, 0);
|
||||||
send_and_confirm_tx(&rpc_client, &mut tx, &program).map_err(|_| {
|
send_and_confirm_tx(&rpc_client, &mut tx, &program_id).map_err(|_| {
|
||||||
WalletError::DynamicProgramError("Program spawn failed".to_string())
|
WalletError::DynamicProgramError("Program spawn failed".to_string())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
Ok(json!({
|
Ok(json!({
|
||||||
"programId": format!("{}", program.pubkey()),
|
"programId": format!("{}", program_id.pubkey()),
|
||||||
})
|
})
|
||||||
.to_string())
|
.to_string())
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user