2020-01-28 16:11:22 -08:00
|
|
|
use crate::{account::Account, hash::Hash};
|
2020-04-03 17:40:59 -07:00
|
|
|
use num_derive::FromPrimitive;
|
2018-12-03 13:31:11 -08:00
|
|
|
|
2019-11-21 16:34:40 -08:00
|
|
|
crate::declare_id!("NativeLoader1111111111111111111111111111111");
|
2019-02-13 20:43:56 -07:00
|
|
|
|
2020-04-03 17:40:59 -07:00
|
|
|
#[derive(Debug, Clone, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
|
|
|
pub struct Info {
|
|
|
|
pub kind: Kind,
|
|
|
|
pub name: String,
|
|
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, Deserialize, Eq, FromPrimitive, Hash, PartialEq, Serialize)]
|
|
|
|
pub enum Kind {
|
|
|
|
Program = 1,
|
|
|
|
Loader = 2,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! native_program_info(
|
|
|
|
($name:expr) => (
|
|
|
|
$crate::native_loader::Info {
|
|
|
|
kind: $crate::native_loader::Kind::Program,
|
|
|
|
name: $name.to_string(),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! native_loader_info(
|
|
|
|
($name:expr) => (
|
|
|
|
$crate::native_loader::Info {
|
|
|
|
kind: $crate::native_loader::Kind::Loader,
|
|
|
|
name: $name.to_string(),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2019-02-13 21:16:26 -07:00
|
|
|
/// Create an executable account with the given shared object name.
|
2020-04-03 17:40:59 -07:00
|
|
|
pub fn create_loadable_account(info: &Info) -> Account {
|
|
|
|
let mut data = vec![info.kind as u8];
|
|
|
|
data.extend_from_slice(info.name.as_bytes());
|
2019-02-13 20:43:56 -07:00
|
|
|
Account {
|
2019-03-05 16:28:14 -08:00
|
|
|
lamports: 1,
|
2019-02-13 21:16:26 -07:00
|
|
|
owner: id(),
|
2020-04-03 17:40:59 -07:00
|
|
|
data,
|
2019-02-13 20:43:56 -07:00
|
|
|
executable: true,
|
2019-08-23 14:04:53 -07:00
|
|
|
rent_epoch: 0,
|
2019-09-20 13:21:12 -07:00
|
|
|
hash: Hash::default(),
|
2019-02-13 20:43:56 -07:00
|
|
|
}
|
|
|
|
}
|