_id => _pubkey variable renaming (#4419)

* wallet: rename *_account_id to *_account_pubkey

* s/from_id/from_pubkey/g

* s/node_id/node_pubkey/g

* s/stake_id/stake_pubkey/g

* s/voter_id/voter_pubkey/g

* s/vote_id/vote_pubkey/g

* s/delegate_id/delegate_pubkey/g

* s/account_id/account_pubkey/g

* s/to_id/to_pubkey/g

* s/my_id/my_pubkey/g

* cargo fmt

* s/staker_id/staker_pubkey/g

* s/mining_pool_id/mining_pool_pubkey/g

* s/leader_id/leader_pubkey/g

* cargo fmt

* s/funding_id/funding_pubkey/g
This commit is contained in:
Michael Vines
2019-05-23 23:20:04 -07:00
committed by GitHub
parent 94beb4b8c2
commit cfe5afd34c
42 changed files with 697 additions and 620 deletions

View File

@ -43,14 +43,14 @@ pub enum StakeInstruction {
}
pub fn create_delegate_account(
from_id: &Pubkey,
staker_id: &Pubkey,
from_pubkey: &Pubkey,
staker_pubkey: &Pubkey,
lamports: u64,
) -> Vec<Instruction> {
vec![
system_instruction::create_account(
from_id,
staker_id,
from_pubkey,
staker_pubkey,
lamports,
std::mem::size_of::<StakeState>() as u64,
&id(),
@ -59,22 +59,22 @@ pub fn create_delegate_account(
id(),
&StakeInstruction::InitializeDelegate,
vec![
AccountMeta::new(*from_id, true),
AccountMeta::new(*staker_id, false),
AccountMeta::new(*from_pubkey, true),
AccountMeta::new(*staker_pubkey, false),
],
),
]
}
pub fn create_mining_pool_account(
from_id: &Pubkey,
staker_id: &Pubkey,
from_pubkey: &Pubkey,
staker_pubkey: &Pubkey,
lamports: u64,
) -> Vec<Instruction> {
vec![
system_instruction::create_account(
from_id,
staker_id,
from_pubkey,
staker_pubkey,
lamports,
std::mem::size_of::<StakeState>() as u64,
&id(),
@ -83,33 +83,37 @@ pub fn create_mining_pool_account(
id(),
&StakeInstruction::InitializeMiningPool,
vec![
AccountMeta::new(*from_id, true),
AccountMeta::new(*staker_id, false),
AccountMeta::new(*from_pubkey, true),
AccountMeta::new(*staker_pubkey, false),
],
),
]
}
pub fn redeem_vote_credits(
from_id: &Pubkey,
mining_pool_id: &Pubkey,
stake_id: &Pubkey,
vote_id: &Pubkey,
from_pubkey: &Pubkey,
mining_pool_pubkey: &Pubkey,
stake_pubkey: &Pubkey,
vote_pubkey: &Pubkey,
) -> Instruction {
let account_metas = vec![
AccountMeta::new(*from_id, true),
AccountMeta::new(*mining_pool_id, false),
AccountMeta::new(*stake_id, false),
AccountMeta::new(*vote_id, false),
AccountMeta::new(*from_pubkey, true),
AccountMeta::new(*mining_pool_pubkey, false),
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new(*vote_pubkey, false),
];
Instruction::new(id(), &StakeInstruction::RedeemVoteCredits, account_metas)
}
pub fn delegate_stake(from_id: &Pubkey, stake_id: &Pubkey, vote_id: &Pubkey) -> Instruction {
pub fn delegate_stake(
from_pubkey: &Pubkey,
stake_pubkey: &Pubkey,
vote_pubkey: &Pubkey,
) -> Instruction {
let account_metas = vec![
AccountMeta::new(*from_id, true),
AccountMeta::new(*stake_id, true),
AccountMeta::new(*vote_id, false),
AccountMeta::new(*from_pubkey, true),
AccountMeta::new(*stake_pubkey, true),
AccountMeta::new(*vote_pubkey, false),
];
Instruction::new(id(), &StakeInstruction::DelegateStake, account_metas)
}

View File

@ -15,7 +15,7 @@ use solana_vote_api::vote_state::VoteState;
pub enum StakeState {
Uninitialized,
Delegate {
voter_id: Pubkey,
voter_pubkey: Pubkey,
credits_observed: u64,
},
MiningPool,
@ -46,13 +46,13 @@ impl StakeState {
}
// utility function, used by Stakes, tests
pub fn voter_id_from(account: &Account) -> Option<Pubkey> {
Self::from(account).and_then(|state: Self| state.voter_id())
pub fn voter_pubkey_from(account: &Account) -> Option<Pubkey> {
Self::from(account).and_then(|state: Self| state.voter_pubkey())
}
pub fn voter_id(&self) -> Option<Pubkey> {
pub fn voter_pubkey(&self) -> Option<Pubkey> {
match self {
StakeState::Delegate { voter_id, .. } => Some(*voter_id),
StakeState::Delegate { voter_pubkey, .. } => Some(*voter_pubkey),
_ => None,
}
}
@ -109,7 +109,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
fn initialize_delegate(&mut self) -> Result<(), InstructionError> {
if let StakeState::Uninitialized = self.state()? {
self.set_state(&StakeState::Delegate {
voter_id: Pubkey::default(),
voter_pubkey: Pubkey::default(),
credits_observed: 0,
})
} else {
@ -124,7 +124,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
if let StakeState::Delegate { .. } = self.state()? {
let vote_state: VoteState = vote_account.state()?;
self.set_state(&StakeState::Delegate {
voter_id: *vote_account.unsigned_key(),
voter_pubkey: *vote_account.unsigned_key(),
credits_observed: vote_state.credits(),
})
} else {
@ -140,14 +140,14 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
if let (
StakeState::MiningPool,
StakeState::Delegate {
voter_id,
voter_pubkey,
credits_observed,
},
) = (self.state()?, stake_account.state()?)
{
let vote_state: VoteState = vote_account.state()?;
if voter_id != *vote_account.unsigned_key() {
if voter_pubkey != *vote_account.unsigned_key() {
return Err(InstructionError::InvalidArgument);
}
@ -168,7 +168,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
vote_account.account.lamports += voters_reward;
stake_account.set_state(&StakeState::Delegate {
voter_id,
voter_pubkey,
credits_observed: vote_state.credits(),
})
} else {
@ -183,7 +183,7 @@ impl<'a> StakeAccount for KeyedAccount<'a> {
// utility function, used by Bank, tests, genesis
pub fn create_delegate_stake_account(
voter_id: &Pubkey,
voter_pubkey: &Pubkey,
vote_state: &VoteState,
lamports: u64,
) -> Account {
@ -191,7 +191,7 @@ pub fn create_delegate_stake_account(
stake_account
.set_state(&StakeState::Delegate {
voter_id: *voter_id,
voter_pubkey: *voter_pubkey,
credits_observed: vote_state.credits(),
})
.expect("set_state");
@ -254,7 +254,7 @@ mod tests {
assert_eq!(
stake_state,
StakeState::Delegate {
voter_id: vote_keypair.pubkey(),
voter_pubkey: vote_keypair.pubkey(),
credits_observed: vote_state.credits()
}
);
@ -438,7 +438,7 @@ mod tests {
let mut vote1_keyed_account = KeyedAccount::new(&vote1_pubkey, false, &mut vote1_account);
vote1_keyed_account.set_state(&vote_state).unwrap();
// wrong voter_id...
// wrong voter_pubkey...
assert_eq!(
mining_pool_keyed_account
.redeem_vote_credits(&mut stake_keyed_account, &mut vote1_keyed_account),