Remove credit-only account handling (#6726)

* Renaming
- credit-only/credit-debit to read-only/read-write
- debitable to writable

* Remove credit handling, making credit-only accounts read-only

* Update programs to remove deprecated credit-only account designation

* Use readonly and writable instead of underscored types
This commit is contained in:
Tyera Eulberg
2019-11-05 09:38:35 -07:00
committed by GitHub
parent cea13e964c
commit c6931dcb07
20 changed files with 344 additions and 621 deletions

View File

@ -55,7 +55,7 @@ pub enum BudgetInstruction {
fn initialize_account(contract: &Pubkey, expr: BudgetExpr) -> Instruction {
let mut keys = vec![];
if let BudgetExpr::Pay(payment) = &expr {
keys.push(AccountMeta::new_credit_only(payment.to, false));
keys.push(AccountMeta::new(payment.to, false));
}
keys.push(AccountMeta::new(*contract, false));
Instruction::new(
@ -146,7 +146,7 @@ pub fn apply_timestamp(
AccountMeta::new(*contract, false),
];
if from != to {
account_metas.push(AccountMeta::new_credit_only(*to, false));
account_metas.push(AccountMeta::new(*to, false));
}
Instruction::new(id(), &BudgetInstruction::ApplyTimestamp(dt), account_metas)
}
@ -157,7 +157,7 @@ pub fn apply_signature(from: &Pubkey, contract: &Pubkey, to: &Pubkey) -> Instruc
AccountMeta::new(*contract, false),
];
if from != to {
account_metas.push(AccountMeta::new_credit_only(*to, false));
account_metas.push(AccountMeta::new(*to, false));
}
Instruction::new(id(), &BudgetInstruction::ApplySignature, account_metas)
}
@ -165,9 +165,9 @@ pub fn apply_signature(from: &Pubkey, contract: &Pubkey, to: &Pubkey) -> Instruc
/// Apply account data to a contract waiting on an AccountData witness.
pub fn apply_account_data(witness_pubkey: &Pubkey, contract: &Pubkey, to: &Pubkey) -> Instruction {
let account_metas = vec![
AccountMeta::new_credit_only(*witness_pubkey, false),
AccountMeta::new_readonly(*witness_pubkey, false),
AccountMeta::new(*contract, false),
AccountMeta::new_credit_only(*to, false),
AccountMeta::new(*to, false),
];
Instruction::new(id(), &BudgetInstruction::ApplyAccountData, account_metas)
}

View File

@ -36,7 +36,7 @@ pub fn mint(
let ix_data = LoaderInstruction::InvokeMain { data };
let accounts = vec![
AccountMeta::new_credit_only(*program_pubkey, false),
AccountMeta::new_readonly(*program_pubkey, false),
AccountMeta::new(*from_pubkey, true),
AccountMeta::new(*to_pubkey, false),
];
@ -65,8 +65,8 @@ pub fn transfer(
let ix_data = LoaderInstruction::InvokeMain { data };
let accounts = vec![
AccountMeta::new_credit_only(*program_pubkey, false),
AccountMeta::new_credit_only(*mint_pubkey, false),
AccountMeta::new_readonly(*program_pubkey, false),
AccountMeta::new_readonly(*mint_pubkey, false),
AccountMeta::new(*from_pubkey, true),
AccountMeta::new(*to_pubkey, false),
];

View File

@ -137,7 +137,7 @@ pub fn initialize(stake_pubkey: &Pubkey, authorized: &Authorized, lockup: &Locku
&StakeInstruction::Initialize(*authorized, *lockup),
vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new_credit_only(sysvar::rent::id(), false),
AccountMeta::new_readonly(sysvar::rent::id(), false),
],
)
}
@ -235,7 +235,7 @@ fn metas_with_signer(
}
// signer wasn't in metas, append it after normal parameters
metas.push(AccountMeta::new_credit_only(*signer, true));
metas.push(AccountMeta::new_readonly(*signer, true));
metas
}
@ -259,10 +259,10 @@ pub fn authorize(
pub fn redeem_vote_credits(stake_pubkey: &Pubkey, vote_pubkey: &Pubkey) -> Instruction {
let account_metas = vec![
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new_credit_only(*vote_pubkey, false),
AccountMeta::new(*vote_pubkey, false),
AccountMeta::new(crate::rewards_pools::random_id(), false),
AccountMeta::new_credit_only(sysvar::rewards::id(), false),
AccountMeta::new_credit_only(sysvar::stake_history::id(), false),
AccountMeta::new_readonly(sysvar::rewards::id(), false),
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
];
Instruction::new(id(), &StakeInstruction::RedeemVoteCredits, account_metas)
}
@ -275,9 +275,9 @@ pub fn delegate_stake(
let account_metas = metas_with_signer(
&[
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new_credit_only(*vote_pubkey, false),
AccountMeta::new_credit_only(sysvar::clock::id(), false),
AccountMeta::new_credit_only(crate::config::id(), false),
AccountMeta::new_readonly(*vote_pubkey, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(crate::config::id(), false),
],
authorized_pubkey,
);
@ -293,9 +293,9 @@ pub fn withdraw(
let account_metas = metas_with_signer(
&[
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new_credit_only(*to_pubkey, false),
AccountMeta::new_credit_only(sysvar::clock::id(), false),
AccountMeta::new_credit_only(sysvar::stake_history::id(), false),
AccountMeta::new(*to_pubkey, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(sysvar::stake_history::id(), false),
],
authorized_pubkey,
);
@ -306,7 +306,7 @@ pub fn deactivate_stake(stake_pubkey: &Pubkey, authorized_pubkey: &Pubkey) -> In
let account_metas = metas_with_signer(
&[
AccountMeta::new(*stake_pubkey, false),
AccountMeta::new_credit_only(sysvar::clock::id(), false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
],
authorized_pubkey,
);

View File

@ -122,8 +122,8 @@ pub fn set_payee(contract: &Pubkey, old_pubkey: &Pubkey, new_pubkey: &Pubkey) ->
pub fn redeem_tokens(contract: &Pubkey, date_pubkey: &Pubkey, to: &Pubkey) -> Instruction {
let account_metas = vec![
AccountMeta::new(*contract, false),
AccountMeta::new_credit_only(*date_pubkey, false),
AccountMeta::new_credit_only(*to, false),
AccountMeta::new_readonly(*date_pubkey, false),
AccountMeta::new(*to, false),
];
Instruction::new(id(), &VestInstruction::RedeemTokens, account_metas)
}
@ -134,7 +134,7 @@ pub fn terminate(contract: &Pubkey, from: &Pubkey, to: &Pubkey) -> Instruction {
AccountMeta::new(*from, true),
];
if from != to {
account_metas.push(AccountMeta::new_credit_only(*to, false));
account_metas.push(AccountMeta::new(*to, false));
}
Instruction::new(id(), &VestInstruction::Terminate, account_metas)
}

View File

@ -106,7 +106,7 @@ fn metas_for_authorized_signer(
// append signer at the end
if !is_own_signer {
account_metas.push(AccountMeta::new_credit_only(*authorized_signer, true))
account_metas.push(AccountMeta::new_readonly(*authorized_signer, true))
// signer
}
@ -134,9 +134,9 @@ pub fn vote(vote_pubkey: &Pubkey, authorized_voter_pubkey: &Pubkey, vote: Vote)
authorized_voter_pubkey,
&[
// request slot_hashes sysvar account after vote_pubkey
AccountMeta::new_credit_only(sysvar::slot_hashes::id(), false),
AccountMeta::new_readonly(sysvar::slot_hashes::id(), false),
// request clock sysvar account after that
AccountMeta::new_credit_only(sysvar::clock::id(), false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
],
);
@ -152,7 +152,7 @@ pub fn withdraw(
let account_metas = metas_for_authorized_signer(
vote_pubkey,
withdrawer_pubkey,
&[AccountMeta::new_credit_only(*to_pubkey, false)],
&[AccountMeta::new(*to_pubkey, false)],
);
Instruction::new(id(), &VoteInstruction::Withdraw(lamports), account_metas)