Merge native programs parts into one unit (#7047)
This commit is contained in:
@ -9,8 +9,10 @@ homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
bincode = "1.2.0"
|
||||
log = "0.4.8"
|
||||
solana-config-api = { path = "../config_api", version = "0.21.0" }
|
||||
serde = "1.0.102"
|
||||
serde_derive = "1.0.102"
|
||||
solana-logger = { path = "../../logger", version = "0.21.0" }
|
||||
solana-sdk = { path = "../../sdk", version = "0.21.0" }
|
||||
|
@ -29,7 +29,7 @@ pub fn process_instruction(
|
||||
.collect();
|
||||
|
||||
if current_signer_keys.is_empty() {
|
||||
// Config account keypair must be a signer on account initilization,
|
||||
// Config account keypair must be a signer on account initialization,
|
||||
// or when no signers specified in Config data
|
||||
if config_keyed_account.signer_key().is_none() {
|
||||
error!("account[0].signer_key().is_none()");
|
@ -1,18 +1,21 @@
|
||||
pub mod config_instruction;
|
||||
pub mod config_processor;
|
||||
|
||||
use crate::config_processor::process_instruction;
|
||||
use bincode::{deserialize, serialize, serialized_size};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_sdk::{account::Account, pubkey::Pubkey, short_vec};
|
||||
|
||||
pub mod config_instruction;
|
||||
pub mod config_processor;
|
||||
|
||||
const CONFIG_PROGRAM_ID: [u8; 32] = [
|
||||
3, 6, 74, 163, 0, 47, 116, 220, 200, 110, 67, 49, 15, 12, 5, 42, 248, 197, 218, 39, 246, 16,
|
||||
64, 25, 163, 35, 239, 160, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
solana_sdk::solana_name_id!(
|
||||
solana_sdk::declare_program!(
|
||||
CONFIG_PROGRAM_ID,
|
||||
"Config1111111111111111111111111111111111111"
|
||||
"Config1111111111111111111111111111111111111",
|
||||
solana_config_program,
|
||||
process_instruction
|
||||
);
|
||||
|
||||
pub trait ConfigState: serde::Serialize + Default {
|
@ -1,21 +0,0 @@
|
||||
[package]
|
||||
name = "solana-config-api"
|
||||
version = "0.21.0"
|
||||
description = "config program API"
|
||||
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
license = "Apache-2.0"
|
||||
homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
bincode = "1.2.0"
|
||||
log = "0.4.8"
|
||||
serde = "1.0.102"
|
||||
serde_derive = "1.0.102"
|
||||
solana-sdk = { path = "../../sdk", version = "0.21.0" }
|
||||
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib"]
|
||||
name = "solana_config_api"
|
@ -1,9 +0,0 @@
|
||||
#[macro_export]
|
||||
macro_rules! solana_config_program {
|
||||
() => {
|
||||
("solana_config_program".to_string(), solana_config_api::id())
|
||||
};
|
||||
}
|
||||
use solana_config_api::config_processor::process_instruction;
|
||||
|
||||
solana_sdk::solana_entrypoint!(process_instruction);
|
@ -15,8 +15,7 @@ serde = "1.0.102"
|
||||
serde_derive = "1.0.102"
|
||||
solana-logger = { path = "../../logger", version = "0.21.0" }
|
||||
solana-sdk = { path = "../../sdk", version = "0.21.0" }
|
||||
solana-config-api = { path = "../config_api", version = "0.21.0" }
|
||||
solana-config-program = { path = "../config_program", version = "0.21.0" }
|
||||
solana-config-program = { path = "../config", version = "0.21.0" }
|
||||
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use bincode::{deserialize, serialized_size};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_config_api::{
|
||||
use solana_config_program::{
|
||||
config_instruction, config_processor::process_instruction, get_config_data, id, ConfigKeys,
|
||||
ConfigState,
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "solana-stake-api"
|
||||
name = "solana-stake-program"
|
||||
version = "0.21.0"
|
||||
description = "Solana Stake program API"
|
||||
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||
@ -19,9 +19,9 @@ serde_derive = "1.0.102"
|
||||
solana-logger = { path = "../../logger", version = "0.21.0" }
|
||||
solana-metrics = { path = "../../metrics", version = "0.21.0" }
|
||||
solana-sdk = { path = "../../sdk", version = "0.21.0" }
|
||||
solana-vote-api = { path = "../vote_api", version = "0.21.0" }
|
||||
solana-config-api = { path = "../config_api", version = "0.21.0" }
|
||||
solana-vote-program = { path = "../vote", version = "0.21.0" }
|
||||
solana-config-program = { path = "../config", version = "0.21.0" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib"]
|
||||
name = "solana_stake_api"
|
||||
crate-type = ["lib", "cdylib"]
|
||||
name = "solana_stake_program"
|
@ -2,7 +2,7 @@
|
||||
//! carries variables that the stake program cares about
|
||||
use bincode::{deserialize, serialized_size};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_config_api::{create_config_account, get_config_data, ConfigState};
|
||||
use solana_config_program::{create_config_account, get_config_data, ConfigState};
|
||||
use solana_sdk::{
|
||||
account::{Account, KeyedAccount},
|
||||
instruction::InstructionError,
|
@ -1,5 +1,6 @@
|
||||
use crate::config::create_genesis_account;
|
||||
use crate::rewards_pools::create_rewards_accounts;
|
||||
use crate::stake_instruction::process_instruction;
|
||||
use solana_sdk::genesis_config::GenesisConfig;
|
||||
|
||||
pub mod config;
|
||||
@ -12,9 +13,11 @@ const STAKE_PROGRAM_ID: [u8; 32] = [
|
||||
120, 114, 43, 104, 164, 157, 192, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
solana_sdk::solana_name_id!(
|
||||
solana_sdk::declare_program!(
|
||||
STAKE_PROGRAM_ID,
|
||||
"Stake11111111111111111111111111111111111111"
|
||||
"Stake11111111111111111111111111111111111111",
|
||||
solana_stake_program,
|
||||
process_instruction
|
||||
);
|
||||
|
||||
pub fn add_genesis_accounts(genesis_config: &mut GenesisConfig) {
|
@ -17,7 +17,7 @@ use solana_sdk::{
|
||||
stake_history::{StakeHistory, StakeHistoryEntry},
|
||||
},
|
||||
};
|
||||
use solana_vote_api::vote_state::VoteState;
|
||||
use solana_vote_program::vote_state::VoteState;
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Copy)]
|
||||
@ -804,7 +804,7 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::id;
|
||||
use solana_sdk::{account::Account, pubkey::Pubkey, system_program};
|
||||
use solana_vote_api::vote_state;
|
||||
use solana_vote_program::vote_state;
|
||||
|
||||
#[test]
|
||||
fn test_stake_state_stake_from_fail() {
|
@ -1,19 +0,0 @@
|
||||
[package]
|
||||
name = "solana-stake-program"
|
||||
version = "0.21.0"
|
||||
description = "Solana stake program"
|
||||
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
license = "Apache-2.0"
|
||||
homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
log = "0.4.8"
|
||||
solana-logger = { path = "../../logger", version = "0.21.0" }
|
||||
solana-sdk = { path = "../../sdk", version = "0.21.0" }
|
||||
solana-stake-api = { path = "../stake_api", version = "0.21.0" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib", "cdylib"]
|
||||
name = "solana_stake_program"
|
@ -1,9 +0,0 @@
|
||||
#[macro_export]
|
||||
macro_rules! solana_stake_program {
|
||||
() => {
|
||||
("solana_stake_program".to_string(), solana_stake_api::id())
|
||||
};
|
||||
}
|
||||
|
||||
use solana_stake_api::stake_instruction::process_instruction;
|
||||
solana_sdk::solana_entrypoint!(process_instruction);
|
@ -12,9 +12,8 @@ edition = "2018"
|
||||
log = "0.4.8"
|
||||
solana-logger = { path = "../../logger", version = "0.21.0" }
|
||||
solana-sdk = { path = "../../sdk", version = "0.21.0" }
|
||||
solana-stake-api = { path = "../stake_api", version = "0.21.0" }
|
||||
solana-stake-program = { path = "../stake_program", version = "0.21.0" }
|
||||
solana-vote-api = { path = "../vote_api", version = "0.21.0" }
|
||||
solana-stake-program = { path = "../stake", version = "0.21.0" }
|
||||
solana-vote-program = { path = "../vote", version = "0.21.0" }
|
||||
|
||||
[dev-dependencies]
|
||||
solana-runtime = { path = "../../runtime", version = "0.21.0" }
|
||||
|
@ -12,11 +12,11 @@ use solana_sdk::{
|
||||
signature::{Keypair, KeypairUtil},
|
||||
sysvar::{self, rewards::Rewards, stake_history::StakeHistory, Sysvar},
|
||||
};
|
||||
use solana_stake_api::{
|
||||
use solana_stake_program::{
|
||||
stake_instruction::{self},
|
||||
stake_state::{self, StakeState},
|
||||
};
|
||||
use solana_vote_api::{
|
||||
use solana_vote_program::{
|
||||
vote_instruction,
|
||||
vote_state::{Vote, VoteInit, VoteState},
|
||||
};
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "solana-vest-api"
|
||||
name = "solana-vest-program"
|
||||
version = "0.21.0"
|
||||
description = "Solana Vest program API"
|
||||
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||
@ -17,11 +17,11 @@ num-traits = "0.2"
|
||||
serde = "1.0.102"
|
||||
serde_derive = "1.0.102"
|
||||
solana-sdk = { path = "../../sdk", version = "0.21.0" }
|
||||
solana-config-api = { path = "../config_api", version = "0.21.0" }
|
||||
solana-config-program = { path = "../config", version = "0.21.0" }
|
||||
|
||||
[dev-dependencies]
|
||||
solana-runtime = { path = "../../runtime", version = "0.21.0" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib"]
|
||||
name = "solana_vest_api"
|
||||
name = "solana_vest_program"
|
@ -7,7 +7,7 @@ use chrono::{
|
||||
serde::ts_seconds,
|
||||
};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use solana_config_api::{config_instruction, ConfigState};
|
||||
use solana_config_program::{config_instruction, ConfigState};
|
||||
use solana_sdk::{instruction::Instruction, pubkey::Pubkey};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
@ -4,12 +4,16 @@ pub mod vest_processor;
|
||||
pub mod vest_schedule;
|
||||
pub mod vest_state;
|
||||
|
||||
use crate::vest_processor::process_instruction;
|
||||
|
||||
const VEST_PROGRAM_ID: [u8; 32] = [
|
||||
7, 87, 23, 47, 219, 236, 238, 33, 137, 188, 215, 141, 32, 229, 155, 195, 133, 124, 23, 232,
|
||||
113, 153, 252, 252, 111, 5, 187, 128, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
solana_sdk::solana_name_id!(
|
||||
solana_sdk::declare_program!(
|
||||
VEST_PROGRAM_ID,
|
||||
"Vest111111111111111111111111111111111111111"
|
||||
"Vest111111111111111111111111111111111111111",
|
||||
solana_vest_program,
|
||||
process_instruction
|
||||
);
|
@ -5,7 +5,7 @@ use crate::{
|
||||
vest_state::VestState,
|
||||
};
|
||||
use chrono::prelude::*;
|
||||
use solana_config_api::get_config_data;
|
||||
use solana_config_program::get_config_data;
|
||||
use solana_sdk::{
|
||||
account::{Account, KeyedAccount},
|
||||
instruction::InstructionError,
|
||||
@ -17,7 +17,7 @@ fn verify_date_account(
|
||||
keyed_account: &mut KeyedAccount,
|
||||
expected_pubkey: &Pubkey,
|
||||
) -> Result<Date<Utc>, InstructionError> {
|
||||
if keyed_account.account.owner != solana_config_api::id() {
|
||||
if keyed_account.account.owner != solana_config_program::id() {
|
||||
return Err(InstructionError::IncorrectProgramId);
|
||||
}
|
||||
|
||||
@ -149,8 +149,8 @@ mod tests {
|
||||
let (genesis_config, mint_keypair) = create_genesis_config(lamports);
|
||||
let mut bank = Bank::new(&genesis_config);
|
||||
bank.add_instruction_processor(
|
||||
solana_config_api::id(),
|
||||
solana_config_api::config_processor::process_instruction,
|
||||
solana_config_program::id(),
|
||||
solana_config_program::config_processor::process_instruction,
|
||||
);
|
||||
bank.add_instruction_processor(id(), process_instruction);
|
||||
(bank, mint_keypair)
|
||||
@ -252,7 +252,7 @@ mod tests {
|
||||
fn test_verify_account_unauthorized() {
|
||||
// Ensure client can't sneak in with an untrusted date account.
|
||||
let date_pubkey = Pubkey::new_rand();
|
||||
let mut account = Account::new(1, 0, &solana_config_api::id());
|
||||
let mut account = Account::new(1, 0, &solana_config_program::id());
|
||||
let mut keyed_account = KeyedAccount::new(&date_pubkey, false, &mut account);
|
||||
|
||||
let mallory_pubkey = Pubkey::new_rand(); // <-- Attack! Not the expected account.
|
||||
@ -266,7 +266,7 @@ mod tests {
|
||||
fn test_verify_signed_account_missing_signature() {
|
||||
// Ensure client can't sneak in with an unsigned account.
|
||||
let date_pubkey = Pubkey::new_rand();
|
||||
let mut account = Account::new(1, 0, &solana_config_api::id());
|
||||
let mut account = Account::new(1, 0, &solana_config_program::id());
|
||||
let mut keyed_account = KeyedAccount::new(&date_pubkey, false, &mut account); // <-- Attack! Unsigned transaction.
|
||||
|
||||
assert_eq!(
|
||||
@ -291,7 +291,7 @@ mod tests {
|
||||
fn test_verify_date_account_uninitialized_config() {
|
||||
// Ensure no panic when `get_config_data()` returns an error.
|
||||
let date_pubkey = Pubkey::new_rand();
|
||||
let mut account = Account::new(1, 0, &solana_config_api::id()); // <-- Attack! Zero space.
|
||||
let mut account = Account::new(1, 0, &solana_config_program::id()); // <-- Attack! Zero space.
|
||||
let mut keyed_account = KeyedAccount::new(&date_pubkey, false, &mut account);
|
||||
assert_eq!(
|
||||
verify_date_account(&mut keyed_account, &date_pubkey).unwrap_err(),
|
||||
@ -303,7 +303,7 @@ mod tests {
|
||||
fn test_verify_date_account_invalid_date_config() {
|
||||
// Ensure no panic when `deserialize::<DateConfig>()` returns an error.
|
||||
let date_pubkey = Pubkey::new_rand();
|
||||
let mut account = Account::new(1, 1, &solana_config_api::id()); // Attack! 1 byte, enough to sneak by `get_config_data()`, but not DateConfig deserialize.
|
||||
let mut account = Account::new(1, 1, &solana_config_program::id()); // Attack! 1 byte, enough to sneak by `get_config_data()`, but not DateConfig deserialize.
|
||||
let mut keyed_account = KeyedAccount::new(&date_pubkey, false, &mut account);
|
||||
assert_eq!(
|
||||
verify_date_account(&mut keyed_account, &date_pubkey).unwrap_err(),
|
||||
@ -315,7 +315,7 @@ mod tests {
|
||||
fn test_verify_date_account_deserialize() {
|
||||
// Ensure no panic when `deserialize::<DateConfig>()` returns an error.
|
||||
let date_pubkey = Pubkey::new_rand();
|
||||
let mut account = Account::new(1, 1, &solana_config_api::id()); // Attack! 1 byte, enough to sneak by `get_config_data()`, but not DateConfig deserialize.
|
||||
let mut account = Account::new(1, 1, &solana_config_program::id()); // Attack! 1 byte, enough to sneak by `get_config_data()`, but not DateConfig deserialize.
|
||||
let mut keyed_account = KeyedAccount::new(&date_pubkey, false, &mut account);
|
||||
assert_eq!(
|
||||
verify_date_account(&mut keyed_account, &date_pubkey).unwrap_err(),
|
@ -1,19 +0,0 @@
|
||||
[package]
|
||||
name = "solana-vest-program"
|
||||
version = "0.21.0"
|
||||
description = "Solana Vest program"
|
||||
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
license = "Apache-2.0"
|
||||
homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
log = "0.4.8"
|
||||
solana-logger = { path = "../../logger", version = "0.21.0" }
|
||||
solana-sdk = { path = "../../sdk", version = "0.21.0" }
|
||||
solana-vest-api = { path = "../vest_api", version = "0.21.0" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib", "cdylib"]
|
||||
name = "solana_vest_program"
|
@ -1,9 +0,0 @@
|
||||
#[macro_export]
|
||||
macro_rules! solana_vest_program {
|
||||
() => {
|
||||
("solana_vest_program".to_string(), solana_vest_api::id())
|
||||
};
|
||||
}
|
||||
|
||||
use solana_vest_api::vest_processor::process_instruction;
|
||||
solana_sdk::solana_entrypoint!(process_instruction);
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "solana-vote-api"
|
||||
name = "solana-vote-program"
|
||||
version = "0.21.0"
|
||||
description = "Solana Vote program API"
|
||||
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||
@ -20,5 +20,5 @@ solana-metrics = { path = "../../metrics", version = "0.21.0" }
|
||||
solana-sdk = { path = "../../sdk", version = "0.21.0" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib"]
|
||||
name = "solana_vote_api"
|
||||
crate-type = ["lib", "cdylib"]
|
||||
name = "solana_vote_program"
|
@ -1,12 +1,16 @@
|
||||
pub mod vote_instruction;
|
||||
pub mod vote_state;
|
||||
|
||||
use crate::vote_instruction::process_instruction;
|
||||
|
||||
const VOTE_PROGRAM_ID: [u8; 32] = [
|
||||
7, 97, 72, 29, 53, 116, 116, 187, 124, 77, 118, 36, 235, 211, 189, 179, 216, 53, 94, 115, 209,
|
||||
16, 67, 252, 13, 163, 83, 128, 0, 0, 0, 0,
|
||||
];
|
||||
|
||||
solana_sdk::solana_name_id!(
|
||||
solana_sdk::declare_program!(
|
||||
VOTE_PROGRAM_ID,
|
||||
"Vote111111111111111111111111111111111111111"
|
||||
"Vote111111111111111111111111111111111111111",
|
||||
solana_vote_program,
|
||||
process_instruction
|
||||
);
|
@ -1,19 +0,0 @@
|
||||
[package]
|
||||
name = "solana-vote-program"
|
||||
version = "0.21.0"
|
||||
description = "Solana Vote program"
|
||||
authors = ["Solana Maintainers <maintainers@solana.com>"]
|
||||
repository = "https://github.com/solana-labs/solana"
|
||||
license = "Apache-2.0"
|
||||
homepage = "https://solana.com/"
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
log = "0.4.8"
|
||||
solana-logger = { path = "../../logger", version = "0.21.0" }
|
||||
solana-sdk = { path = "../../sdk", version = "0.21.0" }
|
||||
solana-vote-api = { path = "../vote_api", version = "0.21.0" }
|
||||
|
||||
[lib]
|
||||
crate-type = ["lib", "cdylib"]
|
||||
name = "solana_vote_program"
|
@ -1,9 +0,0 @@
|
||||
#[macro_export]
|
||||
macro_rules! solana_vote_program {
|
||||
() => {
|
||||
("solana_vote_program".to_string(), solana_vote_api::id())
|
||||
};
|
||||
}
|
||||
|
||||
use solana_vote_api::vote_instruction::process_instruction;
|
||||
solana_sdk::solana_entrypoint!(process_instruction);
|
Reference in New Issue
Block a user