Use bs58 strings to declare IDs rather then raw bytes (#7082)
This commit is contained in:
@ -1,6 +1,2 @@
|
||||
pub const PROGRAM_ID: [u8; 32] = [
|
||||
2, 168, 246, 145, 78, 136, 161, 107, 189, 35, 149, 133, 95, 100, 4, 217, 180, 244, 86, 183,
|
||||
130, 27, 176, 20, 87, 73, 66, 140, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
crate::solana_name_id!(PROGRAM_ID, "BPFLoader1111111111111111111111111111111111");
|
||||
pub const BS58_STRING: &str = "BPFLoader1111111111111111111111111111111111";
|
||||
crate::declare_id!(BS58_STRING);
|
||||
|
@ -30,8 +30,7 @@ macro_rules! solana_entrypoint(
|
||||
|
||||
/// Convenience macro to declare a native program
|
||||
///
|
||||
/// id: Variable containing the program's id (public key bytes)
|
||||
/// bs58: BS58 encoding of the id, used verify check the id bytes
|
||||
/// bs58_string: bs58 string representation the program's id
|
||||
/// name: Name of the program, must match the library name in Cargo.toml
|
||||
/// entrypoint: Program's entrypoint, must be of `type Entrypoint`
|
||||
///
|
||||
@ -43,11 +42,6 @@ macro_rules! solana_entrypoint(
|
||||
/// use solana_sdk::pubkey::Pubkey;
|
||||
/// use solana_sdk::declare_program;
|
||||
///
|
||||
/// const MY_PROGRAM_ID: [u8; 32] = [
|
||||
/// 6, 161, 216, 23, 145, 55, 84, 42, 152, 52, 55, 189, 254, 42, 122, 178, 85, 127, 83, 92, 138,
|
||||
/// 120, 114, 43, 104, 164, 157, 192, 0, 0, 0, 0,
|
||||
/// ];
|
||||
///
|
||||
/// fn my_process_instruction(
|
||||
/// program_id: &Pubkey,
|
||||
/// keyed_accounts: &mut [KeyedAccount],
|
||||
@ -58,7 +52,6 @@ macro_rules! solana_entrypoint(
|
||||
/// }
|
||||
///
|
||||
/// solana_sdk::declare_program!(
|
||||
/// MY_PROGRAM_ID,
|
||||
/// "My!!!11111111111111111111111111111111111111",
|
||||
/// solana_my_program,
|
||||
/// my_process_instruction
|
||||
@ -66,8 +59,8 @@ macro_rules! solana_entrypoint(
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! declare_program(
|
||||
($id:ident, $bs58:expr, $name:ident, $entrypoint:expr) => (
|
||||
$crate::solana_name_id!($id, $bs58);
|
||||
($bs58_string:expr, $name:ident, $entrypoint:expr) => (
|
||||
$crate::declare_id!($bs58_string);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! $name {
|
||||
|
@ -51,5 +51,6 @@ pub mod transport;
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
pub extern crate bs58;
|
||||
pub extern crate lazy_static;
|
||||
extern crate log as logger;
|
||||
|
@ -1,9 +1,5 @@
|
||||
pub const PROGRAM_ID: [u8; 32] = [
|
||||
5, 84, 172, 160, 172, 5, 64, 41, 134, 4, 81, 31, 45, 11, 30, 64, 219, 238, 140, 38, 194, 100,
|
||||
192, 219, 156, 94, 62, 208, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
crate::solana_name_id!(PROGRAM_ID, "MoveLdr111111111111111111111111111111111111");
|
||||
pub const BS58_STRING: &str = "MoveLdr111111111111111111111111111111111111";
|
||||
crate::declare_id!(BS58_STRING);
|
||||
|
||||
pub fn solana_move_loader_program() -> (String, crate::pubkey::Pubkey) {
|
||||
("solana_move_loader_program".to_string(), id())
|
||||
|
@ -1,12 +1,7 @@
|
||||
use crate::account::Account;
|
||||
use crate::hash::Hash;
|
||||
|
||||
const ID: [u8; 32] = [
|
||||
5, 135, 132, 191, 20, 139, 164, 40, 47, 176, 18, 87, 72, 136, 169, 241, 83, 160, 125, 173, 247,
|
||||
101, 192, 69, 92, 154, 151, 3, 128, 0, 0, 0,
|
||||
];
|
||||
|
||||
crate::solana_name_id!(ID, "NativeLoader1111111111111111111111111111111");
|
||||
crate::declare_id!("NativeLoader1111111111111111111111111111111");
|
||||
|
||||
/// Create an executable account with the given shared object name.
|
||||
pub fn create_loadable_account(name: &str) -> Account {
|
||||
|
@ -104,16 +104,52 @@ pub fn read_pubkey_file(infile: &str) -> Result<Pubkey, Box<dyn error::Error>> {
|
||||
Ok(Pubkey::from_str(&printable)?)
|
||||
}
|
||||
|
||||
/// Convenience macro to declare a static Pubkey and functions to interact with it
|
||||
///
|
||||
/// bs58_string: bs58 string representation the program's id
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// solana_sdk::declare_id!("My!!!11111111111111111111111111111111111111");
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! solana_id(
|
||||
($id:ident) => (
|
||||
macro_rules!
|
||||
declare_id(
|
||||
($bs58_string:expr) => (
|
||||
use std::str::FromStr;
|
||||
|
||||
$crate::lazy_static::lazy_static! {
|
||||
static ref _PUBKEY: $crate::pubkey::Pubkey = {
|
||||
match $crate::pubkey::Pubkey::from_str(&$bs58_string) {
|
||||
Ok(pubkey) => pubkey,
|
||||
Err(_) => {
|
||||
let pubkey_vec = $crate::bs58::decode(&$bs58_string)
|
||||
.into_vec()
|
||||
.map_err(|e| panic!("Error: {}, {}", $bs58_string, e))
|
||||
.unwrap();
|
||||
let expected_len = std::mem::size_of::<$crate::pubkey::Pubkey>();
|
||||
let len = pubkey_vec.len();
|
||||
if len != expected_len {
|
||||
panic!(
|
||||
"Error: {}, decoded length {}, expected {}",
|
||||
$bs58_string, len, expected_len);
|
||||
} else {
|
||||
panic!(
|
||||
"Error: {}, not a valid string, cannot determine reason",
|
||||
$bs58_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub fn check_id(id: &$crate::pubkey::Pubkey) -> bool {
|
||||
id.as_ref() == $id
|
||||
*id == *_PUBKEY
|
||||
}
|
||||
|
||||
pub fn id() -> $crate::pubkey::Pubkey {
|
||||
$crate::pubkey::Pubkey::new(&$id)
|
||||
*_PUBKEY
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -121,23 +157,6 @@ macro_rules! solana_id(
|
||||
fn test_id() {
|
||||
assert!(check_id(&id()));
|
||||
}
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! solana_name_id(
|
||||
($id:ident, $name:expr) => (
|
||||
|
||||
$crate::solana_id!($id);
|
||||
|
||||
#[cfg(test)]
|
||||
#[test]
|
||||
fn test_name_id() {
|
||||
if id().to_string() != $name {
|
||||
panic!("id for `{}` should be `{:?}`", $name, $crate::pubkey::bs58::decode($name).into_vec().unwrap());
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -1,8 +1,4 @@
|
||||
const ID: [u8; 32] = [
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
crate::solana_name_id!(ID, "11111111111111111111111111111111");
|
||||
crate::declare_id!("11111111111111111111111111111111");
|
||||
|
||||
pub fn solana_system_program() -> (String, crate::pubkey::Pubkey) {
|
||||
("solana_system_program".to_string(), id())
|
||||
|
@ -8,12 +8,7 @@ use crate::{
|
||||
sysvar::Sysvar,
|
||||
};
|
||||
|
||||
const ID: [u8; 32] = [
|
||||
6, 167, 213, 23, 24, 199, 116, 201, 40, 86, 99, 152, 105, 29, 94, 182, 139, 94, 184, 163, 155,
|
||||
75, 109, 92, 115, 85, 91, 33, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
crate::solana_sysvar_id!(ID, "SysvarC1ock11111111111111111111111111111111", Clock);
|
||||
crate::declare_sysvar_id!("SysvarC1ock11111111111111111111111111111111", Clock);
|
||||
|
||||
impl Sysvar for Clock {}
|
||||
|
||||
|
@ -3,17 +3,7 @@
|
||||
pub use crate::epoch_schedule::EpochSchedule;
|
||||
use crate::{account::Account, sysvar::Sysvar};
|
||||
|
||||
/// epoch_schedule account pubkey
|
||||
const ID: [u8; 32] = [
|
||||
6, 167, 213, 23, 24, 220, 63, 238, 2, 211, 228, 127, 1, 0, 248, 176, 84, 247, 148, 46, 96, 89,
|
||||
30, 63, 80, 135, 25, 168, 5, 0, 0, 0,
|
||||
];
|
||||
|
||||
crate::solana_sysvar_id!(
|
||||
ID,
|
||||
"SysvarEpochSchedu1e111111111111111111111111",
|
||||
EpochSchedule
|
||||
);
|
||||
crate::declare_sysvar_id!("SysvarEpochSchedu1e111111111111111111111111", EpochSchedule);
|
||||
|
||||
impl Sysvar for EpochSchedule {}
|
||||
|
||||
|
@ -2,13 +2,7 @@
|
||||
//!
|
||||
use crate::{account::Account, fee_calculator::FeeCalculator, sysvar::Sysvar};
|
||||
|
||||
/// fees account pubkey
|
||||
const ID: [u8; 32] = [
|
||||
6, 167, 213, 23, 24, 226, 90, 141, 131, 80, 60, 37, 26, 122, 240, 113, 38, 253, 114, 0, 223,
|
||||
111, 196, 237, 82, 106, 156, 144, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
crate::solana_sysvar_id!(ID, "SysvarFees111111111111111111111111111111111", Fees);
|
||||
crate::declare_sysvar_id!("SysvarFees111111111111111111111111111111111", Fees);
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Serialize, Deserialize, Debug, Default)]
|
||||
|
@ -28,9 +28,9 @@ pub fn is_sysvar_id(id: &Pubkey) -> bool {
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! solana_sysvar_id(
|
||||
($id:ident, $name:expr, $type:ty) => (
|
||||
$crate::solana_name_id!($id, $name);
|
||||
macro_rules! declare_sysvar_id(
|
||||
($name:expr, $type:ty) => (
|
||||
$crate::declare_id!($name);
|
||||
|
||||
impl $crate::sysvar::SysvarId for $type {
|
||||
fn check_id(pubkey: &$crate::pubkey::Pubkey) -> bool {
|
||||
@ -48,14 +48,8 @@ macro_rules! solana_sysvar_id(
|
||||
)
|
||||
);
|
||||
|
||||
/// "Sysvar1111111111111111111111111111111111111"
|
||||
/// owner pubkey for sysvar accounts
|
||||
const ID: [u8; 32] = [
|
||||
6, 167, 213, 23, 24, 117, 247, 41, 199, 61, 147, 64, 143, 33, 97, 32, 6, 126, 216, 140, 118,
|
||||
224, 140, 40, 127, 193, 148, 96, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
crate::solana_name_id!(ID, "Sysvar1111111111111111111111111111111111111");
|
||||
// owner pubkey for sysvar accounts
|
||||
crate::declare_id!("Sysvar1111111111111111111111111111111111111");
|
||||
|
||||
pub trait SysvarId {
|
||||
fn check_id(pubkey: &Pubkey) -> bool;
|
||||
|
@ -4,13 +4,8 @@ use std::iter::FromIterator;
|
||||
use std::ops::Deref;
|
||||
|
||||
const MAX_ENTRIES: usize = 32;
|
||||
const ID: [u8; 32] = [
|
||||
0x06, 0xa7, 0xd5, 0x17, 0x19, 0x2c, 0x56, 0x8e, 0xe0, 0x8a, 0x84, 0x5f, 0x73, 0xd2, 0x97, 0x88,
|
||||
0xcf, 0x03, 0x5c, 0x31, 0x45, 0xb2, 0x1a, 0xb3, 0x44, 0xd8, 0x06, 0x2e, 0xa9, 0x40, 0x00, 0x00,
|
||||
];
|
||||
|
||||
crate::solana_sysvar_id!(
|
||||
ID,
|
||||
crate::declare_sysvar_id!(
|
||||
"SysvarRecentB1ockHashes11111111111111111111",
|
||||
RecentBlockhashes
|
||||
);
|
||||
|
@ -8,13 +8,7 @@ use crate::{
|
||||
sysvar::Sysvar,
|
||||
};
|
||||
|
||||
/// rent account pubkey
|
||||
const ID: [u8; 32] = [
|
||||
6, 167, 213, 23, 25, 44, 92, 81, 33, 140, 201, 76, 61, 74, 241, 127, 88, 218, 238, 8, 155, 161,
|
||||
253, 68, 227, 219, 217, 138, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
crate::solana_sysvar_id!(ID, "SysvarRent111111111111111111111111111111111", Rent);
|
||||
crate::declare_sysvar_id!("SysvarRent111111111111111111111111111111111", Rent);
|
||||
|
||||
impl Sysvar for Rent {}
|
||||
|
||||
|
@ -2,13 +2,7 @@
|
||||
//!
|
||||
use crate::{account::Account, sysvar::Sysvar};
|
||||
|
||||
/// account pubkey
|
||||
const ID: [u8; 32] = [
|
||||
6, 167, 213, 23, 25, 44, 97, 55, 206, 224, 146, 217, 182, 146, 62, 225, 204, 214, 25, 3, 250,
|
||||
130, 184, 161, 97, 145, 87, 141, 128, 0, 0, 0,
|
||||
];
|
||||
|
||||
crate::solana_sysvar_id!(ID, "SysvarRewards111111111111111111111111111111", Rewards);
|
||||
crate::declare_sysvar_id!("SysvarRewards111111111111111111111111111111", Rewards);
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
|
||||
|
@ -5,16 +5,7 @@
|
||||
pub use crate::slot_hashes::{SlotHash, SlotHashes};
|
||||
use crate::{account::Account, sysvar::Sysvar};
|
||||
|
||||
const ID: [u8; 32] = [
|
||||
6, 167, 213, 23, 25, 47, 10, 175, 198, 242, 101, 227, 251, 119, 204, 122, 218, 130, 197, 41,
|
||||
208, 190, 59, 19, 110, 45, 0, 85, 32, 0, 0, 0,
|
||||
];
|
||||
|
||||
crate::solana_sysvar_id!(
|
||||
ID,
|
||||
"SysvarS1otHashes111111111111111111111111111",
|
||||
SlotHashes
|
||||
);
|
||||
crate::declare_sysvar_id!("SysvarS1otHashes111111111111111111111111111", SlotHashes);
|
||||
|
||||
pub const MAX_SLOT_HASHES: usize = 512; // 512 slots to get your vote in
|
||||
|
||||
|
@ -7,16 +7,7 @@ pub use crate::clock::Epoch;
|
||||
use crate::{account::Account, sysvar::Sysvar};
|
||||
use std::ops::Deref;
|
||||
|
||||
const ID: [u8; 32] = [
|
||||
6, 167, 213, 23, 25, 53, 132, 208, 254, 237, 155, 179, 67, 29, 19, 32, 107, 229, 68, 40, 27,
|
||||
87, 184, 86, 108, 197, 55, 95, 244, 0, 0, 0,
|
||||
];
|
||||
|
||||
crate::solana_sysvar_id!(
|
||||
ID,
|
||||
"SysvarStakeHistory1111111111111111111111111",
|
||||
StakeHistory
|
||||
);
|
||||
crate::declare_sysvar_id!("SysvarStakeHistory1111111111111111111111111", StakeHistory);
|
||||
|
||||
pub const MAX_STAKE_HISTORY: usize = 512; // it should never take as many as 512 epochs to warm up or cool down
|
||||
|
||||
|
Reference in New Issue
Block a user