Refactor stake program into solana_program (#17906)

* Move stake state / instructions into solana_program

* Update account-decoder

* Update cli and runtime

* Update all other parts

* Commit Cargo.lock changes in programs/bpf

* Update cli stake instruction import

* Allow integer arithmetic

* Update ABI digest

* Bump rust mem instruction count

* Remove useless structs

* Move stake::id() -> stake::program::id()

* Re-export from solana_sdk and mark deprecated

* Address feedback

* Run cargo fmt
This commit is contained in:
Jon Cinque
2021-06-15 18:04:00 +02:00
committed by GitHub
parent 36b09db2d1
commit 1b1d34da59
59 changed files with 1765 additions and 1711 deletions

View File

@@ -36,6 +36,11 @@ use solana_sdk::{
feature, feature_set,
message::Message,
pubkey::Pubkey,
stake::{
self,
instruction::{self as stake_instruction, LockupArgs, StakeError},
state::{Authorized, Lockup, Meta, StakeAuthorize, StakeState},
},
system_instruction::SystemError,
sysvar::{
clock,
@@ -43,10 +48,6 @@ use solana_sdk::{
},
transaction::Transaction,
};
use solana_stake_program::{
stake_instruction::{self, LockupArgs, StakeError},
stake_state::{Authorized, Lockup, Meta, StakeAuthorize, StakeState},
};
use solana_vote_program::vote_state::VoteState;
use std::{ops::Deref, sync::Arc};
@@ -971,7 +972,7 @@ pub fn process_create_stake_account(
) -> ProcessResult {
let stake_account = config.signers[stake_account];
let stake_account_address = if let Some(seed) = seed {
Pubkey::create_with_seed(&stake_account.pubkey(), &seed, &solana_stake_program::id())?
Pubkey::create_with_seed(&stake_account.pubkey(), &seed, &stake::program::id())?
} else {
stake_account.pubkey()
};
@@ -1039,7 +1040,7 @@ pub fn process_create_stake_account(
if !sign_only {
if let Ok(stake_account) = rpc_client.get_account(&stake_account_address) {
let err_msg = if stake_account.owner == solana_stake_program::id() {
let err_msg = if stake_account.owner == stake::program::id() {
format!("Stake account {} already exists", stake_account_address)
} else {
format!(
@@ -1195,7 +1196,7 @@ pub fn process_deactivate_stake_account(
let stake_authority = config.signers[stake_authority];
let stake_account_address = if let Some(seed) = seed {
Pubkey::create_with_seed(&stake_account_pubkey, seed, &solana_stake_program::id())?
Pubkey::create_with_seed(&stake_account_pubkey, seed, &stake::program::id())?
} else {
*stake_account_pubkey
};
@@ -1273,7 +1274,7 @@ pub fn process_withdraw_stake(
let custodian = custodian.map(|index| config.signers[index]);
let stake_account_address = if let Some(seed) = seed {
Pubkey::create_with_seed(&stake_account_pubkey, seed, &solana_stake_program::id())?
Pubkey::create_with_seed(&stake_account_pubkey, seed, &stake::program::id())?
} else {
*stake_account_pubkey
};
@@ -1394,18 +1395,14 @@ pub fn process_split_stake(
let stake_authority = config.signers[stake_authority];
let split_stake_account_address = if let Some(seed) = split_stake_account_seed {
Pubkey::create_with_seed(
&split_stake_account.pubkey(),
&seed,
&solana_stake_program::id(),
)?
Pubkey::create_with_seed(&split_stake_account.pubkey(), &seed, &stake::program::id())?
} else {
split_stake_account.pubkey()
};
if !sign_only {
if let Ok(stake_account) = rpc_client.get_account(&split_stake_account_address) {
let err_msg = if stake_account.owner == solana_stake_program::id() {
let err_msg = if stake_account.owner == stake::program::id() {
format!(
"Stake account {} already exists",
split_stake_account_address
@@ -1540,7 +1537,7 @@ pub fn process_merge_stake(
if !sign_only {
for stake_account_address in &[stake_account_pubkey, source_stake_account_pubkey] {
if let Ok(stake_account) = rpc_client.get_account(stake_account_address) {
if stake_account.owner != solana_stake_program::id() {
if stake_account.owner != stake::program::id() {
return Err(CliError::BadParameter(format!(
"Account {} is not a stake account",
stake_account_address
@@ -1876,7 +1873,7 @@ pub fn process_show_stake_account(
with_rewards: Option<usize>,
) -> ProcessResult {
let stake_account = rpc_client.get_account(stake_account_address)?;
if stake_account.owner != solana_stake_program::id() {
if stake_account.owner != stake::program::id() {
return Err(CliError::RpcRequestError(format!(
"{:?} is not a stake account",
stake_account_address,