pass Pubkeys as refs, copy only where values needed (#3213)
* pass Pubkeys as refs, copy only where values needed * Pubkey is pervasive * fixup
This commit is contained in:
@ -42,11 +42,11 @@ mod bpf {
|
||||
let bank = Bank::new(&genesis_block);
|
||||
|
||||
// Call user program
|
||||
let program_id = load_program(&bank, &mint_keypair, bpf_loader::id(), elf);
|
||||
let program_id = load_program(&bank, &mint_keypair, &bpf_loader::id(), elf);
|
||||
let tx = Transaction::new(
|
||||
&mint_keypair,
|
||||
&[],
|
||||
program_id,
|
||||
&program_id,
|
||||
&vec![1u8],
|
||||
bank.last_blockhash(),
|
||||
0,
|
||||
@ -80,16 +80,16 @@ mod bpf {
|
||||
let loader_id = load_program(
|
||||
&bank,
|
||||
&mint_keypair,
|
||||
native_loader::id(),
|
||||
&native_loader::id(),
|
||||
"solana_bpf_loader".as_bytes().to_vec(),
|
||||
);
|
||||
|
||||
// Call user program
|
||||
let program_id = load_program(&bank, &mint_keypair, loader_id, elf);
|
||||
let program_id = load_program(&bank, &mint_keypair, &loader_id, elf);
|
||||
let tx = Transaction::new(
|
||||
&mint_keypair,
|
||||
&[],
|
||||
program_id,
|
||||
&program_id,
|
||||
&vec![1u8],
|
||||
bank.last_blockhash(),
|
||||
0,
|
||||
@ -126,16 +126,16 @@ mod bpf {
|
||||
let loader_id = load_program(
|
||||
&bank,
|
||||
&mint_keypair,
|
||||
native_loader::id(),
|
||||
&native_loader::id(),
|
||||
"solana_bpf_loader".as_bytes().to_vec(),
|
||||
);
|
||||
|
||||
// Call user program
|
||||
let program_id = load_program(&bank, &mint_keypair, loader_id, elf);
|
||||
let program_id = load_program(&bank, &mint_keypair, &loader_id, elf);
|
||||
let tx = Transaction::new(
|
||||
&mint_keypair,
|
||||
&[],
|
||||
program_id,
|
||||
&program_id,
|
||||
&vec![1u8],
|
||||
bank.last_blockhash(),
|
||||
0,
|
||||
|
@ -175,14 +175,14 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_invalid_instruction() {
|
||||
let mut accounts = vec![Account::new(1, 0, id()), Account::new(0, 512, id())];
|
||||
let mut accounts = vec![Account::new(1, 0, &id()), Account::new(0, 512, &id())];
|
||||
let from = Keypair::new();
|
||||
let contract = Keypair::new();
|
||||
let userdata = (1u8, 2u8, 3u8);
|
||||
let tx = Transaction::new(
|
||||
&from,
|
||||
&[contract.pubkey()],
|
||||
id(),
|
||||
&id(),
|
||||
&userdata,
|
||||
Hash::default(),
|
||||
0,
|
||||
@ -192,7 +192,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_unsigned_witness_key() {
|
||||
let mut accounts = vec![Account::new(1, 0, system_program::id())];
|
||||
let mut accounts = vec![Account::new(1, 0, &system_program::id())];
|
||||
|
||||
// Initialize BudgetState
|
||||
let from = Keypair::new();
|
||||
@ -201,9 +201,9 @@ mod test {
|
||||
let witness = Keypair::new().pubkey();
|
||||
let tx = BudgetTransaction::new_when_signed(
|
||||
&from,
|
||||
to,
|
||||
contract,
|
||||
witness,
|
||||
&to,
|
||||
&contract,
|
||||
&witness,
|
||||
None,
|
||||
1,
|
||||
Hash::default(),
|
||||
@ -212,7 +212,7 @@ mod test {
|
||||
|
||||
// Attack! Part 1: Sign a witness transaction with a random key.
|
||||
let rando = Keypair::new();
|
||||
let mut tx = BudgetTransaction::new_signature(&rando, contract, to, Hash::default());
|
||||
let mut tx = BudgetTransaction::new_signature(&rando, &contract, &to, Hash::default());
|
||||
|
||||
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
||||
tx.account_keys.push(from.pubkey());
|
||||
@ -227,7 +227,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_unsigned_timestamp() {
|
||||
let mut accounts = vec![Account::new(1, 0, system_program::id())];
|
||||
let mut accounts = vec![Account::new(1, 0, &system_program::id())];
|
||||
|
||||
// Initialize BudgetState
|
||||
let from = Keypair::new();
|
||||
@ -236,10 +236,10 @@ mod test {
|
||||
let dt = Utc::now();
|
||||
let tx = BudgetTransaction::new_on_date(
|
||||
&from,
|
||||
to,
|
||||
contract,
|
||||
&to,
|
||||
&contract,
|
||||
dt,
|
||||
from.pubkey(),
|
||||
&from.pubkey(),
|
||||
None,
|
||||
1,
|
||||
Hash::default(),
|
||||
@ -248,7 +248,7 @@ mod test {
|
||||
|
||||
// Attack! Part 1: Sign a timestamp transaction with a random key.
|
||||
let rando = Keypair::new();
|
||||
let mut tx = BudgetTransaction::new_timestamp(&rando, contract, to, dt, Hash::default());
|
||||
let mut tx = BudgetTransaction::new_timestamp(&rando, &contract, &to, dt, Hash::default());
|
||||
|
||||
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
||||
tx.account_keys.push(from.pubkey());
|
||||
@ -263,7 +263,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_transfer_on_date() {
|
||||
let mut accounts = vec![Account::new(1, 0, system_program::id())];
|
||||
let mut accounts = vec![Account::new(1, 0, &system_program::id())];
|
||||
let from_account = 0;
|
||||
let contract_account = 1;
|
||||
let to_account = 2;
|
||||
@ -274,10 +274,10 @@ mod test {
|
||||
let dt = Utc::now();
|
||||
let tx = BudgetTransaction::new_on_date(
|
||||
&from,
|
||||
to.pubkey(),
|
||||
contract.pubkey(),
|
||||
&to.pubkey(),
|
||||
&contract.pubkey(),
|
||||
dt,
|
||||
from.pubkey(),
|
||||
&from.pubkey(),
|
||||
None,
|
||||
1,
|
||||
Hash::default(),
|
||||
@ -291,8 +291,8 @@ mod test {
|
||||
// Attack! Try to payout to a rando key
|
||||
let tx = BudgetTransaction::new_timestamp(
|
||||
&from,
|
||||
contract.pubkey(),
|
||||
rando.pubkey(),
|
||||
&contract.pubkey(),
|
||||
&rando.pubkey(),
|
||||
dt,
|
||||
Hash::default(),
|
||||
);
|
||||
@ -311,8 +311,8 @@ mod test {
|
||||
// that pubkey's funds are now available.
|
||||
let tx = BudgetTransaction::new_timestamp(
|
||||
&from,
|
||||
contract.pubkey(),
|
||||
to.pubkey(),
|
||||
&contract.pubkey(),
|
||||
&to.pubkey(),
|
||||
dt,
|
||||
Hash::default(),
|
||||
);
|
||||
@ -335,7 +335,7 @@ mod test {
|
||||
}
|
||||
#[test]
|
||||
fn test_cancel_transfer() {
|
||||
let mut accounts = vec![Account::new(1, 0, system_program::id())];
|
||||
let mut accounts = vec![Account::new(1, 0, &system_program::id())];
|
||||
let from_account = 0;
|
||||
let contract_account = 1;
|
||||
let pay_account = 2;
|
||||
@ -345,10 +345,10 @@ mod test {
|
||||
let dt = Utc::now();
|
||||
let tx = BudgetTransaction::new_on_date(
|
||||
&from,
|
||||
to.pubkey(),
|
||||
contract.pubkey(),
|
||||
&to.pubkey(),
|
||||
&contract.pubkey(),
|
||||
dt,
|
||||
from.pubkey(),
|
||||
&from.pubkey(),
|
||||
Some(from.pubkey()),
|
||||
1,
|
||||
Hash::default(),
|
||||
@ -360,8 +360,12 @@ mod test {
|
||||
assert!(budget_state.is_pending());
|
||||
|
||||
// Attack! try to put the lamports into the wrong account with cancel
|
||||
let tx =
|
||||
BudgetTransaction::new_signature(&to, contract.pubkey(), to.pubkey(), Hash::default());
|
||||
let tx = BudgetTransaction::new_signature(
|
||||
&to,
|
||||
&contract.pubkey(),
|
||||
&to.pubkey(),
|
||||
Hash::default(),
|
||||
);
|
||||
// unit test hack, the `from account` is passed instead of the `to` account to avoid
|
||||
// creating more account vectors
|
||||
process_transaction(&tx, &mut accounts).unwrap();
|
||||
@ -373,8 +377,8 @@ mod test {
|
||||
// Now, cancel the transaction. from gets her funds back
|
||||
let tx = BudgetTransaction::new_signature(
|
||||
&from,
|
||||
contract.pubkey(),
|
||||
from.pubkey(),
|
||||
&contract.pubkey(),
|
||||
&from.pubkey(),
|
||||
Hash::default(),
|
||||
);
|
||||
process_transaction(&tx, &mut accounts).unwrap();
|
||||
@ -385,8 +389,8 @@ mod test {
|
||||
// try to replay the cancel contract
|
||||
let tx = BudgetTransaction::new_signature(
|
||||
&from,
|
||||
contract.pubkey(),
|
||||
from.pubkey(),
|
||||
&contract.pubkey(),
|
||||
&from.pubkey(),
|
||||
Hash::default(),
|
||||
);
|
||||
assert_eq!(
|
||||
|
@ -14,7 +14,7 @@ impl<'a> BudgetBank<'a> {
|
||||
Self { bank }
|
||||
}
|
||||
|
||||
fn pay(&self, from_keypair: &Keypair, to_id: Pubkey, lamports: u64) -> Result<()> {
|
||||
fn pay(&self, from_keypair: &Keypair, to_id: &Pubkey, lamports: u64) -> Result<()> {
|
||||
let blockhash = self.bank.last_blockhash();
|
||||
let tx = BudgetTransaction::new_payment(from_keypair, to_id, lamports, blockhash, 0);
|
||||
self.bank.process_transaction(&tx)
|
||||
@ -27,6 +27,6 @@ fn test_budget_payment_via_bank() {
|
||||
let bank = Bank::new(&genesis_block);
|
||||
let budget_bank = BudgetBank::new(&bank);
|
||||
let to_id = Keypair::new().pubkey();
|
||||
budget_bank.pay(&from_keypair, to_id, 100).unwrap();
|
||||
budget_bank.pay(&from_keypair, &to_id, 100).unwrap();
|
||||
assert_eq!(bank.get_balance(&to_id), 100);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! The `budget_expr` module provides a domain-specific language for payment plans. Users create BudgetExpr objects that
|
||||
//! The `budget_expr` module provides a domain-specific language for pa&yment plans. Users create BudgetExpr objects that
|
||||
//! are given to an interpreter. The interpreter listens for `Witness` transactions,
|
||||
//! which it uses to reduce the payment plan. When the budget is reduced to a
|
||||
//! `Payment`, the payment is executed.
|
||||
@ -52,36 +52,41 @@ pub enum BudgetExpr {
|
||||
|
||||
impl BudgetExpr {
|
||||
/// Create the simplest budget - one that pays `lamports` to Pubkey.
|
||||
pub fn new_payment(lamports: u64, to: Pubkey) -> Self {
|
||||
BudgetExpr::Pay(Payment { lamports, to })
|
||||
pub fn new_payment(lamports: u64, to: &Pubkey) -> Self {
|
||||
BudgetExpr::Pay(Payment { lamports, to: *to })
|
||||
}
|
||||
|
||||
/// Create a budget that pays `lamports` to `to` after being witnessed by `from`.
|
||||
pub fn new_authorized_payment(from: Pubkey, lamports: u64, to: Pubkey) -> Self {
|
||||
pub fn new_authorized_payment(from: &Pubkey, lamports: u64, to: &Pubkey) -> Self {
|
||||
BudgetExpr::After(
|
||||
Condition::Signature(from),
|
||||
Condition::Signature(*from),
|
||||
Box::new(Self::new_payment(lamports, to)),
|
||||
)
|
||||
}
|
||||
|
||||
/// Create a budget that pays lamports` to `to` after being witnessed by 2x `from`s
|
||||
pub fn new_2_2_multisig_payment(
|
||||
from0: Pubkey,
|
||||
from1: Pubkey,
|
||||
from0: &Pubkey,
|
||||
from1: &Pubkey,
|
||||
lamports: u64,
|
||||
to: Pubkey,
|
||||
to: &Pubkey,
|
||||
) -> Self {
|
||||
BudgetExpr::And(
|
||||
Condition::Signature(from0),
|
||||
Condition::Signature(from1),
|
||||
Condition::Signature(*from0),
|
||||
Condition::Signature(*from1),
|
||||
Box::new(Self::new_payment(lamports, to)),
|
||||
)
|
||||
}
|
||||
|
||||
/// Create a budget that pays `lamports` to `to` after the given DateTime.
|
||||
pub fn new_future_payment(dt: DateTime<Utc>, from: Pubkey, lamports: u64, to: Pubkey) -> Self {
|
||||
pub fn new_future_payment(
|
||||
dt: DateTime<Utc>,
|
||||
from: &Pubkey,
|
||||
lamports: u64,
|
||||
to: &Pubkey,
|
||||
) -> Self {
|
||||
BudgetExpr::After(
|
||||
Condition::Timestamp(dt, from),
|
||||
Condition::Timestamp(dt, *from),
|
||||
Box::new(Self::new_payment(lamports, to)),
|
||||
)
|
||||
}
|
||||
@ -90,17 +95,17 @@ impl BudgetExpr {
|
||||
/// unless cancelled by `from`.
|
||||
pub fn new_cancelable_future_payment(
|
||||
dt: DateTime<Utc>,
|
||||
from: Pubkey,
|
||||
from: &Pubkey,
|
||||
lamports: u64,
|
||||
to: Pubkey,
|
||||
to: &Pubkey,
|
||||
) -> Self {
|
||||
BudgetExpr::Or(
|
||||
(
|
||||
Condition::Timestamp(dt, from),
|
||||
Condition::Timestamp(dt, *from),
|
||||
Box::new(Self::new_payment(lamports, to)),
|
||||
),
|
||||
(
|
||||
Condition::Signature(from),
|
||||
Condition::Signature(*from),
|
||||
Box::new(Self::new_payment(lamports, to)),
|
||||
),
|
||||
)
|
||||
@ -183,10 +188,10 @@ mod tests {
|
||||
let dt = Utc.ymd(2014, 11, 14).and_hms(8, 9, 10);
|
||||
let from = Pubkey::default();
|
||||
let to = Pubkey::default();
|
||||
assert!(BudgetExpr::new_payment(42, to).verify(42));
|
||||
assert!(BudgetExpr::new_authorized_payment(from, 42, to).verify(42));
|
||||
assert!(BudgetExpr::new_future_payment(dt, from, 42, to).verify(42));
|
||||
assert!(BudgetExpr::new_cancelable_future_payment(dt, from, 42, to).verify(42));
|
||||
assert!(BudgetExpr::new_payment(42, &to).verify(42));
|
||||
assert!(BudgetExpr::new_authorized_payment(&from, 42, &to).verify(42));
|
||||
assert!(BudgetExpr::new_future_payment(dt, &from, 42, &to).verify(42));
|
||||
assert!(BudgetExpr::new_cancelable_future_payment(dt, &from, 42, &to).verify(42));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -194,9 +199,9 @@ mod tests {
|
||||
let from = Pubkey::default();
|
||||
let to = Pubkey::default();
|
||||
|
||||
let mut expr = BudgetExpr::new_authorized_payment(from, 42, to);
|
||||
let mut expr = BudgetExpr::new_authorized_payment(&from, 42, &to);
|
||||
expr.apply_witness(&Witness::Signature, &from);
|
||||
assert_eq!(expr, BudgetExpr::new_payment(42, to));
|
||||
assert_eq!(expr, BudgetExpr::new_payment(42, &to));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -205,9 +210,9 @@ mod tests {
|
||||
let from = Keypair::new().pubkey();
|
||||
let to = Keypair::new().pubkey();
|
||||
|
||||
let mut expr = BudgetExpr::new_future_payment(dt, from, 42, to);
|
||||
let mut expr = BudgetExpr::new_future_payment(dt, &from, 42, &to);
|
||||
expr.apply_witness(&Witness::Timestamp(dt), &from);
|
||||
assert_eq!(expr, BudgetExpr::new_payment(42, to));
|
||||
assert_eq!(expr, BudgetExpr::new_payment(42, &to));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -218,7 +223,7 @@ mod tests {
|
||||
let from = Keypair::new().pubkey();
|
||||
let to = Keypair::new().pubkey();
|
||||
|
||||
let mut expr = BudgetExpr::new_future_payment(dt, from, 42, to);
|
||||
let mut expr = BudgetExpr::new_future_payment(dt, &from, 42, &to);
|
||||
let orig_expr = expr.clone();
|
||||
expr.apply_witness(&Witness::Timestamp(dt), &to); // <-- Attack!
|
||||
assert_eq!(expr, orig_expr);
|
||||
@ -230,13 +235,13 @@ mod tests {
|
||||
let from = Pubkey::default();
|
||||
let to = Pubkey::default();
|
||||
|
||||
let mut expr = BudgetExpr::new_cancelable_future_payment(dt, from, 42, to);
|
||||
let mut expr = BudgetExpr::new_cancelable_future_payment(dt, &from, 42, &to);
|
||||
expr.apply_witness(&Witness::Timestamp(dt), &from);
|
||||
assert_eq!(expr, BudgetExpr::new_payment(42, to));
|
||||
assert_eq!(expr, BudgetExpr::new_payment(42, &to));
|
||||
|
||||
let mut expr = BudgetExpr::new_cancelable_future_payment(dt, from, 42, to);
|
||||
let mut expr = BudgetExpr::new_cancelable_future_payment(dt, &from, 42, &to);
|
||||
expr.apply_witness(&Witness::Signature, &from);
|
||||
assert_eq!(expr, BudgetExpr::new_payment(42, from));
|
||||
assert_eq!(expr, BudgetExpr::new_payment(42, &from));
|
||||
}
|
||||
#[test]
|
||||
fn test_2_2_multisig_payment() {
|
||||
@ -244,9 +249,9 @@ mod tests {
|
||||
let from1 = Keypair::new().pubkey();
|
||||
let to = Pubkey::default();
|
||||
|
||||
let mut expr = BudgetExpr::new_2_2_multisig_payment(from0, from1, 42, to);
|
||||
let mut expr = BudgetExpr::new_2_2_multisig_payment(&from0, &from1, 42, &to);
|
||||
expr.apply_witness(&Witness::Signature, &from0);
|
||||
assert_eq!(expr, BudgetExpr::new_authorized_payment(from1, 42, to));
|
||||
assert_eq!(expr, BudgetExpr::new_authorized_payment(&from1, 42, &to));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -256,12 +261,12 @@ mod tests {
|
||||
let from2 = Keypair::new().pubkey();
|
||||
let to = Pubkey::default();
|
||||
|
||||
let expr = BudgetExpr::new_2_2_multisig_payment(from0, from1, 42, to);
|
||||
let expr = BudgetExpr::new_2_2_multisig_payment(&from0, &from1, 42, &to);
|
||||
let mut expr = BudgetExpr::After(Condition::Signature(from2), Box::new(expr));
|
||||
|
||||
expr.apply_witness(&Witness::Signature, &from2);
|
||||
expr.apply_witness(&Witness::Signature, &from0);
|
||||
assert_eq!(expr, BudgetExpr::new_authorized_payment(from1, 42, to));
|
||||
assert_eq!(expr, BudgetExpr::new_authorized_payment(&from1, 42, &to));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -271,16 +276,16 @@ mod tests {
|
||||
let dt = Utc.ymd(2014, 11, 11).and_hms(7, 7, 7);
|
||||
let to = Pubkey::default();
|
||||
|
||||
let expr = BudgetExpr::new_2_2_multisig_payment(from0, from1, 42, to);
|
||||
let expr = BudgetExpr::new_2_2_multisig_payment(&from0, &from1, 42, &to);
|
||||
let mut expr = BudgetExpr::After(Condition::Timestamp(dt, from0), Box::new(expr));
|
||||
|
||||
expr.apply_witness(&Witness::Timestamp(dt), &from0);
|
||||
assert_eq!(
|
||||
expr,
|
||||
BudgetExpr::new_2_2_multisig_payment(from0, from1, 42, to)
|
||||
BudgetExpr::new_2_2_multisig_payment(&from0, &from1, 42, &to)
|
||||
);
|
||||
|
||||
expr.apply_witness(&Witness::Signature, &from0);
|
||||
assert_eq!(expr, BudgetExpr::new_authorized_payment(from1, 42, to));
|
||||
assert_eq!(expr, BudgetExpr::new_authorized_payment(&from1, 42, &to));
|
||||
}
|
||||
}
|
||||
|
@ -28,32 +28,36 @@ pub enum BudgetInstruction {
|
||||
}
|
||||
|
||||
impl BudgetInstruction {
|
||||
pub fn new_initialize_account(contract: Pubkey, expr: BudgetExpr) -> BuilderInstruction {
|
||||
pub fn new_initialize_account(contract: &Pubkey, expr: BudgetExpr) -> BuilderInstruction {
|
||||
let mut keys = vec![];
|
||||
if let BudgetExpr::Pay(payment) = &expr {
|
||||
keys.push((payment.to, false));
|
||||
}
|
||||
keys.push((contract, false));
|
||||
keys.push((*contract, false));
|
||||
BuilderInstruction::new(id(), &BudgetInstruction::InitializeAccount(expr), keys)
|
||||
}
|
||||
|
||||
pub fn new_apply_timestamp(
|
||||
from: Pubkey,
|
||||
contract: Pubkey,
|
||||
to: Pubkey,
|
||||
from: &Pubkey,
|
||||
contract: &Pubkey,
|
||||
to: &Pubkey,
|
||||
dt: DateTime<Utc>,
|
||||
) -> BuilderInstruction {
|
||||
let mut keys = vec![(from, true), (contract, false)];
|
||||
let mut keys = vec![(*from, true), (*contract, false)];
|
||||
if from != to {
|
||||
keys.push((to, false));
|
||||
keys.push((*to, false));
|
||||
}
|
||||
BuilderInstruction::new(id(), &BudgetInstruction::ApplyTimestamp(dt), keys)
|
||||
}
|
||||
|
||||
pub fn new_apply_signature(from: Pubkey, contract: Pubkey, to: Pubkey) -> BuilderInstruction {
|
||||
let mut keys = vec![(from, true), (contract, false)];
|
||||
pub fn new_apply_signature(
|
||||
from: &Pubkey,
|
||||
contract: &Pubkey,
|
||||
to: &Pubkey,
|
||||
) -> BuilderInstruction {
|
||||
let mut keys = vec![(*from, true), (*contract, false)];
|
||||
if from != to {
|
||||
keys.push((to, false));
|
||||
keys.push((*to, false));
|
||||
}
|
||||
BuilderInstruction::new(id(), &BudgetInstruction::ApplySignature, keys)
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_serializer() {
|
||||
let mut a = Account::new(0, 512, id());
|
||||
let mut a = Account::new(0, 512, &id());
|
||||
let b = BudgetState::default();
|
||||
b.serialize(&mut a.userdata).unwrap();
|
||||
let c = BudgetState::deserialize(&a.userdata).unwrap();
|
||||
@ -63,7 +63,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_serializer_userdata_too_small() {
|
||||
let mut a = Account::new(0, 1, id());
|
||||
let mut a = Account::new(0, 1, &id());
|
||||
let b = BudgetState::default();
|
||||
assert_eq!(
|
||||
b.serialize(&mut a.userdata),
|
||||
|
@ -20,7 +20,7 @@ impl BudgetTransaction {
|
||||
#[allow(clippy::new_ret_no_self)]
|
||||
fn new(
|
||||
from_keypair: &Keypair,
|
||||
contract: Pubkey,
|
||||
contract: &Pubkey,
|
||||
expr: BudgetExpr,
|
||||
lamports: u64,
|
||||
recent_blockhash: Hash,
|
||||
@ -30,11 +30,11 @@ impl BudgetTransaction {
|
||||
let space = serialized_size(&BudgetState::new(expr.clone())).unwrap();
|
||||
TransactionBuilder::new(fee)
|
||||
.push(SystemInstruction::new_program_account(
|
||||
from,
|
||||
&from,
|
||||
contract,
|
||||
lamports,
|
||||
space,
|
||||
id(),
|
||||
&id(),
|
||||
))
|
||||
.push(BudgetInstruction::new_initialize_account(contract, expr))
|
||||
.sign(&[from_keypair], recent_blockhash)
|
||||
@ -43,7 +43,7 @@ impl BudgetTransaction {
|
||||
/// Create and sign a new Transaction. Used for unit-testing.
|
||||
pub fn new_payment(
|
||||
from_keypair: &Keypair,
|
||||
to: Pubkey,
|
||||
to: &Pubkey,
|
||||
lamports: u64,
|
||||
recent_blockhash: Hash,
|
||||
fee: u64,
|
||||
@ -52,7 +52,7 @@ impl BudgetTransaction {
|
||||
let expr = BudgetExpr::new_payment(lamports, to);
|
||||
Self::new(
|
||||
from_keypair,
|
||||
contract,
|
||||
&contract,
|
||||
expr,
|
||||
lamports,
|
||||
recent_blockhash,
|
||||
@ -63,15 +63,15 @@ impl BudgetTransaction {
|
||||
/// Create and sign a new Witness Timestamp. Used for unit-testing.
|
||||
pub fn new_timestamp(
|
||||
from_keypair: &Keypair,
|
||||
contract: Pubkey,
|
||||
to: Pubkey,
|
||||
contract: &Pubkey,
|
||||
to: &Pubkey,
|
||||
dt: DateTime<Utc>,
|
||||
recent_blockhash: Hash,
|
||||
) -> Transaction {
|
||||
let from = from_keypair.pubkey();
|
||||
TransactionBuilder::default()
|
||||
.push(BudgetInstruction::new_apply_timestamp(
|
||||
from, contract, to, dt,
|
||||
&from, contract, to, dt,
|
||||
))
|
||||
.sign(&[from_keypair], recent_blockhash)
|
||||
}
|
||||
@ -79,23 +79,23 @@ impl BudgetTransaction {
|
||||
/// Create and sign a new Witness Signature. Used for unit-testing.
|
||||
pub fn new_signature(
|
||||
from_keypair: &Keypair,
|
||||
contract: Pubkey,
|
||||
to: Pubkey,
|
||||
contract: &Pubkey,
|
||||
to: &Pubkey,
|
||||
recent_blockhash: Hash,
|
||||
) -> Transaction {
|
||||
let from = from_keypair.pubkey();
|
||||
TransactionBuilder::default()
|
||||
.push(BudgetInstruction::new_apply_signature(from, contract, to))
|
||||
.push(BudgetInstruction::new_apply_signature(&from, contract, to))
|
||||
.sign(&[from_keypair], recent_blockhash)
|
||||
}
|
||||
|
||||
/// Create and sign a postdated Transaction. Used for unit-testing.
|
||||
pub fn new_on_date(
|
||||
from_keypair: &Keypair,
|
||||
to: Pubkey,
|
||||
contract: Pubkey,
|
||||
to: &Pubkey,
|
||||
contract: &Pubkey,
|
||||
dt: DateTime<Utc>,
|
||||
dt_pubkey: Pubkey,
|
||||
dt_pubkey: &Pubkey,
|
||||
cancelable: Option<Pubkey>,
|
||||
lamports: u64,
|
||||
recent_blockhash: Hash,
|
||||
@ -103,17 +103,17 @@ impl BudgetTransaction {
|
||||
let expr = if let Some(from) = cancelable {
|
||||
BudgetExpr::Or(
|
||||
(
|
||||
Condition::Timestamp(dt, dt_pubkey),
|
||||
Condition::Timestamp(dt, *dt_pubkey),
|
||||
Box::new(BudgetExpr::new_payment(lamports, to)),
|
||||
),
|
||||
(
|
||||
Condition::Signature(from),
|
||||
Box::new(BudgetExpr::new_payment(lamports, from)),
|
||||
Box::new(BudgetExpr::new_payment(lamports, &from)),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
BudgetExpr::After(
|
||||
Condition::Timestamp(dt, dt_pubkey),
|
||||
Condition::Timestamp(dt, *dt_pubkey),
|
||||
Box::new(BudgetExpr::new_payment(lamports, to)),
|
||||
)
|
||||
};
|
||||
@ -123,9 +123,9 @@ impl BudgetTransaction {
|
||||
/// Create and sign a multisig Transaction.
|
||||
pub fn new_when_signed(
|
||||
from_keypair: &Keypair,
|
||||
to: Pubkey,
|
||||
contract: Pubkey,
|
||||
witness: Pubkey,
|
||||
to: &Pubkey,
|
||||
contract: &Pubkey,
|
||||
witness: &Pubkey,
|
||||
cancelable: Option<Pubkey>,
|
||||
lamports: u64,
|
||||
recent_blockhash: Hash,
|
||||
@ -133,17 +133,17 @@ impl BudgetTransaction {
|
||||
let expr = if let Some(from) = cancelable {
|
||||
BudgetExpr::Or(
|
||||
(
|
||||
Condition::Signature(witness),
|
||||
Condition::Signature(*witness),
|
||||
Box::new(BudgetExpr::new_payment(lamports, to)),
|
||||
),
|
||||
(
|
||||
Condition::Signature(from),
|
||||
Box::new(BudgetExpr::new_payment(lamports, from)),
|
||||
Box::new(BudgetExpr::new_payment(lamports, &from)),
|
||||
),
|
||||
)
|
||||
} else {
|
||||
BudgetExpr::After(
|
||||
Condition::Signature(witness),
|
||||
Condition::Signature(*witness),
|
||||
Box::new(BudgetExpr::new_payment(lamports, to)),
|
||||
)
|
||||
};
|
||||
@ -184,7 +184,7 @@ mod tests {
|
||||
fn test_claim() {
|
||||
let keypair = Keypair::new();
|
||||
let zero = Hash::default();
|
||||
let tx0 = BudgetTransaction::new_payment(&keypair, keypair.pubkey(), 42, zero, 0);
|
||||
let tx0 = BudgetTransaction::new_payment(&keypair, &keypair.pubkey(), 42, zero, 0);
|
||||
assert!(BudgetTransaction::verify_plan(&tx0));
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ mod tests {
|
||||
let keypair0 = Keypair::new();
|
||||
let keypair1 = Keypair::new();
|
||||
let pubkey1 = keypair1.pubkey();
|
||||
let tx0 = BudgetTransaction::new_payment(&keypair0, pubkey1, 42, zero, 0);
|
||||
let tx0 = BudgetTransaction::new_payment(&keypair0, &pubkey1, 42, zero, 0);
|
||||
assert!(BudgetTransaction::verify_plan(&tx0));
|
||||
}
|
||||
|
||||
@ -203,7 +203,7 @@ mod tests {
|
||||
let zero = Hash::default();
|
||||
let keypair0 = Keypair::new();
|
||||
let pubkey1 = Keypair::new().pubkey();
|
||||
let tx0 = BudgetTransaction::new_payment(&keypair0, pubkey1, 1, zero, 1);
|
||||
let tx0 = BudgetTransaction::new_payment(&keypair0, &pubkey1, 1, zero, 1);
|
||||
assert!(BudgetTransaction::verify_plan(&tx0));
|
||||
}
|
||||
|
||||
@ -212,7 +212,7 @@ mod tests {
|
||||
let zero = Hash::default();
|
||||
let keypair0 = Keypair::new();
|
||||
let pubkey1 = Keypair::new().pubkey();
|
||||
let tx0 = BudgetTransaction::new_payment(&keypair0, pubkey1, 1, zero, 1);
|
||||
let tx0 = BudgetTransaction::new_payment(&keypair0, &pubkey1, 1, zero, 1);
|
||||
let buf = serialize(&tx0).unwrap();
|
||||
let tx1: Transaction = deserialize(&buf).unwrap();
|
||||
assert_eq!(tx1, tx0);
|
||||
@ -223,7 +223,7 @@ mod tests {
|
||||
let zero = Hash::default();
|
||||
let keypair = Keypair::new();
|
||||
let pubkey = keypair.pubkey();
|
||||
let mut tx = BudgetTransaction::new_payment(&keypair, pubkey, 42, zero, 0);
|
||||
let mut tx = BudgetTransaction::new_payment(&keypair, &pubkey, 42, zero, 0);
|
||||
let mut system_instruction = BudgetTransaction::system_instruction(&tx, 0).unwrap();
|
||||
if let SystemInstruction::CreateAccount {
|
||||
ref mut lamports, ..
|
||||
@ -250,7 +250,7 @@ mod tests {
|
||||
let thief_keypair = Keypair::new();
|
||||
let pubkey1 = keypair1.pubkey();
|
||||
let zero = Hash::default();
|
||||
let mut tx = BudgetTransaction::new_payment(&keypair0, pubkey1, 42, zero, 0);
|
||||
let mut tx = BudgetTransaction::new_payment(&keypair0, &pubkey1, 42, zero, 0);
|
||||
let mut instruction = BudgetTransaction::instruction(&tx, 1);
|
||||
if let Some(BudgetInstruction::InitializeAccount(ref mut expr)) = instruction {
|
||||
if let BudgetExpr::Pay(ref mut payment) = expr {
|
||||
@ -267,7 +267,7 @@ mod tests {
|
||||
let keypair0 = Keypair::new();
|
||||
let keypair1 = Keypair::new();
|
||||
let zero = Hash::default();
|
||||
let mut tx = BudgetTransaction::new_payment(&keypair0, keypair1.pubkey(), 1, zero, 0);
|
||||
let mut tx = BudgetTransaction::new_payment(&keypair0, &keypair1.pubkey(), 1, zero, 0);
|
||||
let mut instruction = BudgetTransaction::instruction(&tx, 1).unwrap();
|
||||
if let BudgetInstruction::InitializeAccount(ref mut expr) = instruction {
|
||||
if let BudgetExpr::Pay(ref mut payment) = expr {
|
||||
|
@ -12,13 +12,13 @@ fn test_program_native_failure() {
|
||||
let bank = Bank::new(&genesis_block);
|
||||
|
||||
let program = "failure".as_bytes().to_vec();
|
||||
let program_id = load_program(&bank, &mint_keypair, native_loader::id(), program);
|
||||
let program_id = load_program(&bank, &mint_keypair, &native_loader::id(), program);
|
||||
|
||||
// Call user program
|
||||
let tx = Transaction::new(
|
||||
&mint_keypair,
|
||||
&[],
|
||||
program_id,
|
||||
&program_id,
|
||||
&1u8,
|
||||
bank.last_blockhash(),
|
||||
0,
|
||||
|
@ -12,13 +12,13 @@ fn test_program_native_noop() {
|
||||
let bank = Bank::new(&genesis_block);
|
||||
|
||||
let program = "noop".as_bytes().to_vec();
|
||||
let program_id = load_program(&bank, &mint_keypair, native_loader::id(), program);
|
||||
let program_id = load_program(&bank, &mint_keypair, &native_loader::id(), program);
|
||||
|
||||
// Call user program
|
||||
let tx = Transaction::new(
|
||||
&mint_keypair,
|
||||
&[],
|
||||
program_id,
|
||||
&program_id,
|
||||
&1u8,
|
||||
bank.last_blockhash(),
|
||||
0,
|
||||
|
@ -92,7 +92,7 @@ mod tests {
|
||||
|
||||
fn create_rewards_account(lamports: u64) -> Account {
|
||||
let space = RewardsState::max_size();
|
||||
Account::new(lamports, space, solana_rewards_api::id())
|
||||
Account::new(lamports, space, &solana_rewards_api::id())
|
||||
}
|
||||
|
||||
fn redeem_vote_credits_(
|
||||
|
@ -20,7 +20,7 @@ impl<'a> RewardsBank<'a> {
|
||||
fn create_rewards_account(
|
||||
&self,
|
||||
from_keypair: &Keypair,
|
||||
rewards_id: Pubkey,
|
||||
rewards_id: &Pubkey,
|
||||
lamports: u64,
|
||||
) -> Result<()> {
|
||||
let blockhash = self.bank.last_blockhash();
|
||||
@ -31,7 +31,7 @@ impl<'a> RewardsBank<'a> {
|
||||
fn create_vote_account(
|
||||
&self,
|
||||
from_keypair: &Keypair,
|
||||
vote_id: Pubkey,
|
||||
vote_id: &Pubkey,
|
||||
lamports: u64,
|
||||
) -> Result<()> {
|
||||
let blockhash = self.bank.last_blockhash();
|
||||
@ -41,7 +41,7 @@ impl<'a> RewardsBank<'a> {
|
||||
|
||||
fn submit_vote(
|
||||
&self,
|
||||
staking_account: Pubkey,
|
||||
staking_account: &Pubkey,
|
||||
vote_keypair: &Keypair,
|
||||
tick_height: u64,
|
||||
) -> Result<VoteState> {
|
||||
@ -55,7 +55,7 @@ impl<'a> RewardsBank<'a> {
|
||||
Ok(VoteState::deserialize(&vote_account.userdata).unwrap())
|
||||
}
|
||||
|
||||
fn redeem_credits(&self, rewards_id: Pubkey, vote_keypair: &Keypair) -> Result<VoteState> {
|
||||
fn redeem_credits(&self, rewards_id: &Pubkey, vote_keypair: &Keypair) -> Result<VoteState> {
|
||||
let blockhash = self.bank.last_blockhash();
|
||||
let tx = RewardsTransaction::new_redeem_credits(&vote_keypair, rewards_id, blockhash, 0);
|
||||
self.bank.process_transaction(&tx)?;
|
||||
@ -74,26 +74,26 @@ fn test_redeem_vote_credits_via_bank() {
|
||||
let rewards_keypair = Keypair::new();
|
||||
let rewards_id = rewards_keypair.pubkey();
|
||||
rewards_bank
|
||||
.create_rewards_account(&from_keypair, rewards_id, 100)
|
||||
.create_rewards_account(&from_keypair, &rewards_id, 100)
|
||||
.unwrap();
|
||||
|
||||
// A staker create a vote account account and delegates a validator to vote on its behalf.
|
||||
let vote_keypair = Keypair::new();
|
||||
let vote_id = vote_keypair.pubkey();
|
||||
rewards_bank
|
||||
.create_vote_account(&from_keypair, vote_id, 100)
|
||||
.create_vote_account(&from_keypair, &vote_id, 100)
|
||||
.unwrap();
|
||||
|
||||
// The validator submits votes to accumulate credits.
|
||||
for i in 0..vote_state::MAX_LOCKOUT_HISTORY {
|
||||
let vote_state = rewards_bank
|
||||
.submit_vote(vote_id, &vote_keypair, i as u64)
|
||||
.submit_vote(&vote_id, &vote_keypair, i as u64)
|
||||
.unwrap();
|
||||
assert_eq!(vote_state.credits(), 0);
|
||||
}
|
||||
let vote_state = rewards_bank
|
||||
.submit_vote(
|
||||
vote_id,
|
||||
&vote_id,
|
||||
&vote_keypair,
|
||||
vote_state::MAX_LOCKOUT_HISTORY as u64 + 1,
|
||||
)
|
||||
@ -108,7 +108,7 @@ fn test_redeem_vote_credits_via_bank() {
|
||||
// Periodically, the staker sumbits its vote account to the rewards pool
|
||||
// to exchange its credits for lamports.
|
||||
let vote_state = rewards_bank
|
||||
.redeem_credits(rewards_id, &vote_keypair)
|
||||
.redeem_credits(&rewards_id, &vote_keypair)
|
||||
.unwrap();
|
||||
assert!(bank.get_balance(&to_id) > to_lamports);
|
||||
assert_eq!(vote_state.credits(), 0);
|
||||
|
@ -9,11 +9,11 @@ pub enum RewardsInstruction {
|
||||
}
|
||||
|
||||
impl RewardsInstruction {
|
||||
pub fn new_redeem_vote_credits(vote_id: Pubkey, rewards_id: Pubkey) -> BuilderInstruction {
|
||||
pub fn new_redeem_vote_credits(vote_id: &Pubkey, rewards_id: &Pubkey) -> BuilderInstruction {
|
||||
BuilderInstruction::new(
|
||||
id(),
|
||||
&RewardsInstruction::RedeemVoteCredits,
|
||||
vec![(vote_id, true), (rewards_id, false)],
|
||||
vec![(*vote_id, true), (*rewards_id, false)],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ pub struct RewardsTransaction {}
|
||||
impl RewardsTransaction {
|
||||
pub fn new_account(
|
||||
from_keypair: &Keypair,
|
||||
rewards_id: Pubkey,
|
||||
rewards_id: &Pubkey,
|
||||
blockhash: Hash,
|
||||
lamports: u64,
|
||||
fee: u64,
|
||||
@ -28,23 +28,23 @@ impl RewardsTransaction {
|
||||
blockhash,
|
||||
lamports,
|
||||
RewardsState::max_size() as u64,
|
||||
id(),
|
||||
&id(),
|
||||
fee,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn new_redeem_credits(
|
||||
vote_keypair: &Keypair,
|
||||
rewards_id: Pubkey,
|
||||
rewards_id: &Pubkey,
|
||||
blockhash: Hash,
|
||||
fee: u64,
|
||||
) -> Transaction {
|
||||
let vote_id = vote_keypair.pubkey();
|
||||
TransactionBuilder::new(fee)
|
||||
.push(RewardsInstruction::new_redeem_vote_credits(
|
||||
vote_id, rewards_id,
|
||||
&vote_id, rewards_id,
|
||||
))
|
||||
.push(VoteInstruction::new_clear_credits(vote_id))
|
||||
.push(VoteInstruction::new_clear_credits(&vote_id))
|
||||
.sign(&[vote_keypair], blockhash)
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||
use solana_sdk::system_transaction::SystemTransaction;
|
||||
use solana_storage_api::{StorageTransaction, ENTRIES_PER_SEGMENT};
|
||||
|
||||
fn get_storage_entry_height(bank: &Bank, account: Pubkey) -> u64 {
|
||||
fn get_storage_entry_height(bank: &Bank, account: &Pubkey) -> u64 {
|
||||
match bank.get_account(&account) {
|
||||
Some(storage_system_account) => {
|
||||
let state = deserialize(&storage_system_account.userdata);
|
||||
@ -24,7 +24,7 @@ fn get_storage_entry_height(bank: &Bank, account: Pubkey) -> u64 {
|
||||
0
|
||||
}
|
||||
|
||||
fn get_storage_blockhash(bank: &Bank, account: Pubkey) -> Hash {
|
||||
fn get_storage_blockhash(bank: &Bank, account: &Pubkey) -> Hash {
|
||||
if let Some(storage_system_account) = bank.get_account(&account) {
|
||||
let state = deserialize(&storage_system_account.userdata);
|
||||
if let Ok(state) = state {
|
||||
@ -51,18 +51,20 @@ fn test_bank_storage() {
|
||||
|
||||
bank.register_tick(&blockhash);
|
||||
|
||||
bank.transfer(10, &alice, jill.pubkey(), blockhash).unwrap();
|
||||
bank.transfer(10, &alice, &jill.pubkey(), blockhash)
|
||||
.unwrap();
|
||||
|
||||
bank.transfer(10, &alice, bob.pubkey(), blockhash).unwrap();
|
||||
bank.transfer(10, &alice, jack.pubkey(), blockhash).unwrap();
|
||||
bank.transfer(10, &alice, &bob.pubkey(), blockhash).unwrap();
|
||||
bank.transfer(10, &alice, &jack.pubkey(), blockhash)
|
||||
.unwrap();
|
||||
|
||||
let tx = SystemTransaction::new_program_account(
|
||||
&alice,
|
||||
bob.pubkey(),
|
||||
&bob.pubkey(),
|
||||
blockhash,
|
||||
1,
|
||||
4 * 1024,
|
||||
solana_storage_api::id(),
|
||||
&solana_storage_api::id(),
|
||||
0,
|
||||
);
|
||||
|
||||
@ -90,11 +92,11 @@ fn test_bank_storage() {
|
||||
//let _result = bank.process_transaction(&tx).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
get_storage_entry_height(&bank, bob.pubkey()),
|
||||
get_storage_entry_height(&bank, &bob.pubkey()),
|
||||
ENTRIES_PER_SEGMENT
|
||||
);
|
||||
assert_eq!(
|
||||
get_storage_blockhash(&bank, bob.pubkey()),
|
||||
get_storage_blockhash(&bank, &bob.pubkey()),
|
||||
storage_blockhash
|
||||
);
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ impl StorageTransaction {
|
||||
entry_height,
|
||||
signature,
|
||||
};
|
||||
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
|
||||
Transaction::new(from_keypair, &[], &id(), &program, recent_blockhash, 0)
|
||||
}
|
||||
|
||||
pub fn new_advertise_recent_blockhash(
|
||||
@ -103,7 +103,7 @@ impl StorageTransaction {
|
||||
hash: storage_hash,
|
||||
entry_height,
|
||||
};
|
||||
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
|
||||
Transaction::new(from_keypair, &[], &id(), &program, recent_blockhash, 0)
|
||||
}
|
||||
|
||||
pub fn new_proof_validation(
|
||||
@ -116,7 +116,7 @@ impl StorageTransaction {
|
||||
entry_height,
|
||||
proof_mask,
|
||||
};
|
||||
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
|
||||
Transaction::new(from_keypair, &[], &id(), &program, recent_blockhash, 0)
|
||||
}
|
||||
|
||||
pub fn new_reward_claim(
|
||||
@ -125,6 +125,6 @@ impl StorageTransaction {
|
||||
entry_height: u64,
|
||||
) -> Transaction {
|
||||
let program = StorageProgram::ClaimStorageReward { entry_height };
|
||||
Transaction::new(from_keypair, &[], id(), &program, recent_blockhash, 0)
|
||||
Transaction::new(from_keypair, &[], &id(), &program, recent_blockhash, 0)
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ fn create_system_account(
|
||||
keyed_accounts: &mut [KeyedAccount],
|
||||
lamports: u64,
|
||||
space: u64,
|
||||
program_id: Pubkey,
|
||||
program_id: &Pubkey,
|
||||
) -> Result<(), SystemError> {
|
||||
if !system_program::check_id(&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner) {
|
||||
info!("CreateAccount: invalid account[from] owner");
|
||||
@ -44,7 +44,7 @@ fn create_system_account(
|
||||
}
|
||||
keyed_accounts[FROM_ACCOUNT_INDEX].account.lamports -= lamports;
|
||||
keyed_accounts[TO_ACCOUNT_INDEX].account.lamports += lamports;
|
||||
keyed_accounts[TO_ACCOUNT_INDEX].account.owner = program_id;
|
||||
keyed_accounts[TO_ACCOUNT_INDEX].account.owner = *program_id;
|
||||
keyed_accounts[TO_ACCOUNT_INDEX].account.userdata = vec![0; space as usize];
|
||||
keyed_accounts[TO_ACCOUNT_INDEX].account.executable = false;
|
||||
Ok(())
|
||||
@ -52,12 +52,12 @@ fn create_system_account(
|
||||
|
||||
fn assign_account_to_program(
|
||||
keyed_accounts: &mut [KeyedAccount],
|
||||
program_id: Pubkey,
|
||||
program_id: &Pubkey,
|
||||
) -> Result<(), ProgramError> {
|
||||
if !system_program::check_id(&keyed_accounts[FROM_ACCOUNT_INDEX].account.owner) {
|
||||
Err(ProgramError::AssignOfUnownedAccount)?;
|
||||
}
|
||||
keyed_accounts[FROM_ACCOUNT_INDEX].account.owner = program_id;
|
||||
keyed_accounts[FROM_ACCOUNT_INDEX].account.owner = *program_id;
|
||||
Ok(())
|
||||
}
|
||||
fn move_lamports(keyed_accounts: &mut [KeyedAccount], lamports: u64) -> Result<(), ProgramError> {
|
||||
@ -94,7 +94,7 @@ pub fn entrypoint(
|
||||
lamports,
|
||||
space,
|
||||
program_id,
|
||||
} => create_system_account(keyed_accounts, lamports, space, program_id).map_err(|e| {
|
||||
} => create_system_account(keyed_accounts, lamports, space, &program_id).map_err(|e| {
|
||||
match e {
|
||||
SystemError::AccountAlreadyInUse => ProgramError::InvalidArgument,
|
||||
SystemError::ResultWithNegativeLamports => {
|
||||
@ -104,7 +104,7 @@ pub fn entrypoint(
|
||||
}
|
||||
}),
|
||||
SystemInstruction::Assign { program_id } => {
|
||||
assign_account_to_program(keyed_accounts, program_id)
|
||||
assign_account_to_program(keyed_accounts, &program_id)
|
||||
}
|
||||
SystemInstruction::Move { lamports } => move_lamports(keyed_accounts, lamports),
|
||||
}
|
||||
@ -124,16 +124,16 @@ mod tests {
|
||||
fn test_create_system_account() {
|
||||
let new_program_owner = Pubkey::new(&[9; 32]);
|
||||
let from = Keypair::new().pubkey();
|
||||
let mut from_account = Account::new(100, 0, system_program::id());
|
||||
let mut from_account = Account::new(100, 0, &system_program::id());
|
||||
|
||||
let to = Keypair::new().pubkey();
|
||||
let mut to_account = Account::new(0, 0, Pubkey::default());
|
||||
let mut to_account = Account::new(0, 0, &Pubkey::default());
|
||||
|
||||
let mut keyed_accounts = [
|
||||
KeyedAccount::new(&from, true, &mut from_account),
|
||||
KeyedAccount::new(&to, false, &mut to_account),
|
||||
];
|
||||
create_system_account(&mut keyed_accounts, 50, 2, new_program_owner).unwrap();
|
||||
create_system_account(&mut keyed_accounts, 50, 2, &new_program_owner).unwrap();
|
||||
let from_lamports = from_account.lamports;
|
||||
let to_lamports = to_account.lamports;
|
||||
let to_owner = to_account.owner;
|
||||
@ -149,17 +149,17 @@ mod tests {
|
||||
// Attempt to create account with more lamports than remaining in from_account
|
||||
let new_program_owner = Pubkey::new(&[9; 32]);
|
||||
let from = Keypair::new().pubkey();
|
||||
let mut from_account = Account::new(100, 0, system_program::id());
|
||||
let mut from_account = Account::new(100, 0, &system_program::id());
|
||||
|
||||
let to = Keypair::new().pubkey();
|
||||
let mut to_account = Account::new(0, 0, Pubkey::default());
|
||||
let mut to_account = Account::new(0, 0, &Pubkey::default());
|
||||
let unchanged_account = to_account.clone();
|
||||
|
||||
let mut keyed_accounts = [
|
||||
KeyedAccount::new(&from, true, &mut from_account),
|
||||
KeyedAccount::new(&to, false, &mut to_account),
|
||||
];
|
||||
let result = create_system_account(&mut keyed_accounts, 150, 2, new_program_owner);
|
||||
let result = create_system_account(&mut keyed_accounts, 150, 2, &new_program_owner);
|
||||
assert_eq!(result, Err(SystemError::ResultWithNegativeLamports));
|
||||
let from_lamports = from_account.lamports;
|
||||
assert_eq!(from_lamports, 100);
|
||||
@ -171,18 +171,18 @@ mod tests {
|
||||
// Attempt to create system account in account already owned by another program
|
||||
let new_program_owner = Pubkey::new(&[9; 32]);
|
||||
let from = Keypair::new().pubkey();
|
||||
let mut from_account = Account::new(100, 0, system_program::id());
|
||||
let mut from_account = Account::new(100, 0, &system_program::id());
|
||||
|
||||
let original_program_owner = Pubkey::new(&[5; 32]);
|
||||
let owned_key = Keypair::new().pubkey();
|
||||
let mut owned_account = Account::new(0, 0, original_program_owner);
|
||||
let mut owned_account = Account::new(0, 0, &original_program_owner);
|
||||
let unchanged_account = owned_account.clone();
|
||||
|
||||
let mut keyed_accounts = [
|
||||
KeyedAccount::new(&from, true, &mut from_account),
|
||||
KeyedAccount::new(&owned_key, false, &mut owned_account),
|
||||
];
|
||||
let result = create_system_account(&mut keyed_accounts, 50, 2, new_program_owner);
|
||||
let result = create_system_account(&mut keyed_accounts, 50, 2, &new_program_owner);
|
||||
assert_eq!(result, Err(SystemError::AccountAlreadyInUse));
|
||||
let from_lamports = from_account.lamports;
|
||||
assert_eq!(from_lamports, 100);
|
||||
@ -194,7 +194,7 @@ mod tests {
|
||||
// Attempt to create system account in account with populated userdata
|
||||
let new_program_owner = Pubkey::new(&[9; 32]);
|
||||
let from = Keypair::new().pubkey();
|
||||
let mut from_account = Account::new(100, 0, system_program::id());
|
||||
let mut from_account = Account::new(100, 0, &system_program::id());
|
||||
|
||||
let populated_key = Keypair::new().pubkey();
|
||||
let mut populated_account = Account {
|
||||
@ -209,7 +209,7 @@ mod tests {
|
||||
KeyedAccount::new(&from, true, &mut from_account),
|
||||
KeyedAccount::new(&populated_key, false, &mut populated_account),
|
||||
];
|
||||
let result = create_system_account(&mut keyed_accounts, 50, 2, new_program_owner);
|
||||
let result = create_system_account(&mut keyed_accounts, 50, 2, &new_program_owner);
|
||||
assert_eq!(result, Err(SystemError::AccountAlreadyInUse));
|
||||
assert_eq!(from_account.lamports, 100);
|
||||
assert_eq!(populated_account, unchanged_account);
|
||||
@ -220,14 +220,14 @@ mod tests {
|
||||
let other_program = Pubkey::new(&[9; 32]);
|
||||
|
||||
let from = Keypair::new().pubkey();
|
||||
let mut from_account = Account::new(100, 0, other_program);
|
||||
let mut from_account = Account::new(100, 0, &other_program);
|
||||
let to = Keypair::new().pubkey();
|
||||
let mut to_account = Account::new(0, 0, Pubkey::default());
|
||||
let mut to_account = Account::new(0, 0, &Pubkey::default());
|
||||
let mut keyed_accounts = [
|
||||
KeyedAccount::new(&from, true, &mut from_account),
|
||||
KeyedAccount::new(&to, false, &mut to_account),
|
||||
];
|
||||
let result = create_system_account(&mut keyed_accounts, 50, 2, other_program);
|
||||
let result = create_system_account(&mut keyed_accounts, 50, 2, &other_program);
|
||||
assert_eq!(result, Err(SystemError::SourceNotSystemAccount));
|
||||
}
|
||||
|
||||
@ -236,16 +236,16 @@ mod tests {
|
||||
let new_program_owner = Pubkey::new(&[9; 32]);
|
||||
|
||||
let from = Keypair::new().pubkey();
|
||||
let mut from_account = Account::new(100, 0, system_program::id());
|
||||
let mut from_account = Account::new(100, 0, &system_program::id());
|
||||
let mut keyed_accounts = [KeyedAccount::new(&from, true, &mut from_account)];
|
||||
assign_account_to_program(&mut keyed_accounts, new_program_owner).unwrap();
|
||||
assign_account_to_program(&mut keyed_accounts, &new_program_owner).unwrap();
|
||||
let from_owner = from_account.owner;
|
||||
assert_eq!(from_owner, new_program_owner);
|
||||
|
||||
// Attempt to assign account not owned by system program
|
||||
let another_program_owner = Pubkey::new(&[8; 32]);
|
||||
keyed_accounts = [KeyedAccount::new(&from, true, &mut from_account)];
|
||||
let result = assign_account_to_program(&mut keyed_accounts, another_program_owner);
|
||||
let result = assign_account_to_program(&mut keyed_accounts, &another_program_owner);
|
||||
assert_eq!(result, Err(ProgramError::AssignOfUnownedAccount));
|
||||
assert_eq!(from_account.owner, new_program_owner);
|
||||
}
|
||||
@ -253,9 +253,9 @@ mod tests {
|
||||
#[test]
|
||||
fn test_move_lamports() {
|
||||
let from = Keypair::new().pubkey();
|
||||
let mut from_account = Account::new(100, 0, Pubkey::new(&[2; 32])); // account owner should not matter
|
||||
let mut from_account = Account::new(100, 0, &Pubkey::new(&[2; 32])); // account owner should not matter
|
||||
let to = Keypair::new().pubkey();
|
||||
let mut to_account = Account::new(1, 0, Pubkey::new(&[3; 32])); // account owner should not matter
|
||||
let mut to_account = Account::new(1, 0, &Pubkey::new(&[3; 32])); // account owner should not matter
|
||||
let mut keyed_accounts = [
|
||||
KeyedAccount::new(&from, true, &mut from_account),
|
||||
KeyedAccount::new(&to, false, &mut to_account),
|
||||
|
@ -27,8 +27,8 @@ fn test_system_unsigned_transaction() {
|
||||
let blockhash = system_bank.bank.last_blockhash();
|
||||
let tx = TransactionBuilder::default()
|
||||
.push(SystemInstruction::new_move(
|
||||
from_keypair.pubkey(),
|
||||
to_keypair.pubkey(),
|
||||
&from_keypair.pubkey(),
|
||||
&to_keypair.pubkey(),
|
||||
50,
|
||||
))
|
||||
.sign(&[&from_keypair], blockhash);
|
||||
|
@ -25,10 +25,10 @@ fn entrypoint(
|
||||
match deserialize(data).map_err(|_| ProgramError::InvalidUserdata)? {
|
||||
VoteInstruction::InitializeAccount => vote_state::initialize_account(keyed_accounts),
|
||||
VoteInstruction::DelegateStake(delegate_id) => {
|
||||
vote_state::delegate_stake(keyed_accounts, delegate_id)
|
||||
vote_state::delegate_stake(keyed_accounts, &delegate_id)
|
||||
}
|
||||
VoteInstruction::AuthorizeVoter(voter_id) => {
|
||||
vote_state::authorize_voter(keyed_accounts, voter_id)
|
||||
vote_state::authorize_voter(keyed_accounts, &voter_id)
|
||||
}
|
||||
VoteInstruction::Vote(vote) => {
|
||||
debug!("{:?} by {}", vote, keyed_accounts[0].signer_key().unwrap());
|
||||
|
@ -24,7 +24,7 @@ impl<'a> VoteBank<'a> {
|
||||
fn create_vote_account(
|
||||
&self,
|
||||
from_keypair: &Keypair,
|
||||
vote_id: Pubkey,
|
||||
vote_id: &Pubkey,
|
||||
lamports: u64,
|
||||
) -> Result<()> {
|
||||
let blockhash = self.bank.last_blockhash();
|
||||
@ -36,7 +36,7 @@ impl<'a> VoteBank<'a> {
|
||||
&self,
|
||||
from_keypair: &Keypair,
|
||||
vote_keypair: &Keypair,
|
||||
delegate_id: Pubkey,
|
||||
delegate_id: &Pubkey,
|
||||
lamports: u64,
|
||||
) -> Result<()> {
|
||||
let blockhash = self.bank.last_blockhash();
|
||||
@ -53,7 +53,7 @@ impl<'a> VoteBank<'a> {
|
||||
|
||||
fn submit_vote(
|
||||
&self,
|
||||
staking_account: Pubkey,
|
||||
staking_account: &Pubkey,
|
||||
vote_keypair: &Keypair,
|
||||
tick_height: u64,
|
||||
) -> Result<VoteState> {
|
||||
@ -77,10 +77,10 @@ fn test_vote_bank_basic() {
|
||||
let vote_keypair = Keypair::new();
|
||||
let vote_id = vote_keypair.pubkey();
|
||||
vote_bank
|
||||
.create_vote_account(&from_keypair, vote_id, 100)
|
||||
.create_vote_account(&from_keypair, &vote_id, 100)
|
||||
.unwrap();
|
||||
|
||||
let vote_state = vote_bank.submit_vote(vote_id, &vote_keypair, 0).unwrap();
|
||||
let vote_state = vote_bank.submit_vote(&vote_id, &vote_keypair, 0).unwrap();
|
||||
assert_eq!(vote_state.votes.len(), 1);
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ fn test_vote_bank_delegate() {
|
||||
let delegate_keypair = Keypair::new();
|
||||
let delegate_id = delegate_keypair.pubkey();
|
||||
vote_bank
|
||||
.create_vote_account_with_delegate(&from_keypair, &vote_keypair, delegate_id, 100)
|
||||
.create_vote_account_with_delegate(&from_keypair, &vote_keypair, &delegate_id, 100)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ fn test_vote_via_bank_with_no_signature() {
|
||||
let vote_keypair = Keypair::new();
|
||||
let vote_id = vote_keypair.pubkey();
|
||||
vote_bank
|
||||
.create_vote_account(&mallory_keypair, vote_id, 100)
|
||||
.create_vote_account(&mallory_keypair, &vote_id, 100)
|
||||
.unwrap();
|
||||
|
||||
let mallory_id = mallory_keypair.pubkey();
|
||||
@ -121,7 +121,7 @@ fn test_vote_via_bank_with_no_signature() {
|
||||
// the 0th account in the second instruction is not! The program
|
||||
// needs to check that it's signed.
|
||||
let tx = TransactionBuilder::default()
|
||||
.push(SystemInstruction::new_move(mallory_id, vote_id, 1))
|
||||
.push(SystemInstruction::new_move(&mallory_id, &vote_id, 1))
|
||||
.push(vote_ix)
|
||||
.sign(&[&mallory_keypair], blockhash);
|
||||
|
||||
|
@ -32,31 +32,34 @@ pub enum VoteInstruction {
|
||||
}
|
||||
|
||||
impl VoteInstruction {
|
||||
pub fn new_clear_credits(vote_id: Pubkey) -> BuilderInstruction {
|
||||
BuilderInstruction::new(id(), &VoteInstruction::ClearCredits, vec![(vote_id, true)])
|
||||
pub fn new_clear_credits(vote_id: &Pubkey) -> BuilderInstruction {
|
||||
BuilderInstruction::new(id(), &VoteInstruction::ClearCredits, vec![(*vote_id, true)])
|
||||
}
|
||||
pub fn new_delegate_stake(vote_id: Pubkey, delegate_id: Pubkey) -> BuilderInstruction {
|
||||
pub fn new_delegate_stake(vote_id: &Pubkey, delegate_id: &Pubkey) -> BuilderInstruction {
|
||||
BuilderInstruction::new(
|
||||
id(),
|
||||
&VoteInstruction::DelegateStake(delegate_id),
|
||||
vec![(vote_id, true)],
|
||||
&VoteInstruction::DelegateStake(*delegate_id),
|
||||
vec![(*vote_id, true)],
|
||||
)
|
||||
}
|
||||
pub fn new_authorize_voter(vote_id: Pubkey, authorized_voter_id: Pubkey) -> BuilderInstruction {
|
||||
pub fn new_authorize_voter(
|
||||
vote_id: &Pubkey,
|
||||
authorized_voter_id: &Pubkey,
|
||||
) -> BuilderInstruction {
|
||||
BuilderInstruction::new(
|
||||
id(),
|
||||
&VoteInstruction::AuthorizeVoter(authorized_voter_id),
|
||||
vec![(vote_id, true)],
|
||||
&VoteInstruction::AuthorizeVoter(*authorized_voter_id),
|
||||
vec![(*vote_id, true)],
|
||||
)
|
||||
}
|
||||
pub fn new_initialize_account(vote_id: Pubkey) -> BuilderInstruction {
|
||||
pub fn new_initialize_account(vote_id: &Pubkey) -> BuilderInstruction {
|
||||
BuilderInstruction::new(
|
||||
id(),
|
||||
&VoteInstruction::InitializeAccount,
|
||||
vec![(vote_id, false)],
|
||||
vec![(*vote_id, false)],
|
||||
)
|
||||
}
|
||||
pub fn new_vote(vote_id: Pubkey, vote: Vote) -> BuilderInstruction {
|
||||
BuilderInstruction::new(id(), &VoteInstruction::Vote(vote), vec![(vote_id, true)])
|
||||
pub fn new_vote(vote_id: &Pubkey, vote: Vote) -> BuilderInstruction {
|
||||
BuilderInstruction::new(id(), &VoteInstruction::Vote(vote), vec![(*vote_id, true)])
|
||||
}
|
||||
}
|
||||
|
@ -51,14 +51,14 @@ pub struct VoteState {
|
||||
}
|
||||
|
||||
impl VoteState {
|
||||
pub fn new(staker_id: Pubkey) -> Self {
|
||||
pub fn new(staker_id: &Pubkey) -> Self {
|
||||
let votes = VecDeque::new();
|
||||
let credits = 0;
|
||||
let root_slot = None;
|
||||
Self {
|
||||
votes,
|
||||
delegate_id: staker_id,
|
||||
authorized_voter_id: staker_id,
|
||||
delegate_id: *staker_id,
|
||||
authorized_voter_id: *staker_id,
|
||||
credits,
|
||||
root_slot,
|
||||
}
|
||||
@ -151,7 +151,7 @@ impl VoteState {
|
||||
|
||||
pub fn delegate_stake(
|
||||
keyed_accounts: &mut [KeyedAccount],
|
||||
node_id: Pubkey,
|
||||
node_id: &Pubkey,
|
||||
) -> Result<(), ProgramError> {
|
||||
if !check_id(&keyed_accounts[0].account.owner) {
|
||||
error!("account[0] is not assigned to the VOTE_PROGRAM");
|
||||
@ -165,7 +165,7 @@ pub fn delegate_stake(
|
||||
|
||||
let vote_state = VoteState::deserialize(&keyed_accounts[0].account.userdata);
|
||||
if let Ok(mut vote_state) = vote_state {
|
||||
vote_state.delegate_id = node_id;
|
||||
vote_state.delegate_id = *node_id;
|
||||
vote_state.serialize(&mut keyed_accounts[0].account.userdata)?;
|
||||
} else {
|
||||
error!("account[0] does not valid userdata");
|
||||
@ -180,7 +180,7 @@ pub fn delegate_stake(
|
||||
/// voter. The default voter is the owner of the vote account's pubkey.
|
||||
pub fn authorize_voter(
|
||||
keyed_accounts: &mut [KeyedAccount],
|
||||
voter_id: Pubkey,
|
||||
voter_id: &Pubkey,
|
||||
) -> Result<(), ProgramError> {
|
||||
if !check_id(&keyed_accounts[0].account.owner) {
|
||||
error!("account[0] is not assigned to the VOTE_PROGRAM");
|
||||
@ -194,7 +194,7 @@ pub fn authorize_voter(
|
||||
|
||||
let vote_state = VoteState::deserialize(&keyed_accounts[0].account.userdata);
|
||||
if let Ok(mut vote_state) = vote_state {
|
||||
vote_state.authorized_voter_id = voter_id;
|
||||
vote_state.authorized_voter_id = *voter_id;
|
||||
vote_state.serialize(&mut keyed_accounts[0].account.userdata)?;
|
||||
} else {
|
||||
error!("account[0] does not valid userdata");
|
||||
@ -217,7 +217,7 @@ pub fn initialize_account(keyed_accounts: &mut [KeyedAccount]) -> Result<(), Pro
|
||||
let vote_state = VoteState::deserialize(&keyed_accounts[0].account.userdata);
|
||||
if let Ok(vote_state) = vote_state {
|
||||
if vote_state.delegate_id == Pubkey::default() {
|
||||
let vote_state = VoteState::new(*staker_id);
|
||||
let vote_state = VoteState::new(staker_id);
|
||||
vote_state.serialize(&mut keyed_accounts[0].account.userdata)?;
|
||||
} else {
|
||||
error!("account[0] userdata already initialized");
|
||||
@ -274,7 +274,7 @@ pub fn clear_credits(keyed_accounts: &mut [KeyedAccount]) -> Result<(), ProgramE
|
||||
|
||||
pub fn create_vote_account(lamports: u64) -> Account {
|
||||
let space = VoteState::max_size();
|
||||
Account::new(lamports, space, id())
|
||||
Account::new(lamports, space, &id())
|
||||
}
|
||||
|
||||
pub fn initialize_and_deserialize(
|
||||
@ -309,7 +309,7 @@ mod tests {
|
||||
let mut vote_account = create_vote_account(100);
|
||||
|
||||
let bogus_account_id = Keypair::new().pubkey();
|
||||
let mut bogus_account = Account::new(100, 0, id());
|
||||
let mut bogus_account = Account::new(100, 0, &id());
|
||||
|
||||
let mut keyed_accounts = [KeyedAccount::new(
|
||||
&bogus_account_id,
|
||||
@ -385,7 +385,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_vote_lockout() {
|
||||
let voter_id = Keypair::new().pubkey();
|
||||
let mut vote_state = VoteState::new(voter_id);
|
||||
let mut vote_state = VoteState::new(&voter_id);
|
||||
|
||||
for i in 0..(MAX_LOCKOUT_HISTORY + 1) {
|
||||
vote_state.process_vote(Vote::new((INITIAL_LOCKOUT as usize * i) as u64));
|
||||
@ -415,7 +415,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_vote_double_lockout_after_expiration() {
|
||||
let voter_id = Keypair::new().pubkey();
|
||||
let mut vote_state = VoteState::new(voter_id);
|
||||
let mut vote_state = VoteState::new(&voter_id);
|
||||
|
||||
for i in 0..3 {
|
||||
let vote = Vote::new(i as u64);
|
||||
@ -441,7 +441,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_vote_credits() {
|
||||
let voter_id = Keypair::new().pubkey();
|
||||
let mut vote_state = VoteState::new(voter_id);
|
||||
let mut vote_state = VoteState::new(&voter_id);
|
||||
|
||||
for i in 0..MAX_LOCKOUT_HISTORY {
|
||||
vote_state.process_vote(Vote::new(i as u64));
|
||||
|
@ -15,7 +15,7 @@ pub struct VoteTransaction {}
|
||||
|
||||
impl VoteTransaction {
|
||||
pub fn new_vote<T: KeypairUtil>(
|
||||
staking_account: Pubkey,
|
||||
staking_account: &Pubkey,
|
||||
authorized_voter_keypair: &T,
|
||||
slot: u64,
|
||||
recent_blockhash: Hash,
|
||||
@ -30,7 +30,7 @@ impl VoteTransaction {
|
||||
/// Fund or create the staking account with lamports
|
||||
pub fn new_account(
|
||||
from_keypair: &Keypair,
|
||||
staker_id: Pubkey,
|
||||
staker_id: &Pubkey,
|
||||
recent_blockhash: Hash,
|
||||
lamports: u64,
|
||||
fee: u64,
|
||||
@ -39,11 +39,11 @@ impl VoteTransaction {
|
||||
let space = VoteState::max_size() as u64;
|
||||
TransactionBuilder::new(fee)
|
||||
.push(SystemInstruction::new_program_account(
|
||||
from_id,
|
||||
&from_id,
|
||||
staker_id,
|
||||
lamports,
|
||||
space,
|
||||
id(),
|
||||
&id(),
|
||||
))
|
||||
.push(VoteInstruction::new_initialize_account(staker_id))
|
||||
.sign(&[from_keypair], recent_blockhash)
|
||||
@ -53,7 +53,7 @@ impl VoteTransaction {
|
||||
pub fn new_account_with_delegate(
|
||||
from_keypair: &Keypair,
|
||||
voter_keypair: &Keypair,
|
||||
delegate_id: Pubkey,
|
||||
delegate_id: &Pubkey,
|
||||
recent_blockhash: Hash,
|
||||
lamports: u64,
|
||||
fee: u64,
|
||||
@ -63,14 +63,14 @@ impl VoteTransaction {
|
||||
let space = VoteState::max_size() as u64;
|
||||
TransactionBuilder::new(fee)
|
||||
.push(SystemInstruction::new_program_account(
|
||||
from_id,
|
||||
voter_id,
|
||||
&from_id,
|
||||
&voter_id,
|
||||
lamports,
|
||||
space,
|
||||
id(),
|
||||
&id(),
|
||||
))
|
||||
.push(VoteInstruction::new_initialize_account(voter_id))
|
||||
.push(VoteInstruction::new_delegate_stake(voter_id, delegate_id))
|
||||
.push(VoteInstruction::new_initialize_account(&voter_id))
|
||||
.push(VoteInstruction::new_delegate_stake(&voter_id, &delegate_id))
|
||||
.sign(&[from_keypair, voter_keypair], recent_blockhash)
|
||||
}
|
||||
|
||||
@ -78,12 +78,12 @@ impl VoteTransaction {
|
||||
pub fn new_authorize_voter(
|
||||
vote_keypair: &Keypair,
|
||||
recent_blockhash: Hash,
|
||||
authorized_voter_id: Pubkey,
|
||||
authorized_voter_id: &Pubkey,
|
||||
fee: u64,
|
||||
) -> Transaction {
|
||||
TransactionBuilder::new(fee)
|
||||
.push(VoteInstruction::new_authorize_voter(
|
||||
vote_keypair.pubkey(),
|
||||
&vote_keypair.pubkey(),
|
||||
authorized_voter_id,
|
||||
))
|
||||
.sign(&[vote_keypair], recent_blockhash)
|
||||
@ -93,12 +93,12 @@ impl VoteTransaction {
|
||||
pub fn delegate_vote_account<T: KeypairUtil>(
|
||||
vote_keypair: &T,
|
||||
recent_blockhash: Hash,
|
||||
node_id: Pubkey,
|
||||
node_id: &Pubkey,
|
||||
fee: u64,
|
||||
) -> Transaction {
|
||||
TransactionBuilder::new(fee)
|
||||
.push(VoteInstruction::new_delegate_stake(
|
||||
vote_keypair.pubkey(),
|
||||
&vote_keypair.pubkey(),
|
||||
node_id,
|
||||
))
|
||||
.sign(&[vote_keypair], recent_blockhash)
|
||||
@ -133,7 +133,7 @@ mod tests {
|
||||
let slot = 1;
|
||||
let recent_blockhash = Hash::default();
|
||||
let transaction =
|
||||
VoteTransaction::new_vote(keypair.pubkey(), &keypair, slot, recent_blockhash, 0);
|
||||
VoteTransaction::new_vote(&keypair.pubkey(), &keypair, slot, recent_blockhash, 0);
|
||||
assert_eq!(
|
||||
VoteTransaction::get_votes(&transaction),
|
||||
vec![(keypair.pubkey(), Vote::new(slot), recent_blockhash)]
|
||||
|
Reference in New Issue
Block a user