Update genesis addrgen to system_instruction create_address_with_seed (#7539)

This commit is contained in:
Rob Walker
2019-12-17 15:14:59 -08:00
committed by GitHub
parent 8176470b7f
commit 282667c4b5
2 changed files with 21 additions and 13 deletions

View File

@ -1,29 +1,32 @@
use solana_sdk::{hash::hashv, pubkey::Pubkey}; use solana_sdk::{pubkey::Pubkey, system_instruction::create_address_with_seed};
#[derive(Default)] #[derive(Default)]
pub struct AddressGenerator { pub struct AddressGenerator {
base_pubkey: Pubkey, base_pubkey: Pubkey,
base_name: String, base_seed: String,
program_id: Pubkey,
nth: usize, nth: usize,
} }
impl AddressGenerator { impl AddressGenerator {
pub fn new(base_pubkey: &Pubkey, base_name: &str) -> Self { pub fn new(base_pubkey: &Pubkey, base_seed: &str, program_id: &Pubkey) -> Self {
Self { Self {
base_pubkey: *base_pubkey, base_pubkey: *base_pubkey,
base_name: base_name.to_string(), base_seed: base_seed.to_string(),
program_id: *program_id,
nth: 0, nth: 0,
} }
} }
pub fn nth(&self, nth: usize) -> Pubkey { pub fn nth(&self, nth: usize) -> Pubkey {
Pubkey::new( create_address_with_seed(
hashv(&[ &self.base_pubkey,
self.base_pubkey.as_ref(), &format!("{}:{}", self.base_seed, nth),
format!("{}:{}", self.base_name, nth).as_bytes(), &self.program_id,
])
.as_ref(),
) )
.unwrap()
} }
#[allow(clippy::should_implement_trait)] #[allow(clippy::should_implement_trait)]
pub fn next(&mut self) -> Pubkey { pub fn next(&mut self) -> Pubkey {
let nth = self.nth; let nth = self.nth;

View File

@ -7,8 +7,9 @@ use solana_sdk::{
account::Account, clock::Slot, genesis_config::GenesisConfig, native_token::sol_to_lamports, account::Account, clock::Slot, genesis_config::GenesisConfig, native_token::sol_to_lamports,
pubkey::Pubkey, system_program, timing::years_as_slots, pubkey::Pubkey, system_program, timing::years_as_slots,
}; };
use solana_stake_program::stake_state::{ use solana_stake_program::{
create_lockup_stake_account, Authorized, Lockup, StakeState, self,
stake_state::{create_lockup_stake_account, Authorized, Lockup, StakeState},
}; };
#[derive(Debug)] #[derive(Debug)]
@ -88,7 +89,11 @@ pub fn create_and_add_stakes(
genesis_config.ticks_per_slot, genesis_config.ticks_per_slot,
); );
let mut address_generator = AddressGenerator::new(&authorized.staker, staker_info.name); let mut address_generator = AddressGenerator::new(
&authorized.staker,
staker_info.name,
&solana_stake_program::id(),
);
let stake_rent_reserve = StakeState::get_rent_exempt_reserve(&genesis_config.rent); let stake_rent_reserve = StakeState::get_rent_exempt_reserve(&genesis_config.rent);