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:
@@ -21,7 +21,6 @@ serde_json = "1.0.64"
|
||||
solana-account-decoder = { path = "../account-decoder", version = "=1.8.0" }
|
||||
solana-sdk = { path = "../sdk", version = "=1.8.0" }
|
||||
solana-runtime = { path = "../runtime", version = "=1.8.0" }
|
||||
solana-stake-program = { path = "../programs/stake", version = "=1.8.0" }
|
||||
solana-vote-program = { path = "../programs/vote", version = "=1.8.0" }
|
||||
spl-associated-token-account-v1-0 = { package = "spl-associated-token-account", version = "=1.0.2", features = ["no-entrypoint"] }
|
||||
spl-memo = { version = "=3.0.1", features = ["no-entrypoint"] }
|
||||
|
@@ -9,7 +9,7 @@ use crate::{
|
||||
use inflector::Inflector;
|
||||
use serde_json::Value;
|
||||
use solana_account_decoder::parse_token::spl_token_id_v2_0;
|
||||
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, system_program};
|
||||
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey, stake, system_program};
|
||||
use std::{collections::HashMap, str::from_utf8};
|
||||
use thiserror::Error;
|
||||
|
||||
@@ -19,7 +19,7 @@ lazy_static! {
|
||||
static ref BPF_UPGRADEABLE_LOADER_PROGRAM_ID: Pubkey = solana_sdk::bpf_loader_upgradeable::id();
|
||||
static ref MEMO_V1_PROGRAM_ID: Pubkey = Pubkey::new_from_array(spl_memo::v1::id().to_bytes());
|
||||
static ref MEMO_V3_PROGRAM_ID: Pubkey = Pubkey::new_from_array(spl_memo::id().to_bytes());
|
||||
static ref STAKE_PROGRAM_ID: Pubkey = solana_stake_program::id();
|
||||
static ref STAKE_PROGRAM_ID: Pubkey = stake::program::id();
|
||||
static ref SYSTEM_PROGRAM_ID: Pubkey = system_program::id();
|
||||
static ref TOKEN_PROGRAM_ID: Pubkey = spl_token_id_v2_0();
|
||||
static ref VOTE_PROGRAM_ID: Pubkey = solana_vote_program::id();
|
||||
|
@@ -3,8 +3,9 @@ use crate::parse_instruction::{
|
||||
};
|
||||
use bincode::deserialize;
|
||||
use serde_json::{json, Map};
|
||||
use solana_sdk::{instruction::CompiledInstruction, pubkey::Pubkey};
|
||||
use solana_stake_program::stake_instruction::StakeInstruction;
|
||||
use solana_sdk::{
|
||||
instruction::CompiledInstruction, pubkey::Pubkey, stake::instruction::StakeInstruction,
|
||||
};
|
||||
|
||||
pub fn parse_stake(
|
||||
instruction: &CompiledInstruction,
|
||||
@@ -195,10 +196,13 @@ fn check_num_stake_accounts(accounts: &[u8], num: usize) -> Result<(), ParseInst
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use solana_sdk::{message::Message, pubkey::Pubkey};
|
||||
use solana_stake_program::{
|
||||
stake_instruction::{self, LockupArgs},
|
||||
stake_state::{Authorized, Lockup, StakeAuthorize},
|
||||
use solana_sdk::{
|
||||
message::Message,
|
||||
pubkey::Pubkey,
|
||||
stake::{
|
||||
instruction::{self, LockupArgs},
|
||||
state::{Authorized, Lockup, StakeAuthorize},
|
||||
},
|
||||
};
|
||||
|
||||
#[test]
|
||||
@@ -221,7 +225,7 @@ mod test {
|
||||
let lamports = 55;
|
||||
|
||||
let instructions =
|
||||
stake_instruction::create_account(&keys[0], &keys[1], &authorized, &lockup, lamports);
|
||||
instruction::create_account(&keys[0], &keys[1], &authorized, &lockup, lamports);
|
||||
let message = Message::new(&instructions, None);
|
||||
assert_eq!(
|
||||
parse_stake(&message.instructions[1], &keys[0..3]).unwrap(),
|
||||
@@ -244,13 +248,8 @@ mod test {
|
||||
);
|
||||
assert!(parse_stake(&message.instructions[1], &keys[0..2]).is_err());
|
||||
|
||||
let instruction = stake_instruction::authorize(
|
||||
&keys[1],
|
||||
&keys[0],
|
||||
&keys[3],
|
||||
StakeAuthorize::Staker,
|
||||
None,
|
||||
);
|
||||
let instruction =
|
||||
instruction::authorize(&keys[1], &keys[0], &keys[3], StakeAuthorize::Staker, None);
|
||||
let message = Message::new(&[instruction], None);
|
||||
assert_eq!(
|
||||
parse_stake(&message.instructions[0], &keys[0..3]).unwrap(),
|
||||
@@ -267,7 +266,7 @@ mod test {
|
||||
);
|
||||
assert!(parse_stake(&message.instructions[0], &keys[0..2]).is_err());
|
||||
|
||||
let instruction = stake_instruction::authorize(
|
||||
let instruction = instruction::authorize(
|
||||
&keys[1],
|
||||
&keys[0],
|
||||
&keys[3],
|
||||
@@ -291,7 +290,7 @@ mod test {
|
||||
);
|
||||
assert!(parse_stake(&message.instructions[0], &keys[0..2]).is_err());
|
||||
|
||||
let instruction = stake_instruction::delegate_stake(&keys[1], &keys[0], &keys[2]);
|
||||
let instruction = instruction::delegate_stake(&keys[1], &keys[0], &keys[2]);
|
||||
let message = Message::new(&[instruction], None);
|
||||
assert_eq!(
|
||||
parse_stake(&message.instructions[0], &keys[0..6]).unwrap(),
|
||||
@@ -313,7 +312,7 @@ mod test {
|
||||
// * split account (signer, allocate + assign first)
|
||||
// * stake authority (signer)
|
||||
// * stake account
|
||||
let instructions = stake_instruction::split(&keys[2], &keys[1], lamports, &keys[0]);
|
||||
let instructions = instruction::split(&keys[2], &keys[1], lamports, &keys[0]);
|
||||
let message = Message::new(&instructions, None);
|
||||
assert_eq!(
|
||||
parse_stake(&message.instructions[2], &keys[0..3]).unwrap(),
|
||||
@@ -329,7 +328,7 @@ mod test {
|
||||
);
|
||||
assert!(parse_stake(&message.instructions[2], &keys[0..2]).is_err());
|
||||
|
||||
let instruction = stake_instruction::withdraw(&keys[1], &keys[0], &keys[2], lamports, None);
|
||||
let instruction = instruction::withdraw(&keys[1], &keys[0], &keys[2], lamports, None);
|
||||
let message = Message::new(&[instruction], None);
|
||||
assert_eq!(
|
||||
parse_stake(&message.instructions[0], &keys[0..5]).unwrap(),
|
||||
@@ -346,7 +345,7 @@ mod test {
|
||||
}
|
||||
);
|
||||
let instruction =
|
||||
stake_instruction::withdraw(&keys[2], &keys[0], &keys[3], lamports, Some(&keys[1]));
|
||||
instruction::withdraw(&keys[2], &keys[0], &keys[3], lamports, Some(&keys[1]));
|
||||
let message = Message::new(&[instruction], None);
|
||||
assert_eq!(
|
||||
parse_stake(&message.instructions[0], &keys[0..6]).unwrap(),
|
||||
@@ -365,7 +364,7 @@ mod test {
|
||||
);
|
||||
assert!(parse_stake(&message.instructions[0], &keys[0..4]).is_err());
|
||||
|
||||
let instruction = stake_instruction::deactivate_stake(&keys[1], &keys[0]);
|
||||
let instruction = instruction::deactivate_stake(&keys[1], &keys[0]);
|
||||
let message = Message::new(&[instruction], None);
|
||||
assert_eq!(
|
||||
parse_stake(&message.instructions[0], &keys[0..3]).unwrap(),
|
||||
@@ -380,7 +379,7 @@ mod test {
|
||||
);
|
||||
assert!(parse_stake(&message.instructions[0], &keys[0..2]).is_err());
|
||||
|
||||
let instructions = stake_instruction::merge(&keys[1], &keys[0], &keys[2]);
|
||||
let instructions = instruction::merge(&keys[1], &keys[0], &keys[2]);
|
||||
let message = Message::new(&instructions, None);
|
||||
assert_eq!(
|
||||
parse_stake(&message.instructions[0], &keys[0..5]).unwrap(),
|
||||
@@ -398,7 +397,7 @@ mod test {
|
||||
assert!(parse_stake(&message.instructions[0], &keys[0..4]).is_err());
|
||||
|
||||
let seed = "test_seed";
|
||||
let instruction = stake_instruction::authorize_with_seed(
|
||||
let instruction = instruction::authorize_with_seed(
|
||||
&keys[1],
|
||||
&keys[0],
|
||||
seed.to_string(),
|
||||
@@ -425,7 +424,7 @@ mod test {
|
||||
);
|
||||
assert!(parse_stake(&message.instructions[0], &keys[0..1]).is_err());
|
||||
|
||||
let instruction = stake_instruction::authorize_with_seed(
|
||||
let instruction = instruction::authorize_with_seed(
|
||||
&keys[1],
|
||||
&keys[0],
|
||||
seed.to_string(),
|
||||
@@ -470,7 +469,7 @@ mod test {
|
||||
epoch: None,
|
||||
custodian: None,
|
||||
};
|
||||
let instruction = stake_instruction::set_lockup(&keys[1], &lockup, &keys[0]);
|
||||
let instruction = instruction::set_lockup(&keys[1], &lockup, &keys[0]);
|
||||
let message = Message::new(&[instruction], None);
|
||||
assert_eq!(
|
||||
parse_stake(&message.instructions[0], &keys[0..2]).unwrap(),
|
||||
@@ -491,7 +490,7 @@ mod test {
|
||||
epoch: Some(epoch),
|
||||
custodian: None,
|
||||
};
|
||||
let instruction = stake_instruction::set_lockup(&keys[1], &lockup, &keys[0]);
|
||||
let instruction = instruction::set_lockup(&keys[1], &lockup, &keys[0]);
|
||||
let message = Message::new(&[instruction], None);
|
||||
assert_eq!(
|
||||
parse_stake(&message.instructions[0], &keys[0..2]).unwrap(),
|
||||
@@ -513,7 +512,7 @@ mod test {
|
||||
epoch: Some(epoch),
|
||||
custodian: Some(custodian),
|
||||
};
|
||||
let instruction = stake_instruction::set_lockup(&keys[1], &lockup, &keys[0]);
|
||||
let instruction = instruction::set_lockup(&keys[1], &lockup, &keys[0]);
|
||||
let message = Message::new(&[instruction], None);
|
||||
assert_eq!(
|
||||
parse_stake(&message.instructions[0], &keys[0..2]).unwrap(),
|
||||
|
Reference in New Issue
Block a user