Replace transaction traits with structs
Also: * SystemTransaction::new -> new_account * SystemTransaction::new_create -> new_program_account
This commit is contained in:
parent
1b3e7f734a
commit
dad0bfe447
|
@ -190,7 +190,7 @@ pub fn generate_txs(
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map(|(id, keypair)| {
|
.map(|(id, keypair)| {
|
||||||
(
|
(
|
||||||
Transaction::system_new(id, keypair.pubkey(), 1, last_id),
|
SystemTransaction::new_account(id, keypair.pubkey(), 1, last_id, 0),
|
||||||
timestamp(),
|
timestamp(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -342,7 +342,7 @@ pub fn fund_keys(client: &mut ThinClient, source: &Keypair, dests: &[Keypair], t
|
||||||
.map(|(k, m)| {
|
.map(|(k, m)| {
|
||||||
(
|
(
|
||||||
k.clone(),
|
k.clone(),
|
||||||
Transaction::system_move_many(k, &m, Default::default(), 0),
|
SystemTransaction::new_move_many(k, &m, Default::default(), 0),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -8,7 +8,6 @@ use solana::last_id_queue::MAX_ENTRY_IDS;
|
||||||
use solana_sdk::hash::hash;
|
use solana_sdk::hash::hash;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
|
@ -22,13 +21,18 @@ fn bench_process_transaction(bencher: &mut Bencher) {
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
// Seed the 'from' account.
|
// Seed the 'from' account.
|
||||||
let rando0 = Keypair::new();
|
let rando0 = Keypair::new();
|
||||||
let tx =
|
let tx = SystemTransaction::new_move(
|
||||||
Transaction::system_move(&mint_keypair, rando0.pubkey(), 10_000, bank.last_id(), 0);
|
&mint_keypair,
|
||||||
|
rando0.pubkey(),
|
||||||
|
10_000,
|
||||||
|
bank.last_id(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
|
|
||||||
// Seed the 'to' account and a cell for its signature.
|
// Seed the 'to' account and a cell for its signature.
|
||||||
let rando1 = Keypair::new();
|
let rando1 = Keypair::new();
|
||||||
let tx = Transaction::system_move(&rando0, rando1.pubkey(), 1, bank.last_id(), 0);
|
let tx = SystemTransaction::new_move(&rando0, rando1.pubkey(), 1, bank.last_id(), 0);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
|
|
||||||
// Finally, return the transaction to the benchmark.
|
// Finally, return the transaction to the benchmark.
|
||||||
|
|
|
@ -14,7 +14,6 @@ use solana_sdk::hash::hash;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::sync::mpsc::{channel, Receiver};
|
use std::sync::mpsc::{channel, Receiver};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -50,7 +49,7 @@ fn bench_banking_stage_multi_accounts(bencher: &mut Bencher) {
|
||||||
let (verified_sender, verified_receiver) = channel();
|
let (verified_sender, verified_receiver) = channel();
|
||||||
let bank = Arc::new(Bank::new(&genesis_block));
|
let bank = Arc::new(Bank::new(&genesis_block));
|
||||||
let dummy_leader_id = Keypair::new().pubkey();
|
let dummy_leader_id = Keypair::new().pubkey();
|
||||||
let dummy = Transaction::system_move(
|
let dummy = SystemTransaction::new_move(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
mint_keypair.pubkey(),
|
mint_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -72,7 +71,7 @@ fn bench_banking_stage_multi_accounts(bencher: &mut Bencher) {
|
||||||
.collect();
|
.collect();
|
||||||
// fund all the accounts
|
// fund all the accounts
|
||||||
transactions.iter().for_each(|tx| {
|
transactions.iter().for_each(|tx| {
|
||||||
let fund = Transaction::system_move(
|
let fund = SystemTransaction::new_move(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
tx.account_keys[0],
|
tx.account_keys[0],
|
||||||
mint_total / txes as u64,
|
mint_total / txes as u64,
|
||||||
|
@ -145,7 +144,7 @@ fn bench_banking_stage_multi_programs(bencher: &mut Bencher) {
|
||||||
let (verified_sender, verified_receiver) = channel();
|
let (verified_sender, verified_receiver) = channel();
|
||||||
let bank = Arc::new(Bank::new(&genesis_block));
|
let bank = Arc::new(Bank::new(&genesis_block));
|
||||||
let dummy_leader_id = Keypair::new().pubkey();
|
let dummy_leader_id = Keypair::new().pubkey();
|
||||||
let dummy = Transaction::system_move(
|
let dummy = SystemTransaction::new_move(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
mint_keypair.pubkey(),
|
mint_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -183,7 +182,7 @@ fn bench_banking_stage_multi_programs(bencher: &mut Bencher) {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
transactions.iter().for_each(|tx| {
|
transactions.iter().for_each(|tx| {
|
||||||
let fund = Transaction::system_move(
|
let fund = SystemTransaction::new_move(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
tx.account_keys[0],
|
tx.account_keys[0],
|
||||||
mint_total / txes as u64,
|
mint_total / txes as u64,
|
||||||
|
|
|
@ -6,7 +6,6 @@ use solana::entry::{next_entries, reconstruct_entries_from_blobs, EntrySlice};
|
||||||
use solana_sdk::hash::{hash, Hash};
|
use solana_sdk::hash::{hash, Hash};
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
|
@ -14,7 +13,7 @@ fn bench_block_to_blobs_to_block(bencher: &mut Bencher) {
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let one = hash(&zero.as_ref());
|
let one = hash(&zero.as_ref());
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx0 = Transaction::system_move(&keypair, keypair.pubkey(), 1, one, 0);
|
let tx0 = SystemTransaction::new_move(&keypair, keypair.pubkey(), 1, one, 0);
|
||||||
let transactions = vec![tx0; 10];
|
let transactions = vec![tx0; 10];
|
||||||
let entries = next_entries(&zero, 1, transactions);
|
let entries = next_entries(&zero, 1, transactions);
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ fn create_and_fund_vote_account(
|
||||||
let last_id = client.get_last_id();
|
let last_id = client.get_last_id();
|
||||||
info!("create_and_fund_vote_account last_id={:?}", last_id);
|
info!("create_and_fund_vote_account last_id={:?}", last_id);
|
||||||
let transaction =
|
let transaction =
|
||||||
VoteTransaction::vote_account_new(node_keypair, vote_account, last_id, 1, 1);
|
VoteTransaction::new_account(node_keypair, vote_account, last_id, 1, 1);
|
||||||
|
|
||||||
match client.transfer_signed(&transaction) {
|
match client.transfer_signed(&transaction) {
|
||||||
Ok(signature) => {
|
Ok(signature) => {
|
||||||
|
|
|
@ -313,7 +313,7 @@ mod test {
|
||||||
let contract = Keypair::new().pubkey();
|
let contract = Keypair::new().pubkey();
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let witness = Keypair::new().pubkey();
|
let witness = Keypair::new().pubkey();
|
||||||
let tx = Transaction::budget_new_when_signed(
|
let tx = BudgetTransaction::new_when_signed(
|
||||||
&from,
|
&from,
|
||||||
to,
|
to,
|
||||||
contract,
|
contract,
|
||||||
|
@ -326,7 +326,7 @@ mod test {
|
||||||
|
|
||||||
// Attack! Part 1: Sign a witness transaction with a random key.
|
// Attack! Part 1: Sign a witness transaction with a random key.
|
||||||
let rando = Keypair::new();
|
let rando = Keypair::new();
|
||||||
let mut tx = Transaction::budget_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.
|
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
||||||
tx.account_keys.push(from.pubkey());
|
tx.account_keys.push(from.pubkey());
|
||||||
|
@ -352,7 +352,7 @@ mod test {
|
||||||
let contract = Keypair::new().pubkey();
|
let contract = Keypair::new().pubkey();
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let dt = Utc::now();
|
let dt = Utc::now();
|
||||||
let tx = Transaction::budget_new_on_date(
|
let tx = BudgetTransaction::new_on_date(
|
||||||
&from,
|
&from,
|
||||||
to,
|
to,
|
||||||
contract,
|
contract,
|
||||||
|
@ -366,7 +366,7 @@ mod test {
|
||||||
|
|
||||||
// Attack! Part 1: Sign a timestamp transaction with a random key.
|
// Attack! Part 1: Sign a timestamp transaction with a random key.
|
||||||
let rando = Keypair::new();
|
let rando = Keypair::new();
|
||||||
let mut tx = Transaction::budget_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.
|
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
||||||
tx.account_keys.push(from.pubkey());
|
tx.account_keys.push(from.pubkey());
|
||||||
|
@ -394,7 +394,7 @@ mod test {
|
||||||
let to = Keypair::new();
|
let to = Keypair::new();
|
||||||
let rando = Keypair::new();
|
let rando = Keypair::new();
|
||||||
let dt = Utc::now();
|
let dt = Utc::now();
|
||||||
let tx = Transaction::budget_new_on_date(
|
let tx = BudgetTransaction::new_on_date(
|
||||||
&from,
|
&from,
|
||||||
to.pubkey(),
|
to.pubkey(),
|
||||||
contract.pubkey(),
|
contract.pubkey(),
|
||||||
|
@ -411,7 +411,7 @@ mod test {
|
||||||
assert!(program.is_pending());
|
assert!(program.is_pending());
|
||||||
|
|
||||||
// Attack! Try to payout to a rando key
|
// Attack! Try to payout to a rando key
|
||||||
let tx = Transaction::budget_new_timestamp(
|
let tx = BudgetTransaction::new_timestamp(
|
||||||
&from,
|
&from,
|
||||||
contract.pubkey(),
|
contract.pubkey(),
|
||||||
rando.pubkey(),
|
rando.pubkey(),
|
||||||
|
@ -431,7 +431,7 @@ mod test {
|
||||||
|
|
||||||
// Now, acknowledge the time in the condition occurred and
|
// Now, acknowledge the time in the condition occurred and
|
||||||
// that pubkey's funds are now available.
|
// that pubkey's funds are now available.
|
||||||
let tx = Transaction::budget_new_timestamp(
|
let tx = BudgetTransaction::new_timestamp(
|
||||||
&from,
|
&from,
|
||||||
contract.pubkey(),
|
contract.pubkey(),
|
||||||
to.pubkey(),
|
to.pubkey(),
|
||||||
|
@ -469,7 +469,7 @@ mod test {
|
||||||
let contract = Keypair::new();
|
let contract = Keypair::new();
|
||||||
let to = Keypair::new();
|
let to = Keypair::new();
|
||||||
let dt = Utc::now();
|
let dt = Utc::now();
|
||||||
let tx = Transaction::budget_new_on_date(
|
let tx = BudgetTransaction::new_on_date(
|
||||||
&from,
|
&from,
|
||||||
to.pubkey(),
|
to.pubkey(),
|
||||||
contract.pubkey(),
|
contract.pubkey(),
|
||||||
|
@ -487,7 +487,7 @@ mod test {
|
||||||
|
|
||||||
// Attack! try to put the tokens into the wrong account with cancel
|
// Attack! try to put the tokens into the wrong account with cancel
|
||||||
let tx =
|
let tx =
|
||||||
Transaction::budget_new_signature(&to, contract.pubkey(), to.pubkey(), Hash::default());
|
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
|
// unit test hack, the `from account` is passed instead of the `to` account to avoid
|
||||||
// creating more account vectors
|
// creating more account vectors
|
||||||
process_transaction(&tx, &mut accounts).unwrap();
|
process_transaction(&tx, &mut accounts).unwrap();
|
||||||
|
@ -498,7 +498,7 @@ mod test {
|
||||||
assert_eq!(accounts[pay_account].tokens, 0);
|
assert_eq!(accounts[pay_account].tokens, 0);
|
||||||
|
|
||||||
// Now, cancel the transaction. from gets her funds back
|
// Now, cancel the transaction. from gets her funds back
|
||||||
let tx = Transaction::budget_new_signature(
|
let tx = BudgetTransaction::new_signature(
|
||||||
&from,
|
&from,
|
||||||
contract.pubkey(),
|
contract.pubkey(),
|
||||||
from.pubkey(),
|
from.pubkey(),
|
||||||
|
@ -510,7 +510,7 @@ mod test {
|
||||||
assert_eq!(accounts[pay_account].tokens, 1);
|
assert_eq!(accounts[pay_account].tokens, 1);
|
||||||
|
|
||||||
// try to replay the signature contract
|
// try to replay the signature contract
|
||||||
let tx = Transaction::budget_new_signature(
|
let tx = BudgetTransaction::new_signature(
|
||||||
&from,
|
&from,
|
||||||
contract.pubkey(),
|
contract.pubkey(),
|
||||||
from.pubkey(),
|
from.pubkey(),
|
||||||
|
@ -535,7 +535,7 @@ mod test {
|
||||||
let from = Keypair::new();
|
let from = Keypair::new();
|
||||||
let contract = Keypair::new();
|
let contract = Keypair::new();
|
||||||
let to = Keypair::new();
|
let to = Keypair::new();
|
||||||
let tx = Transaction::budget_new_on_date(
|
let tx = BudgetTransaction::new_on_date(
|
||||||
&from,
|
&from,
|
||||||
to.pubkey(),
|
to.pubkey(),
|
||||||
contract.pubkey(),
|
contract.pubkey(),
|
||||||
|
@ -549,7 +549,7 @@ mod test {
|
||||||
assert!(process_transaction(&tx, &mut accounts).is_err());
|
assert!(process_transaction(&tx, &mut accounts).is_err());
|
||||||
assert!(BudgetProgram::deserialize(&accounts[1].userdata).is_err());
|
assert!(BudgetProgram::deserialize(&accounts[1].userdata).is_err());
|
||||||
|
|
||||||
let tx = Transaction::budget_new_timestamp(
|
let tx = BudgetTransaction::new_timestamp(
|
||||||
&from,
|
&from,
|
||||||
contract.pubkey(),
|
contract.pubkey(),
|
||||||
to.pubkey(),
|
to.pubkey(),
|
||||||
|
|
|
@ -242,7 +242,7 @@ mod test {
|
||||||
keyed_accounts.push(KeyedAccount::new(&pubkey, true, &mut user_account));
|
keyed_accounts.push(KeyedAccount::new(&pubkey, true, &mut user_account));
|
||||||
keyed_accounts.push(KeyedAccount::new(&system_key, false, &mut system_account));
|
keyed_accounts.push(KeyedAccount::new(&system_key, false, &mut system_account));
|
||||||
|
|
||||||
let tx = Transaction::storage_new_advertise_last_id(
|
let tx = StorageTransaction::new_advertise_last_id(
|
||||||
&keypair,
|
&keypair,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
|
@ -260,7 +260,7 @@ mod test {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let mut accounts = [Default::default()];
|
let mut accounts = [Default::default()];
|
||||||
|
|
||||||
let tx = Transaction::storage_new_mining_proof(
|
let tx = StorageTransaction::new_mining_proof(
|
||||||
&keypair,
|
&keypair,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
|
@ -281,7 +281,7 @@ mod test {
|
||||||
let mut accounts = [Account::default(), Account::default()];
|
let mut accounts = [Account::default(), Account::default()];
|
||||||
accounts[1].userdata.resize(16 * 1024, 0);
|
accounts[1].userdata.resize(16 * 1024, 0);
|
||||||
|
|
||||||
let tx = Transaction::storage_new_mining_proof(
|
let tx = StorageTransaction::new_mining_proof(
|
||||||
&keypair,
|
&keypair,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
|
@ -300,7 +300,7 @@ mod test {
|
||||||
let mut accounts = [Account::default(), Account::default()];
|
let mut accounts = [Account::default(), Account::default()];
|
||||||
accounts[1].userdata.resize(16 * 1024, 0);
|
accounts[1].userdata.resize(16 * 1024, 0);
|
||||||
|
|
||||||
let tx = Transaction::storage_new_advertise_last_id(
|
let tx = StorageTransaction::new_advertise_last_id(
|
||||||
&keypair,
|
&keypair,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
|
@ -309,7 +309,7 @@ mod test {
|
||||||
|
|
||||||
test_transaction(&tx, &mut accounts).unwrap();
|
test_transaction(&tx, &mut accounts).unwrap();
|
||||||
|
|
||||||
let tx = Transaction::storage_new_mining_proof(
|
let tx = StorageTransaction::new_mining_proof(
|
||||||
&keypair,
|
&keypair,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
|
@ -329,7 +329,7 @@ mod test {
|
||||||
|
|
||||||
let entry_height = 0;
|
let entry_height = 0;
|
||||||
|
|
||||||
let tx = Transaction::storage_new_advertise_last_id(
|
let tx = StorageTransaction::new_advertise_last_id(
|
||||||
&keypair,
|
&keypair,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
|
@ -338,7 +338,7 @@ mod test {
|
||||||
|
|
||||||
test_transaction(&tx, &mut accounts).unwrap();
|
test_transaction(&tx, &mut accounts).unwrap();
|
||||||
|
|
||||||
let tx = Transaction::storage_new_mining_proof(
|
let tx = StorageTransaction::new_mining_proof(
|
||||||
&keypair,
|
&keypair,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
|
@ -347,7 +347,7 @@ mod test {
|
||||||
);
|
);
|
||||||
test_transaction(&tx, &mut accounts).unwrap();
|
test_transaction(&tx, &mut accounts).unwrap();
|
||||||
|
|
||||||
let tx = Transaction::storage_new_advertise_last_id(
|
let tx = StorageTransaction::new_advertise_last_id(
|
||||||
&keypair,
|
&keypair,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
|
@ -355,7 +355,7 @@ mod test {
|
||||||
);
|
);
|
||||||
test_transaction(&tx, &mut accounts).unwrap();
|
test_transaction(&tx, &mut accounts).unwrap();
|
||||||
|
|
||||||
let tx = Transaction::storage_new_proof_validation(
|
let tx = StorageTransaction::new_proof_validation(
|
||||||
&keypair,
|
&keypair,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
entry_height,
|
entry_height,
|
||||||
|
@ -363,7 +363,7 @@ mod test {
|
||||||
);
|
);
|
||||||
test_transaction(&tx, &mut accounts).unwrap();
|
test_transaction(&tx, &mut accounts).unwrap();
|
||||||
|
|
||||||
let tx = Transaction::storage_new_advertise_last_id(
|
let tx = StorageTransaction::new_advertise_last_id(
|
||||||
&keypair,
|
&keypair,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
|
@ -371,7 +371,7 @@ mod test {
|
||||||
);
|
);
|
||||||
test_transaction(&tx, &mut accounts).unwrap();
|
test_transaction(&tx, &mut accounts).unwrap();
|
||||||
|
|
||||||
let tx = Transaction::storage_new_reward_claim(&keypair, Hash::default(), entry_height);
|
let tx = StorageTransaction::new_reward_claim(&keypair, Hash::default(), entry_height);
|
||||||
test_transaction(&tx, &mut accounts).unwrap();
|
test_transaction(&tx, &mut accounts).unwrap();
|
||||||
|
|
||||||
assert!(accounts[0].tokens == TOTAL_VALIDATOR_REWARDS);
|
assert!(accounts[0].tokens == TOTAL_VALIDATOR_REWARDS);
|
||||||
|
|
|
@ -13,68 +13,17 @@ use crate::transaction::{self, Transaction};
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
|
|
||||||
pub trait BudgetTransaction {
|
pub struct BudgetTransaction {}
|
||||||
fn budget_new_taxed(
|
|
||||||
from_keypair: &Keypair,
|
|
||||||
to: Pubkey,
|
|
||||||
tokens: u64,
|
|
||||||
fee: u64,
|
|
||||||
last_id: Hash,
|
|
||||||
) -> Self;
|
|
||||||
|
|
||||||
fn budget_new(from_keypair: &Keypair, to: Pubkey, tokens: u64, last_id: Hash) -> Self;
|
impl BudgetTransaction {
|
||||||
|
|
||||||
fn budget_new_timestamp(
|
|
||||||
from_keypair: &Keypair,
|
|
||||||
contract: Pubkey,
|
|
||||||
to: Pubkey,
|
|
||||||
dt: DateTime<Utc>,
|
|
||||||
last_id: Hash,
|
|
||||||
) -> Self;
|
|
||||||
|
|
||||||
fn budget_new_signature(
|
|
||||||
from_keypair: &Keypair,
|
|
||||||
contract: Pubkey,
|
|
||||||
to: Pubkey,
|
|
||||||
last_id: Hash,
|
|
||||||
) -> Self;
|
|
||||||
|
|
||||||
fn budget_new_on_date(
|
|
||||||
from_keypair: &Keypair,
|
|
||||||
to: Pubkey,
|
|
||||||
contract: Pubkey,
|
|
||||||
dt: DateTime<Utc>,
|
|
||||||
dt_pubkey: Pubkey,
|
|
||||||
cancelable: Option<Pubkey>,
|
|
||||||
tokens: u64,
|
|
||||||
last_id: Hash,
|
|
||||||
) -> Self;
|
|
||||||
|
|
||||||
fn budget_new_when_signed(
|
|
||||||
from_keypair: &Keypair,
|
|
||||||
to: Pubkey,
|
|
||||||
contract: Pubkey,
|
|
||||||
witness: Pubkey,
|
|
||||||
cancelable: Option<Pubkey>,
|
|
||||||
tokens: u64,
|
|
||||||
last_id: Hash,
|
|
||||||
) -> Self;
|
|
||||||
|
|
||||||
fn instruction(&self, program_index: usize) -> Option<Instruction>;
|
|
||||||
fn system_instruction(&self, program_index: usize) -> Option<SystemInstruction>;
|
|
||||||
|
|
||||||
fn verify_plan(&self) -> bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl BudgetTransaction for Transaction {
|
|
||||||
/// Create and sign a new Transaction. Used for unit-testing.
|
/// Create and sign a new Transaction. Used for unit-testing.
|
||||||
fn budget_new_taxed(
|
pub fn new_payment(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
to: Pubkey,
|
to: Pubkey,
|
||||||
tokens: u64,
|
tokens: u64,
|
||||||
fee: u64,
|
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
) -> Self {
|
fee: u64,
|
||||||
|
) -> Transaction {
|
||||||
let contract = Keypair::new().pubkey();
|
let contract = Keypair::new().pubkey();
|
||||||
let keys = vec![from_keypair.pubkey(), contract];
|
let keys = vec![from_keypair.pubkey(), contract];
|
||||||
|
|
||||||
|
@ -93,7 +42,7 @@ impl BudgetTransaction for Transaction {
|
||||||
transaction::Instruction::new(1, &budget_instruction, vec![1]),
|
transaction::Instruction::new(1, &budget_instruction, vec![1]),
|
||||||
];
|
];
|
||||||
|
|
||||||
Self::new_with_instructions(
|
Transaction::new_with_instructions(
|
||||||
&[from_keypair],
|
&[from_keypair],
|
||||||
&keys,
|
&keys,
|
||||||
last_id,
|
last_id,
|
||||||
|
@ -104,20 +53,21 @@ impl BudgetTransaction for Transaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create and sign a new Transaction. Used for unit-testing.
|
/// Create and sign a new Transaction. Used for unit-testing.
|
||||||
fn budget_new(from_keypair: &Keypair, to: Pubkey, tokens: u64, last_id: Hash) -> Self {
|
#[allow(clippy::new_ret_no_self)]
|
||||||
Self::budget_new_taxed(from_keypair, to, tokens, 0, last_id)
|
pub fn new(from_keypair: &Keypair, to: Pubkey, tokens: u64, last_id: Hash) -> Transaction {
|
||||||
|
Self::new_payment(from_keypair, to, tokens, last_id, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create and sign a new Witness Timestamp. Used for unit-testing.
|
/// Create and sign a new Witness Timestamp. Used for unit-testing.
|
||||||
fn budget_new_timestamp(
|
pub fn new_timestamp(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
contract: Pubkey,
|
contract: Pubkey,
|
||||||
to: Pubkey,
|
to: Pubkey,
|
||||||
dt: DateTime<Utc>,
|
dt: DateTime<Utc>,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
) -> Self {
|
) -> Transaction {
|
||||||
let instruction = Instruction::ApplyTimestamp(dt);
|
let instruction = Instruction::ApplyTimestamp(dt);
|
||||||
Self::new(
|
Transaction::new(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
&[contract, to],
|
&[contract, to],
|
||||||
budget_program::id(),
|
budget_program::id(),
|
||||||
|
@ -128,14 +78,14 @@ impl BudgetTransaction for Transaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create and sign a new Witness Signature. Used for unit-testing.
|
/// Create and sign a new Witness Signature. Used for unit-testing.
|
||||||
fn budget_new_signature(
|
pub fn new_signature(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
contract: Pubkey,
|
contract: Pubkey,
|
||||||
to: Pubkey,
|
to: Pubkey,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
) -> Self {
|
) -> Transaction {
|
||||||
let instruction = Instruction::ApplySignature;
|
let instruction = Instruction::ApplySignature;
|
||||||
Self::new(
|
Transaction::new(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
&[contract, to],
|
&[contract, to],
|
||||||
budget_program::id(),
|
budget_program::id(),
|
||||||
|
@ -146,7 +96,7 @@ impl BudgetTransaction for Transaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create and sign a postdated Transaction. Used for unit-testing.
|
/// Create and sign a postdated Transaction. Used for unit-testing.
|
||||||
fn budget_new_on_date(
|
pub fn new_on_date(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
to: Pubkey,
|
to: Pubkey,
|
||||||
contract: Pubkey,
|
contract: Pubkey,
|
||||||
|
@ -155,7 +105,7 @@ impl BudgetTransaction for Transaction {
|
||||||
cancelable: Option<Pubkey>,
|
cancelable: Option<Pubkey>,
|
||||||
tokens: u64,
|
tokens: u64,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
) -> Self {
|
) -> Transaction {
|
||||||
let expr = if let Some(from) = cancelable {
|
let expr = if let Some(from) = cancelable {
|
||||||
BudgetExpr::Or(
|
BudgetExpr::Or(
|
||||||
(
|
(
|
||||||
|
@ -174,7 +124,7 @@ impl BudgetTransaction for Transaction {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
let instruction = Instruction::NewBudget(expr);
|
let instruction = Instruction::NewBudget(expr);
|
||||||
Self::new(
|
Transaction::new(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
&[contract],
|
&[contract],
|
||||||
budget_program::id(),
|
budget_program::id(),
|
||||||
|
@ -184,7 +134,7 @@ impl BudgetTransaction for Transaction {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/// Create and sign a multisig Transaction.
|
/// Create and sign a multisig Transaction.
|
||||||
fn budget_new_when_signed(
|
pub fn new_when_signed(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
to: Pubkey,
|
to: Pubkey,
|
||||||
contract: Pubkey,
|
contract: Pubkey,
|
||||||
|
@ -192,7 +142,7 @@ impl BudgetTransaction for Transaction {
|
||||||
cancelable: Option<Pubkey>,
|
cancelable: Option<Pubkey>,
|
||||||
tokens: u64,
|
tokens: u64,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
) -> Self {
|
) -> Transaction {
|
||||||
let expr = if let Some(from) = cancelable {
|
let expr = if let Some(from) = cancelable {
|
||||||
BudgetExpr::Or(
|
BudgetExpr::Or(
|
||||||
(
|
(
|
||||||
|
@ -211,7 +161,7 @@ impl BudgetTransaction for Transaction {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
let instruction = Instruction::NewBudget(expr);
|
let instruction = Instruction::NewBudget(expr);
|
||||||
Self::new(
|
Transaction::new(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
&[contract],
|
&[contract],
|
||||||
budget_program::id(),
|
budget_program::id(),
|
||||||
|
@ -221,19 +171,19 @@ impl BudgetTransaction for Transaction {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn instruction(&self, instruction_index: usize) -> Option<Instruction> {
|
pub fn system_instruction(tx: &Transaction, index: usize) -> Option<SystemInstruction> {
|
||||||
deserialize(&self.userdata(instruction_index)).ok()
|
deserialize(&tx.userdata(index)).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn system_instruction(&self, instruction_index: usize) -> Option<SystemInstruction> {
|
pub fn instruction(tx: &Transaction, index: usize) -> Option<Instruction> {
|
||||||
deserialize(&self.userdata(instruction_index)).ok()
|
deserialize(&tx.userdata(index)).ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Verify only the payment plan.
|
/// Verify only the payment plan.
|
||||||
fn verify_plan(&self) -> bool {
|
pub fn verify_plan(tx: &Transaction) -> bool {
|
||||||
if let Some(SystemInstruction::Move { tokens }) = self.system_instruction(0) {
|
if let Some(SystemInstruction::Move { tokens }) = Self::system_instruction(tx, 0) {
|
||||||
if let Some(Instruction::NewBudget(expr)) = self.instruction(1) {
|
if let Some(Instruction::NewBudget(expr)) = BudgetTransaction::instruction(&tx, 1) {
|
||||||
if !(self.fee <= tokens && expr.verify(tokens - self.fee)) {
|
if !(tx.fee <= tokens && expr.verify(tokens - tx.fee)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,26 +201,27 @@ mod tests {
|
||||||
fn test_claim() {
|
fn test_claim() {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let tx0 = Transaction::budget_new(&keypair, keypair.pubkey(), 42, zero);
|
let tx0 = BudgetTransaction::new(&keypair, keypair.pubkey(), 42, zero);
|
||||||
assert!(tx0.verify_plan());
|
assert!(BudgetTransaction::verify_plan(&tx0));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transfer() {
|
fn test_payment() {
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let keypair0 = Keypair::new();
|
let keypair0 = Keypair::new();
|
||||||
let keypair1 = Keypair::new();
|
let keypair1 = Keypair::new();
|
||||||
let pubkey1 = keypair1.pubkey();
|
let pubkey1 = keypair1.pubkey();
|
||||||
let tx0 = Transaction::budget_new(&keypair0, pubkey1, 42, zero);
|
let tx0 = BudgetTransaction::new(&keypair0, pubkey1, 42, zero);
|
||||||
assert!(tx0.verify_plan());
|
assert!(BudgetTransaction::verify_plan(&tx0));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transfer_with_fee() {
|
fn test_payment_with_fee() {
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let keypair0 = Keypair::new();
|
let keypair0 = Keypair::new();
|
||||||
let pubkey1 = Keypair::new().pubkey();
|
let pubkey1 = Keypair::new().pubkey();
|
||||||
assert!(Transaction::budget_new_taxed(&keypair0, pubkey1, 1, 1, zero).verify_plan());
|
let tx0 = BudgetTransaction::new_payment(&keypair0, pubkey1, 1, zero, 1);
|
||||||
|
assert!(BudgetTransaction::verify_plan(&tx0));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -299,11 +250,11 @@ mod tests {
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let pubkey = keypair.pubkey();
|
let pubkey = keypair.pubkey();
|
||||||
let mut tx = Transaction::budget_new(&keypair, pubkey, 42, zero);
|
let mut tx = BudgetTransaction::new(&keypair, pubkey, 42, zero);
|
||||||
let mut system_instruction = tx.system_instruction(0).unwrap();
|
let mut system_instruction = BudgetTransaction::system_instruction(&tx, 0).unwrap();
|
||||||
if let SystemInstruction::Move { ref mut tokens } = system_instruction {
|
if let SystemInstruction::Move { ref mut tokens } = system_instruction {
|
||||||
*tokens = 1_000_000; // <-- attack, part 1!
|
*tokens = 1_000_000; // <-- attack, part 1!
|
||||||
let mut instruction = tx.instruction(1).unwrap();
|
let mut instruction = BudgetTransaction::instruction(&tx, 1).unwrap();
|
||||||
if let Instruction::NewBudget(ref mut expr) = instruction {
|
if let Instruction::NewBudget(ref mut expr) = instruction {
|
||||||
if let BudgetExpr::Pay(ref mut payment) = expr {
|
if let BudgetExpr::Pay(ref mut payment) = expr {
|
||||||
payment.tokens = *tokens; // <-- attack, part 2!
|
payment.tokens = *tokens; // <-- attack, part 2!
|
||||||
|
@ -312,7 +263,7 @@ mod tests {
|
||||||
tx.instructions[1].userdata = serialize(&instruction).unwrap();
|
tx.instructions[1].userdata = serialize(&instruction).unwrap();
|
||||||
}
|
}
|
||||||
tx.instructions[0].userdata = serialize(&system_instruction).unwrap();
|
tx.instructions[0].userdata = serialize(&system_instruction).unwrap();
|
||||||
assert!(tx.verify_plan());
|
assert!(BudgetTransaction::verify_plan(&tx));
|
||||||
assert!(!tx.verify_signature());
|
assert!(!tx.verify_signature());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,15 +274,15 @@ mod tests {
|
||||||
let thief_keypair = Keypair::new();
|
let thief_keypair = Keypair::new();
|
||||||
let pubkey1 = keypair1.pubkey();
|
let pubkey1 = keypair1.pubkey();
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let mut tx = Transaction::budget_new(&keypair0, pubkey1, 42, zero);
|
let mut tx = BudgetTransaction::new(&keypair0, pubkey1, 42, zero);
|
||||||
let mut instruction = tx.instruction(1);
|
let mut instruction = BudgetTransaction::instruction(&tx, 1);
|
||||||
if let Some(Instruction::NewBudget(ref mut expr)) = instruction {
|
if let Some(Instruction::NewBudget(ref mut expr)) = instruction {
|
||||||
if let BudgetExpr::Pay(ref mut payment) = expr {
|
if let BudgetExpr::Pay(ref mut payment) = expr {
|
||||||
payment.to = thief_keypair.pubkey(); // <-- attack!
|
payment.to = thief_keypair.pubkey(); // <-- attack!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tx.instructions[1].userdata = serialize(&instruction).unwrap();
|
tx.instructions[1].userdata = serialize(&instruction).unwrap();
|
||||||
assert!(tx.verify_plan());
|
assert!(BudgetTransaction::verify_plan(&tx));
|
||||||
assert!(!tx.verify_signature());
|
assert!(!tx.verify_signature());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,24 +291,24 @@ mod tests {
|
||||||
let keypair0 = Keypair::new();
|
let keypair0 = Keypair::new();
|
||||||
let keypair1 = Keypair::new();
|
let keypair1 = Keypair::new();
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let mut tx = Transaction::budget_new(&keypair0, keypair1.pubkey(), 1, zero);
|
let mut tx = BudgetTransaction::new(&keypair0, keypair1.pubkey(), 1, zero);
|
||||||
let mut instruction = tx.instruction(1).unwrap();
|
let mut instruction = BudgetTransaction::instruction(&tx, 1).unwrap();
|
||||||
if let Instruction::NewBudget(ref mut expr) = instruction {
|
if let Instruction::NewBudget(ref mut expr) = instruction {
|
||||||
if let BudgetExpr::Pay(ref mut payment) = expr {
|
if let BudgetExpr::Pay(ref mut payment) = expr {
|
||||||
payment.tokens = 2; // <-- attack!
|
payment.tokens = 2; // <-- attack!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tx.instructions[1].userdata = serialize(&instruction).unwrap();
|
tx.instructions[1].userdata = serialize(&instruction).unwrap();
|
||||||
assert!(!tx.verify_plan());
|
assert!(!BudgetTransaction::verify_plan(&tx));
|
||||||
|
|
||||||
// Also, ensure all branchs of the plan spend all tokens
|
// Also, ensure all branchs of the plan spend all tokens
|
||||||
let mut instruction = tx.instruction(1).unwrap();
|
let mut instruction = BudgetTransaction::instruction(&tx, 1).unwrap();
|
||||||
if let Instruction::NewBudget(ref mut expr) = instruction {
|
if let Instruction::NewBudget(ref mut expr) = instruction {
|
||||||
if let BudgetExpr::Pay(ref mut payment) = expr {
|
if let BudgetExpr::Pay(ref mut payment) = expr {
|
||||||
payment.tokens = 0; // <-- whoops!
|
payment.tokens = 0; // <-- whoops!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tx.instructions[1].userdata = serialize(&instruction).unwrap();
|
tx.instructions[1].userdata = serialize(&instruction).unwrap();
|
||||||
assert!(!tx.verify_plan());
|
assert!(!BudgetTransaction::verify_plan(&tx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,33 +6,27 @@ use crate::pubkey::Pubkey;
|
||||||
use crate::signature::Keypair;
|
use crate::signature::Keypair;
|
||||||
use crate::transaction::Transaction;
|
use crate::transaction::Transaction;
|
||||||
|
|
||||||
pub trait LoaderTransaction {
|
pub struct LoaderTransaction {}
|
||||||
fn loader_write(
|
|
||||||
|
impl LoaderTransaction {
|
||||||
|
pub fn new_write(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
loader: Pubkey,
|
loader: Pubkey,
|
||||||
offset: u32,
|
offset: u32,
|
||||||
bytes: Vec<u8>,
|
bytes: Vec<u8>,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Self;
|
) -> Transaction {
|
||||||
|
|
||||||
fn loader_finalize(from_keypair: &Keypair, loader: Pubkey, last_id: Hash, fee: u64) -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl LoaderTransaction for Transaction {
|
|
||||||
fn loader_write(
|
|
||||||
from_keypair: &Keypair,
|
|
||||||
loader: Pubkey,
|
|
||||||
offset: u32,
|
|
||||||
bytes: Vec<u8>,
|
|
||||||
last_id: Hash,
|
|
||||||
fee: u64,
|
|
||||||
) -> Self {
|
|
||||||
let instruction = LoaderInstruction::Write { offset, bytes };
|
let instruction = LoaderInstruction::Write { offset, bytes };
|
||||||
Transaction::new(from_keypair, &[], loader, &instruction, last_id, fee)
|
Transaction::new(from_keypair, &[], loader, &instruction, last_id, fee)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn loader_finalize(from_keypair: &Keypair, loader: Pubkey, last_id: Hash, fee: u64) -> Self {
|
pub fn new_finalize(
|
||||||
|
from_keypair: &Keypair,
|
||||||
|
loader: Pubkey,
|
||||||
|
last_id: Hash,
|
||||||
|
fee: u64,
|
||||||
|
) -> Transaction {
|
||||||
let instruction = LoaderInstruction::Finalize;
|
let instruction = LoaderInstruction::Finalize;
|
||||||
Transaction::new(from_keypair, &[], loader, &instruction, last_id, fee)
|
Transaction::new(from_keypair, &[], loader, &instruction, last_id, fee)
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,40 +83,16 @@ pub fn system_id() -> Pubkey {
|
||||||
Pubkey::new(&STORAGE_SYSTEM_ACCOUNT_ID)
|
Pubkey::new(&STORAGE_SYSTEM_ACCOUNT_ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait StorageTransaction {
|
pub struct StorageTransaction {}
|
||||||
fn storage_new_mining_proof(
|
|
||||||
|
impl StorageTransaction {
|
||||||
|
pub fn new_mining_proof(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
sha_state: Hash,
|
sha_state: Hash,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
entry_height: u64,
|
entry_height: u64,
|
||||||
signature: Signature,
|
signature: Signature,
|
||||||
) -> Self;
|
) -> Transaction {
|
||||||
|
|
||||||
fn storage_new_advertise_last_id(
|
|
||||||
from_keypair: &Keypair,
|
|
||||||
storage_last_id: Hash,
|
|
||||||
last_id: Hash,
|
|
||||||
entry_height: u64,
|
|
||||||
) -> Self;
|
|
||||||
|
|
||||||
fn storage_new_proof_validation(
|
|
||||||
from_keypair: &Keypair,
|
|
||||||
last_id: Hash,
|
|
||||||
entry_height: u64,
|
|
||||||
proof_mask: Vec<ProofStatus>,
|
|
||||||
) -> Self;
|
|
||||||
|
|
||||||
fn storage_new_reward_claim(from_keypair: &Keypair, last_id: Hash, entry_height: u64) -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StorageTransaction for Transaction {
|
|
||||||
fn storage_new_mining_proof(
|
|
||||||
from_keypair: &Keypair,
|
|
||||||
sha_state: Hash,
|
|
||||||
last_id: Hash,
|
|
||||||
entry_height: u64,
|
|
||||||
signature: Signature,
|
|
||||||
) -> Self {
|
|
||||||
let program = StorageProgram::SubmitMiningProof {
|
let program = StorageProgram::SubmitMiningProof {
|
||||||
sha_state,
|
sha_state,
|
||||||
entry_height,
|
entry_height,
|
||||||
|
@ -132,12 +108,12 @@ impl StorageTransaction for Transaction {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn storage_new_advertise_last_id(
|
pub fn new_advertise_last_id(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
storage_id: Hash,
|
storage_id: Hash,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
entry_height: u64,
|
entry_height: u64,
|
||||||
) -> Self {
|
) -> Transaction {
|
||||||
let program = StorageProgram::AdvertiseStorageLastId {
|
let program = StorageProgram::AdvertiseStorageLastId {
|
||||||
id: storage_id,
|
id: storage_id,
|
||||||
entry_height,
|
entry_height,
|
||||||
|
@ -152,12 +128,12 @@ impl StorageTransaction for Transaction {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn storage_new_proof_validation(
|
pub fn new_proof_validation(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
entry_height: u64,
|
entry_height: u64,
|
||||||
proof_mask: Vec<ProofStatus>,
|
proof_mask: Vec<ProofStatus>,
|
||||||
) -> Self {
|
) -> Transaction {
|
||||||
let program = StorageProgram::ProofValidation {
|
let program = StorageProgram::ProofValidation {
|
||||||
entry_height,
|
entry_height,
|
||||||
proof_mask,
|
proof_mask,
|
||||||
|
@ -172,7 +148,11 @@ impl StorageTransaction for Transaction {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn storage_new_reward_claim(from_keypair: &Keypair, last_id: Hash, entry_height: u64) -> Self {
|
pub fn new_reward_claim(
|
||||||
|
from_keypair: &Keypair,
|
||||||
|
last_id: Hash,
|
||||||
|
entry_height: u64,
|
||||||
|
) -> Transaction {
|
||||||
let program = StorageProgram::ClaimStorageReward { entry_height };
|
let program = StorageProgram::ClaimStorageReward { entry_height };
|
||||||
Transaction::new(
|
Transaction::new(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
|
|
|
@ -7,42 +7,11 @@ use crate::system_instruction::SystemInstruction;
|
||||||
use crate::system_program;
|
use crate::system_program;
|
||||||
use crate::transaction::{Instruction, Transaction};
|
use crate::transaction::{Instruction, Transaction};
|
||||||
|
|
||||||
pub trait SystemTransaction {
|
pub struct SystemTransaction {}
|
||||||
fn system_create(
|
|
||||||
from_keypair: &Keypair,
|
|
||||||
to: Pubkey,
|
|
||||||
last_id: Hash,
|
|
||||||
tokens: u64,
|
|
||||||
space: u64,
|
|
||||||
program_id: Pubkey,
|
|
||||||
fee: u64,
|
|
||||||
) -> Self;
|
|
||||||
|
|
||||||
fn system_assign(from_keypair: &Keypair, last_id: Hash, program_id: Pubkey, fee: u64) -> Self;
|
impl SystemTransaction {
|
||||||
|
|
||||||
fn system_new(from_keypair: &Keypair, to: Pubkey, tokens: u64, last_id: Hash) -> Self;
|
|
||||||
|
|
||||||
fn system_move(
|
|
||||||
from_keypair: &Keypair,
|
|
||||||
to: Pubkey,
|
|
||||||
tokens: u64,
|
|
||||||
last_id: Hash,
|
|
||||||
fee: u64,
|
|
||||||
) -> Self;
|
|
||||||
|
|
||||||
fn system_move_many(
|
|
||||||
from_keypair: &Keypair,
|
|
||||||
moves: &[(Pubkey, u64)],
|
|
||||||
last_id: Hash,
|
|
||||||
fee: u64,
|
|
||||||
) -> Self;
|
|
||||||
|
|
||||||
fn system_spawn(from_keypair: &Keypair, last_id: Hash, fee: u64) -> Self;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SystemTransaction for Transaction {
|
|
||||||
/// Create and sign new SystemInstruction::CreateAccount transaction
|
/// Create and sign new SystemInstruction::CreateAccount transaction
|
||||||
fn system_create(
|
pub fn new_program_account(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
to: Pubkey,
|
to: Pubkey,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
|
@ -50,7 +19,7 @@ impl SystemTransaction for Transaction {
|
||||||
space: u64,
|
space: u64,
|
||||||
program_id: Pubkey,
|
program_id: Pubkey,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Self {
|
) -> Transaction {
|
||||||
let create = SystemInstruction::CreateAccount {
|
let create = SystemInstruction::CreateAccount {
|
||||||
tokens, //TODO, the tokens to allocate might need to be higher then 0 in the future
|
tokens, //TODO, the tokens to allocate might need to be higher then 0 in the future
|
||||||
space,
|
space,
|
||||||
|
@ -65,8 +34,25 @@ impl SystemTransaction for Transaction {
|
||||||
fee,
|
fee,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create and sign a transaction to create a system account
|
||||||
|
pub fn new_account(
|
||||||
|
from_keypair: &Keypair,
|
||||||
|
to: Pubkey,
|
||||||
|
tokens: u64,
|
||||||
|
last_id: Hash,
|
||||||
|
fee: u64,
|
||||||
|
) -> Transaction {
|
||||||
|
let program_id = system_program::id();
|
||||||
|
Self::new_program_account(from_keypair, to, last_id, tokens, 0, program_id, fee)
|
||||||
|
}
|
||||||
/// Create and sign new SystemInstruction::Assign transaction
|
/// Create and sign new SystemInstruction::Assign transaction
|
||||||
fn system_assign(from_keypair: &Keypair, last_id: Hash, program_id: Pubkey, fee: u64) -> Self {
|
pub fn new_assign(
|
||||||
|
from_keypair: &Keypair,
|
||||||
|
last_id: Hash,
|
||||||
|
program_id: Pubkey,
|
||||||
|
fee: u64,
|
||||||
|
) -> Transaction {
|
||||||
let assign = SystemInstruction::Assign { program_id };
|
let assign = SystemInstruction::Assign { program_id };
|
||||||
Transaction::new(
|
Transaction::new(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
|
@ -77,18 +63,14 @@ impl SystemTransaction for Transaction {
|
||||||
fee,
|
fee,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/// Create and sign new SystemInstruction::CreateAccount transaction with some defaults
|
|
||||||
fn system_new(from_keypair: &Keypair, to: Pubkey, tokens: u64, last_id: Hash) -> Self {
|
|
||||||
Transaction::system_create(from_keypair, to, last_id, tokens, 0, Pubkey::default(), 0)
|
|
||||||
}
|
|
||||||
/// Create and sign new SystemInstruction::Move transaction
|
/// Create and sign new SystemInstruction::Move transaction
|
||||||
fn system_move(
|
pub fn new_move(
|
||||||
from_keypair: &Keypair,
|
from_keypair: &Keypair,
|
||||||
to: Pubkey,
|
to: Pubkey,
|
||||||
tokens: u64,
|
tokens: u64,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Self {
|
) -> Transaction {
|
||||||
let move_tokens = SystemInstruction::Move { tokens };
|
let move_tokens = SystemInstruction::Move { tokens };
|
||||||
Transaction::new(
|
Transaction::new(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
|
@ -100,7 +82,12 @@ impl SystemTransaction for Transaction {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/// Create and sign new SystemInstruction::Move transaction to many destinations
|
/// Create and sign new SystemInstruction::Move transaction to many destinations
|
||||||
fn system_move_many(from: &Keypair, moves: &[(Pubkey, u64)], last_id: Hash, fee: u64) -> Self {
|
pub fn new_move_many(
|
||||||
|
from: &Keypair,
|
||||||
|
moves: &[(Pubkey, u64)],
|
||||||
|
last_id: Hash,
|
||||||
|
fee: u64,
|
||||||
|
) -> Transaction {
|
||||||
let instructions: Vec<_> = moves
|
let instructions: Vec<_> = moves
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
|
@ -121,7 +108,7 @@ impl SystemTransaction for Transaction {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/// Create and sign new SystemInstruction::Spawn transaction
|
/// Create and sign new SystemInstruction::Spawn transaction
|
||||||
fn system_spawn(from_keypair: &Keypair, last_id: Hash, fee: u64) -> Self {
|
pub fn new_spawn(from_keypair: &Keypair, last_id: Hash, fee: u64) -> Transaction {
|
||||||
let spawn = SystemInstruction::Spawn;
|
let spawn = SystemInstruction::Spawn;
|
||||||
Transaction::new(
|
Transaction::new(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
|
@ -146,7 +133,7 @@ mod tests {
|
||||||
let t2 = Keypair::new();
|
let t2 = Keypair::new();
|
||||||
let moves = vec![(t1.pubkey(), 1), (t2.pubkey(), 2)];
|
let moves = vec![(t1.pubkey(), 1), (t2.pubkey(), 2)];
|
||||||
|
|
||||||
let tx = Transaction::system_move_many(&from, &moves, Default::default(), 0);
|
let tx = SystemTransaction::new_move_many(&from, &moves, Default::default(), 0);
|
||||||
assert_eq!(tx.account_keys[0], from.pubkey());
|
assert_eq!(tx.account_keys[0], from.pubkey());
|
||||||
assert_eq!(tx.account_keys[1], t1.pubkey());
|
assert_eq!(tx.account_keys[1], t1.pubkey());
|
||||||
assert_eq!(tx.account_keys[2], t2.pubkey());
|
assert_eq!(tx.account_keys[2], t2.pubkey());
|
||||||
|
|
|
@ -174,6 +174,7 @@ impl Transaction {
|
||||||
pub fn userdata(&self, instruction_index: usize) -> &[u8] {
|
pub fn userdata(&self, instruction_index: usize) -> &[u8] {
|
||||||
&self.instructions[instruction_index].userdata
|
&self.instructions[instruction_index].userdata
|
||||||
}
|
}
|
||||||
|
|
||||||
fn key_index(&self, instruction_index: usize, accounts_index: usize) -> Option<usize> {
|
fn key_index(&self, instruction_index: usize, accounts_index: usize) -> Option<usize> {
|
||||||
self.instructions
|
self.instructions
|
||||||
.get(instruction_index)
|
.get(instruction_index)
|
||||||
|
|
|
@ -9,31 +9,15 @@ use crate::transaction::{Instruction, Transaction};
|
||||||
use crate::vote_program::{self, Vote, VoteInstruction};
|
use crate::vote_program::{self, Vote, VoteInstruction};
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
|
|
||||||
pub trait VoteTransaction {
|
pub struct VoteTransaction {}
|
||||||
fn vote_new<T: KeypairUtil>(
|
|
||||||
|
impl VoteTransaction {
|
||||||
|
pub fn new_vote<T: KeypairUtil>(
|
||||||
vote_account: &T,
|
vote_account: &T,
|
||||||
tick_height: u64,
|
tick_height: u64,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Self;
|
) -> Transaction {
|
||||||
fn vote_account_new(
|
|
||||||
validator_id: &Keypair,
|
|
||||||
vote_account_id: Pubkey,
|
|
||||||
last_id: Hash,
|
|
||||||
num_tokens: u64,
|
|
||||||
fee: u64,
|
|
||||||
) -> Self;
|
|
||||||
|
|
||||||
fn get_votes(&self) -> Vec<(Pubkey, Vote, Hash)>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl VoteTransaction for Transaction {
|
|
||||||
fn vote_new<T: KeypairUtil>(
|
|
||||||
vote_account: &T,
|
|
||||||
tick_height: u64,
|
|
||||||
last_id: Hash,
|
|
||||||
fee: u64,
|
|
||||||
) -> Self {
|
|
||||||
let vote = Vote { tick_height };
|
let vote = Vote { tick_height };
|
||||||
let instruction = VoteInstruction::NewVote(vote);
|
let instruction = VoteInstruction::NewVote(vote);
|
||||||
Transaction::new(
|
Transaction::new(
|
||||||
|
@ -46,13 +30,13 @@ impl VoteTransaction for Transaction {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn vote_account_new(
|
pub fn new_account(
|
||||||
validator_id: &Keypair,
|
validator_id: &Keypair,
|
||||||
vote_account_id: Pubkey,
|
vote_account_id: Pubkey,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
num_tokens: u64,
|
num_tokens: u64,
|
||||||
fee: u64,
|
fee: u64,
|
||||||
) -> Self {
|
) -> Transaction {
|
||||||
Transaction::new_with_instructions(
|
Transaction::new_with_instructions(
|
||||||
&[validator_id],
|
&[validator_id],
|
||||||
&[vote_account_id],
|
&[vote_account_id],
|
||||||
|
@ -74,13 +58,13 @@ impl VoteTransaction for Transaction {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_votes(&self) -> Vec<(Pubkey, Vote, Hash)> {
|
pub fn get_votes(tx: &Transaction) -> Vec<(Pubkey, Vote, Hash)> {
|
||||||
let mut votes = vec![];
|
let mut votes = vec![];
|
||||||
for i in 0..self.instructions.len() {
|
for i in 0..tx.instructions.len() {
|
||||||
let tx_program_id = self.program_id(i);
|
let tx_program_id = tx.program_id(i);
|
||||||
if vote_program::check_id(&tx_program_id) {
|
if vote_program::check_id(&tx_program_id) {
|
||||||
if let Ok(Some(VoteInstruction::NewVote(vote))) = deserialize(&self.userdata(i)) {
|
if let Ok(Some(VoteInstruction::NewVote(vote))) = deserialize(&tx.userdata(i)) {
|
||||||
votes.push((self.account_keys[0], vote, self.last_id))
|
votes.push((tx.account_keys[0], vote, tx.last_id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
108
src/bank.rs
108
src/bank.rs
|
@ -804,7 +804,7 @@ impl Bank {
|
||||||
to: Pubkey,
|
to: Pubkey,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
) -> Result<Signature> {
|
) -> Result<Signature> {
|
||||||
let tx = Transaction::system_new(keypair, to, n, last_id);
|
let tx = SystemTransaction::new_account(keypair, to, n, last_id, 0);
|
||||||
let signature = tx.signatures[0];
|
let signature = tx.signatures[0];
|
||||||
self.process_transaction(&tx).map(|_| signature)
|
self.process_transaction(&tx).map(|_| signature)
|
||||||
}
|
}
|
||||||
|
@ -960,8 +960,8 @@ mod tests {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
assert_eq!(bank.last_id(), genesis_block.last_id());
|
assert_eq!(bank.last_id(), genesis_block.last_id());
|
||||||
|
|
||||||
let t1 = Transaction::system_move(&mint_keypair, key1, 1, genesis_block.last_id(), 0);
|
let t1 = SystemTransaction::new_move(&mint_keypair, key1, 1, genesis_block.last_id(), 0);
|
||||||
let t2 = Transaction::system_move(&mint_keypair, key2, 1, genesis_block.last_id(), 0);
|
let t2 = SystemTransaction::new_move(&mint_keypair, key2, 1, genesis_block.last_id(), 0);
|
||||||
let res = bank.process_transactions(&vec![t1.clone(), t2.clone()]);
|
let res = bank.process_transactions(&vec![t1.clone(), t2.clone()]);
|
||||||
assert_eq!(res.len(), 2);
|
assert_eq!(res.len(), 2);
|
||||||
assert_eq!(res[0], Ok(()));
|
assert_eq!(res[0], Ok(()));
|
||||||
|
@ -1032,7 +1032,7 @@ mod tests {
|
||||||
let key1 = Keypair::new().pubkey();
|
let key1 = Keypair::new().pubkey();
|
||||||
let key2 = Keypair::new().pubkey();
|
let key2 = Keypair::new().pubkey();
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let t1 = Transaction::system_move_many(
|
let t1 = SystemTransaction::new_move_many(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&[(key1, 1), (key2, 1)],
|
&[(key1, 1), (key2, 1)],
|
||||||
genesis_block.last_id(),
|
genesis_block.last_id(),
|
||||||
|
@ -1056,13 +1056,11 @@ mod tests {
|
||||||
let dest = Keypair::new();
|
let dest = Keypair::new();
|
||||||
|
|
||||||
// source with 0 program context
|
// source with 0 program context
|
||||||
let tx = Transaction::system_create(
|
let tx = SystemTransaction::new_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
dest.pubkey(),
|
dest.pubkey(),
|
||||||
genesis_block.last_id(),
|
|
||||||
2,
|
2,
|
||||||
0,
|
genesis_block.last_id(),
|
||||||
Pubkey::default(),
|
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
let signature = tx.signatures[0];
|
let signature = tx.signatures[0];
|
||||||
|
@ -1137,10 +1135,20 @@ mod tests {
|
||||||
let (genesis_block, mint_keypair) = GenesisBlock::new(2);
|
let (genesis_block, mint_keypair) = GenesisBlock::new(2);
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx0 =
|
let tx0 = SystemTransaction::new_account(
|
||||||
Transaction::system_new(&mint_keypair, keypair.pubkey(), 2, genesis_block.last_id());
|
&mint_keypair,
|
||||||
let tx1 =
|
keypair.pubkey(),
|
||||||
Transaction::system_new(&keypair, mint_keypair.pubkey(), 1, genesis_block.last_id());
|
2,
|
||||||
|
genesis_block.last_id(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
let tx1 = SystemTransaction::new_account(
|
||||||
|
&keypair,
|
||||||
|
mint_keypair.pubkey(),
|
||||||
|
1,
|
||||||
|
genesis_block.last_id(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
let txs = vec![tx0, tx1];
|
let txs = vec![tx0, tx1];
|
||||||
let results = bank.process_transactions(&txs);
|
let results = bank.process_transactions(&txs);
|
||||||
assert!(results[1].is_err());
|
assert!(results[1].is_err());
|
||||||
|
@ -1155,7 +1163,7 @@ mod tests {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let entry = next_entry(&genesis_block.last_id(), 1, vec![]);
|
let entry = next_entry(&genesis_block.last_id(), 1, vec![]);
|
||||||
let tx = Transaction::system_new(&mint_keypair, keypair.pubkey(), 1, entry.id);
|
let tx = SystemTransaction::new_account(&mint_keypair, keypair.pubkey(), 1, entry.id, 0);
|
||||||
|
|
||||||
// First, ensure the TX is rejected because of the unregistered last ID
|
// First, ensure the TX is rejected because of the unregistered last ID
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -1203,12 +1211,8 @@ mod tests {
|
||||||
|
|
||||||
let num_hashes = 1;
|
let num_hashes = 1;
|
||||||
for k in keypairs {
|
for k in keypairs {
|
||||||
let txs = vec![Transaction::system_new(
|
let tx = SystemTransaction::new_account(mint_keypair, k.pubkey(), 1, last_id, 0);
|
||||||
mint_keypair,
|
let txs = vec![tx];
|
||||||
k.pubkey(),
|
|
||||||
1,
|
|
||||||
last_id,
|
|
||||||
)];
|
|
||||||
let mut e = next_entries(&hash, 0, txs);
|
let mut e = next_entries(&hash, 0, txs);
|
||||||
entries.append(&mut e);
|
entries.append(&mut e);
|
||||||
hash = entries.last().unwrap().id;
|
hash = entries.last().unwrap().id;
|
||||||
|
@ -1239,7 +1243,7 @@ mod tests {
|
||||||
let num_hashes = 1;
|
let num_hashes = 1;
|
||||||
for i in 1..num_entries {
|
for i in 1..num_entries {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx = Transaction::system_new(mint_keypair, keypair.pubkey(), 1, last_id);
|
let tx = SystemTransaction::new_account(mint_keypair, keypair.pubkey(), 1, last_id, 0);
|
||||||
let entry = Entry::new(&hash, 0, num_hashes, vec![tx]);
|
let entry = Entry::new(&hash, 0, num_hashes, vec![tx]);
|
||||||
hash = entry.id;
|
hash = entry.id;
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
|
@ -1247,7 +1251,7 @@ mod tests {
|
||||||
// Add a second Transaction that will produce a
|
// Add a second Transaction that will produce a
|
||||||
// ProgramError<0, ResultWithNegativeTokens> error when processed
|
// ProgramError<0, ResultWithNegativeTokens> error when processed
|
||||||
let keypair2 = Keypair::new();
|
let keypair2 = Keypair::new();
|
||||||
let tx = Transaction::system_new(&keypair, keypair2.pubkey(), 42, last_id);
|
let tx = SystemTransaction::new_account(&keypair, keypair2.pubkey(), 42, last_id, 0);
|
||||||
let entry = Entry::new(&hash, 0, num_hashes, vec![tx]);
|
let entry = Entry::new(&hash, 0, num_hashes, vec![tx]);
|
||||||
hash = entry.id;
|
hash = entry.id;
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
|
@ -1352,8 +1356,13 @@ mod tests {
|
||||||
let alice = Keypair::new();
|
let alice = Keypair::new();
|
||||||
let bob = Keypair::new();
|
let bob = Keypair::new();
|
||||||
|
|
||||||
let tx1 =
|
let tx1 = SystemTransaction::new_account(
|
||||||
Transaction::system_new(&mint_keypair, alice.pubkey(), 1, genesis_block.last_id());
|
&mint_keypair,
|
||||||
|
alice.pubkey(),
|
||||||
|
1,
|
||||||
|
genesis_block.last_id(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
let pay_alice = vec![tx1];
|
let pay_alice = vec![tx1];
|
||||||
|
|
||||||
let lock_result = bank.lock_accounts(&pay_alice);
|
let lock_result = bank.lock_accounts(&pay_alice);
|
||||||
|
@ -1433,9 +1442,11 @@ mod tests {
|
||||||
let last_id = bank.last_id();
|
let last_id = bank.last_id();
|
||||||
|
|
||||||
// ensure bank can process 2 entries that have a common account and no tick is registered
|
// ensure bank can process 2 entries that have a common account and no tick is registered
|
||||||
let tx = Transaction::system_new(&mint_keypair, keypair1.pubkey(), 2, bank.last_id());
|
let tx =
|
||||||
|
SystemTransaction::new_account(&mint_keypair, keypair1.pubkey(), 2, bank.last_id(), 0);
|
||||||
let entry_1 = next_entry(&last_id, 1, vec![tx]);
|
let entry_1 = next_entry(&last_id, 1, vec![tx]);
|
||||||
let tx = Transaction::system_new(&mint_keypair, keypair2.pubkey(), 2, bank.last_id());
|
let tx =
|
||||||
|
SystemTransaction::new_account(&mint_keypair, keypair2.pubkey(), 2, bank.last_id(), 0);
|
||||||
let entry_2 = next_entry(&entry_1.id, 1, vec![tx]);
|
let entry_2 = next_entry(&entry_1.id, 1, vec![tx]);
|
||||||
assert_eq!(bank.par_process_entries(&[entry_1, entry_2]), Ok(()));
|
assert_eq!(bank.par_process_entries(&[entry_1, entry_2]), Ok(()));
|
||||||
assert_eq!(bank.get_balance(&keypair1.pubkey()), 2);
|
assert_eq!(bank.get_balance(&keypair1.pubkey()), 2);
|
||||||
|
@ -1464,11 +1475,12 @@ mod tests {
|
||||||
let entry_1_to_mint = next_entry(
|
let entry_1_to_mint = next_entry(
|
||||||
&bank.last_id(),
|
&bank.last_id(),
|
||||||
1,
|
1,
|
||||||
vec![Transaction::system_new(
|
vec![SystemTransaction::new_account(
|
||||||
&keypair1,
|
&keypair1,
|
||||||
mint_keypair.pubkey(),
|
mint_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
bank.last_id(),
|
bank.last_id(),
|
||||||
|
0,
|
||||||
)],
|
)],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1476,8 +1488,14 @@ mod tests {
|
||||||
&entry_1_to_mint.id,
|
&entry_1_to_mint.id,
|
||||||
1,
|
1,
|
||||||
vec![
|
vec![
|
||||||
Transaction::system_new(&keypair2, keypair3.pubkey(), 2, bank.last_id()), // should be fine
|
SystemTransaction::new_account(&keypair2, keypair3.pubkey(), 2, bank.last_id(), 0), // should be fine
|
||||||
Transaction::system_new(&keypair1, mint_keypair.pubkey(), 2, bank.last_id()), // will collide
|
SystemTransaction::new_account(
|
||||||
|
&keypair1,
|
||||||
|
mint_keypair.pubkey(),
|
||||||
|
2,
|
||||||
|
bank.last_id(),
|
||||||
|
0,
|
||||||
|
), // will collide
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1500,16 +1518,18 @@ mod tests {
|
||||||
let keypair4 = Keypair::new();
|
let keypair4 = Keypair::new();
|
||||||
|
|
||||||
//load accounts
|
//load accounts
|
||||||
let tx = Transaction::system_new(&mint_keypair, keypair1.pubkey(), 1, bank.last_id());
|
let tx =
|
||||||
|
SystemTransaction::new_account(&mint_keypair, keypair1.pubkey(), 1, bank.last_id(), 0);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
let tx = Transaction::system_new(&mint_keypair, keypair2.pubkey(), 1, bank.last_id());
|
let tx =
|
||||||
|
SystemTransaction::new_account(&mint_keypair, keypair2.pubkey(), 1, bank.last_id(), 0);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
|
|
||||||
// ensure bank can process 2 entries that do not have a common account and no tick is registered
|
// ensure bank can process 2 entries that do not have a common account and no tick is registered
|
||||||
let last_id = bank.last_id();
|
let last_id = bank.last_id();
|
||||||
let tx = Transaction::system_new(&keypair1, keypair3.pubkey(), 1, bank.last_id());
|
let tx = SystemTransaction::new_account(&keypair1, keypair3.pubkey(), 1, bank.last_id(), 0);
|
||||||
let entry_1 = next_entry(&last_id, 1, vec![tx]);
|
let entry_1 = next_entry(&last_id, 1, vec![tx]);
|
||||||
let tx = Transaction::system_new(&keypair2, keypair4.pubkey(), 1, bank.last_id());
|
let tx = SystemTransaction::new_account(&keypair2, keypair4.pubkey(), 1, bank.last_id(), 0);
|
||||||
let entry_2 = next_entry(&entry_1.id, 1, vec![tx]);
|
let entry_2 = next_entry(&entry_1.id, 1, vec![tx]);
|
||||||
assert_eq!(bank.par_process_entries(&[entry_1, entry_2]), Ok(()));
|
assert_eq!(bank.par_process_entries(&[entry_1, entry_2]), Ok(()));
|
||||||
assert_eq!(bank.get_balance(&keypair3.pubkey()), 1);
|
assert_eq!(bank.get_balance(&keypair3.pubkey()), 1);
|
||||||
|
@ -1526,18 +1546,20 @@ mod tests {
|
||||||
let keypair4 = Keypair::new();
|
let keypair4 = Keypair::new();
|
||||||
|
|
||||||
//load accounts
|
//load accounts
|
||||||
let tx = Transaction::system_new(&mint_keypair, keypair1.pubkey(), 1, bank.last_id());
|
let tx =
|
||||||
|
SystemTransaction::new_account(&mint_keypair, keypair1.pubkey(), 1, bank.last_id(), 0);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
let tx = Transaction::system_new(&mint_keypair, keypair2.pubkey(), 1, bank.last_id());
|
let tx =
|
||||||
|
SystemTransaction::new_account(&mint_keypair, keypair2.pubkey(), 1, bank.last_id(), 0);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
|
|
||||||
let last_id = bank.last_id();
|
let last_id = bank.last_id();
|
||||||
|
|
||||||
// ensure bank can process 2 entries that do not have a common account and tick is registered
|
// ensure bank can process 2 entries that do not have a common account and tick is registered
|
||||||
let tx = Transaction::system_new(&keypair2, keypair3.pubkey(), 1, bank.last_id());
|
let tx = SystemTransaction::new_account(&keypair2, keypair3.pubkey(), 1, bank.last_id(), 0);
|
||||||
let entry_1 = next_entry(&last_id, 1, vec![tx]);
|
let entry_1 = next_entry(&last_id, 1, vec![tx]);
|
||||||
let tick = next_entry(&entry_1.id, 1, vec![]);
|
let tick = next_entry(&entry_1.id, 1, vec![]);
|
||||||
let tx = Transaction::system_new(&keypair1, keypair4.pubkey(), 1, tick.id);
|
let tx = SystemTransaction::new_account(&keypair1, keypair4.pubkey(), 1, tick.id, 0);
|
||||||
let entry_2 = next_entry(&tick.id, 1, vec![tx]);
|
let entry_2 = next_entry(&tick.id, 1, vec![tx]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.par_process_entries(&[entry_1.clone(), tick.clone(), entry_2.clone()]),
|
bank.par_process_entries(&[entry_1.clone(), tick.clone(), entry_2.clone()]),
|
||||||
|
@ -1547,7 +1569,7 @@ mod tests {
|
||||||
assert_eq!(bank.get_balance(&keypair4.pubkey()), 1);
|
assert_eq!(bank.get_balance(&keypair4.pubkey()), 1);
|
||||||
assert_eq!(bank.last_id(), tick.id);
|
assert_eq!(bank.last_id(), tick.id);
|
||||||
// ensure that an error is returned for an empty account (keypair2)
|
// ensure that an error is returned for an empty account (keypair2)
|
||||||
let tx = Transaction::system_new(&keypair2, keypair3.pubkey(), 1, tick.id);
|
let tx = SystemTransaction::new_account(&keypair2, keypair3.pubkey(), 1, tick.id, 0);
|
||||||
let entry_3 = next_entry(&entry_2.id, 1, vec![tx]);
|
let entry_3 = next_entry(&entry_2.id, 1, vec![tx]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.par_process_entries(&[entry_3]),
|
bank.par_process_entries(&[entry_3]),
|
||||||
|
@ -1625,8 +1647,8 @@ mod tests {
|
||||||
let pubkey = Keypair::new().pubkey();
|
let pubkey = Keypair::new().pubkey();
|
||||||
|
|
||||||
let transactions = vec![
|
let transactions = vec![
|
||||||
Transaction::system_move(&mint_keypair, pubkey, 1, genesis_block.last_id(), 0),
|
SystemTransaction::new_move(&mint_keypair, pubkey, 1, genesis_block.last_id(), 0),
|
||||||
Transaction::system_move(&mint_keypair, pubkey, 1, genesis_block.last_id(), 0),
|
SystemTransaction::new_move(&mint_keypair, pubkey, 1, genesis_block.last_id(), 0),
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut results = vec![Ok(()), Ok(())];
|
let mut results = vec![Ok(()), Ok(())];
|
||||||
|
@ -1698,7 +1720,7 @@ mod tests {
|
||||||
bank.transfer(10, &alice, bob.pubkey(), last_id).unwrap();
|
bank.transfer(10, &alice, bob.pubkey(), last_id).unwrap();
|
||||||
bank.transfer(10, &alice, jack.pubkey(), last_id).unwrap();
|
bank.transfer(10, &alice, jack.pubkey(), last_id).unwrap();
|
||||||
|
|
||||||
let tx = Transaction::storage_new_advertise_last_id(
|
let tx = StorageTransaction::new_advertise_last_id(
|
||||||
&bob,
|
&bob,
|
||||||
storage_last_id,
|
storage_last_id,
|
||||||
last_id,
|
last_id,
|
||||||
|
@ -1709,7 +1731,7 @@ mod tests {
|
||||||
|
|
||||||
let entry_height = 0;
|
let entry_height = 0;
|
||||||
|
|
||||||
let tx = Transaction::storage_new_mining_proof(
|
let tx = StorageTransaction::new_mining_proof(
|
||||||
&jack,
|
&jack,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
last_id,
|
last_id,
|
||||||
|
@ -1729,7 +1751,7 @@ mod tests {
|
||||||
let bank = Arc::new(Bank::new(&genesis_block));
|
let bank = Arc::new(Bank::new(&genesis_block));
|
||||||
let pubkey = Keypair::new().pubkey();
|
let pubkey = Keypair::new().pubkey();
|
||||||
|
|
||||||
let transactions = vec![Transaction::system_move(
|
let transactions = vec![SystemTransaction::new_move(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
pubkey,
|
pubkey,
|
||||||
1,
|
1,
|
||||||
|
@ -1763,7 +1785,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let transactions = vec![Transaction::system_move(
|
let transactions = vec![SystemTransaction::new_move(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
pubkey,
|
pubkey,
|
||||||
2,
|
2,
|
||||||
|
|
|
@ -303,7 +303,6 @@ mod tests {
|
||||||
use crate::packet::to_packets;
|
use crate::packet::to_packets;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -402,14 +401,15 @@ mod tests {
|
||||||
|
|
||||||
// good tx
|
// good tx
|
||||||
let keypair = mint_keypair;
|
let keypair = mint_keypair;
|
||||||
let tx = Transaction::system_new(&keypair, keypair.pubkey(), 1, start_hash);
|
let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, start_hash, 0);
|
||||||
|
|
||||||
// good tx, but no verify
|
// good tx, but no verify
|
||||||
let tx_no_ver = Transaction::system_new(&keypair, keypair.pubkey(), 1, start_hash);
|
let tx_no_ver =
|
||||||
|
SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, start_hash, 0);
|
||||||
|
|
||||||
// bad tx, AccountNotFound
|
// bad tx, AccountNotFound
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx_anf = Transaction::system_new(&keypair, keypair.pubkey(), 1, start_hash);
|
let tx_anf = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, start_hash, 0);
|
||||||
|
|
||||||
// send 'em over
|
// send 'em over
|
||||||
let packets = to_packets(&[tx, tx_no_ver, tx_anf]);
|
let packets = to_packets(&[tx, tx_no_ver, tx_anf]);
|
||||||
|
@ -460,7 +460,13 @@ mod tests {
|
||||||
|
|
||||||
// Process a batch that includes a transaction that receives two tokens.
|
// Process a batch that includes a transaction that receives two tokens.
|
||||||
let alice = Keypair::new();
|
let alice = Keypair::new();
|
||||||
let tx = Transaction::system_new(&mint_keypair, alice.pubkey(), 2, genesis_block.last_id());
|
let tx = SystemTransaction::new_account(
|
||||||
|
&mint_keypair,
|
||||||
|
alice.pubkey(),
|
||||||
|
2,
|
||||||
|
genesis_block.last_id(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
|
||||||
let packets = to_packets(&[tx]);
|
let packets = to_packets(&[tx]);
|
||||||
verified_sender
|
verified_sender
|
||||||
|
@ -468,7 +474,13 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Process a second batch that spends one of those tokens.
|
// Process a second batch that spends one of those tokens.
|
||||||
let tx = Transaction::system_new(&alice, mint_keypair.pubkey(), 1, genesis_block.last_id());
|
let tx = SystemTransaction::new_account(
|
||||||
|
&alice,
|
||||||
|
mint_keypair.pubkey(),
|
||||||
|
1,
|
||||||
|
genesis_block.last_id(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
let packets = to_packets(&[tx]);
|
let packets = to_packets(&[tx]);
|
||||||
verified_sender
|
verified_sender
|
||||||
.send(vec![(packets[0].clone(), vec![1u8])])
|
.send(vec![(packets[0].clone(), vec![1u8])])
|
||||||
|
|
|
@ -102,7 +102,6 @@ mod tests {
|
||||||
use solana_sdk::budget_transaction::BudgetTransaction;
|
use solana_sdk::budget_transaction::BudgetTransaction;
|
||||||
use solana_sdk::hash::{hash, Hash, Hasher};
|
use solana_sdk::hash::{hash, Hash, Hasher};
|
||||||
use solana_sdk::signature::KeypairUtil;
|
use solana_sdk::signature::KeypairUtil;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use std::fs::remove_file;
|
use std::fs::remove_file;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
@ -129,7 +128,7 @@ mod tests {
|
||||||
Entry::new_mut(
|
Entry::new_mut(
|
||||||
&mut id,
|
&mut id,
|
||||||
&mut num_hashes,
|
&mut num_hashes,
|
||||||
vec![Transaction::budget_new_signature(
|
vec![BudgetTransaction::new_signature(
|
||||||
&keypair,
|
&keypair,
|
||||||
keypair.pubkey(),
|
keypair.pubkey(),
|
||||||
keypair.pubkey(),
|
keypair.pubkey(),
|
||||||
|
|
|
@ -166,7 +166,6 @@ pub mod tests {
|
||||||
use bincode::serialize;
|
use bincode::serialize;
|
||||||
use solana_sdk::hash::hash;
|
use solana_sdk::hash::hash;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use solana_sdk::vote_transaction::VoteTransaction;
|
use solana_sdk::vote_transaction::VoteTransaction;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
|
@ -206,7 +205,7 @@ pub mod tests {
|
||||||
|
|
||||||
if i < 6 {
|
if i < 6 {
|
||||||
let vote_tx =
|
let vote_tx =
|
||||||
Transaction::vote_new(&voting_keypair, (i + 1) as u64, last_id, 0);
|
VoteTransaction::new_vote(&voting_keypair, (i + 1) as u64, last_id, 0);
|
||||||
bank.process_transaction(&vote_tx).unwrap();
|
bank.process_transaction(&vote_tx).unwrap();
|
||||||
}
|
}
|
||||||
(voting_keypair, validator_keypair)
|
(voting_keypair, validator_keypair)
|
||||||
|
@ -224,7 +223,7 @@ pub mod tests {
|
||||||
|
|
||||||
// Get another validator to vote, so we now have 2/3 consensus
|
// Get another validator to vote, so we now have 2/3 consensus
|
||||||
let voting_keypair = &vote_accounts[7].0;
|
let voting_keypair = &vote_accounts[7].0;
|
||||||
let vote_tx = Transaction::vote_new(voting_keypair, 7, ids[6], 0);
|
let vote_tx = VoteTransaction::new_vote(voting_keypair, 7, ids[6], 0);
|
||||||
bank.process_transaction(&vote_tx).unwrap();
|
bank.process_transaction(&vote_tx).unwrap();
|
||||||
|
|
||||||
ComputeLeaderConfirmationService::compute_confirmation(
|
ComputeLeaderConfirmationService::compute_confirmation(
|
||||||
|
|
28
src/entry.rs
28
src/entry.rs
|
@ -407,7 +407,7 @@ pub fn make_tiny_test_entries_from_id(start: &Hash, num: usize) -> Vec<Entry> {
|
||||||
Entry::new_mut(
|
Entry::new_mut(
|
||||||
&mut id,
|
&mut id,
|
||||||
&mut num_hashes,
|
&mut num_hashes,
|
||||||
vec![Transaction::budget_new_timestamp(
|
vec![BudgetTransaction::new_timestamp(
|
||||||
&keypair,
|
&keypair,
|
||||||
keypair.pubkey(),
|
keypair.pubkey(),
|
||||||
keypair.pubkey(),
|
keypair.pubkey(),
|
||||||
|
@ -430,7 +430,7 @@ pub fn make_large_test_entries(num_entries: usize) -> Vec<Entry> {
|
||||||
let one = hash(&zero.as_ref());
|
let one = hash(&zero.as_ref());
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
|
|
||||||
let tx = Transaction::budget_new_timestamp(
|
let tx = BudgetTransaction::new_timestamp(
|
||||||
&keypair,
|
&keypair,
|
||||||
keypair.pubkey(),
|
keypair.pubkey(),
|
||||||
keypair.pubkey(),
|
keypair.pubkey(),
|
||||||
|
@ -484,11 +484,9 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::entry::Entry;
|
use crate::entry::Entry;
|
||||||
use crate::packet::{to_blobs, BLOB_DATA_SIZE, PACKET_DATA_SIZE};
|
use crate::packet::{to_blobs, BLOB_DATA_SIZE, PACKET_DATA_SIZE};
|
||||||
use solana_sdk::budget_transaction::BudgetTransaction;
|
|
||||||
use solana_sdk::hash::hash;
|
use solana_sdk::hash::hash;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -507,8 +505,8 @@ mod tests {
|
||||||
|
|
||||||
// First, verify entries
|
// First, verify entries
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx0 = Transaction::system_new(&keypair, keypair.pubkey(), 0, zero);
|
let tx0 = SystemTransaction::new_account(&keypair, keypair.pubkey(), 0, zero, 0);
|
||||||
let tx1 = Transaction::system_new(&keypair, keypair.pubkey(), 1, zero);
|
let tx1 = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, zero, 0);
|
||||||
let mut e0 = Entry::new(&zero, 0, 0, vec![tx0.clone(), tx1.clone()]);
|
let mut e0 = Entry::new(&zero, 0, 0, vec![tx0.clone(), tx1.clone()]);
|
||||||
assert!(e0.verify(&zero));
|
assert!(e0.verify(&zero));
|
||||||
|
|
||||||
|
@ -524,7 +522,7 @@ mod tests {
|
||||||
|
|
||||||
// First, verify entries
|
// First, verify entries
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx0 = Transaction::budget_new_timestamp(
|
let tx0 = BudgetTransaction::new_timestamp(
|
||||||
&keypair,
|
&keypair,
|
||||||
keypair.pubkey(),
|
keypair.pubkey(),
|
||||||
keypair.pubkey(),
|
keypair.pubkey(),
|
||||||
|
@ -532,7 +530,7 @@ mod tests {
|
||||||
zero,
|
zero,
|
||||||
);
|
);
|
||||||
let tx1 =
|
let tx1 =
|
||||||
Transaction::budget_new_signature(&keypair, keypair.pubkey(), keypair.pubkey(), zero);
|
BudgetTransaction::new_signature(&keypair, keypair.pubkey(), keypair.pubkey(), zero);
|
||||||
let mut e0 = Entry::new(&zero, 0, 0, vec![tx0.clone(), tx1.clone()]);
|
let mut e0 = Entry::new(&zero, 0, 0, vec![tx0.clone(), tx1.clone()]);
|
||||||
assert!(e0.verify(&zero));
|
assert!(e0.verify(&zero));
|
||||||
|
|
||||||
|
@ -554,7 +552,7 @@ mod tests {
|
||||||
assert_eq!(tick.id, zero);
|
assert_eq!(tick.id, zero);
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx0 = Transaction::budget_new_timestamp(
|
let tx0 = BudgetTransaction::new_timestamp(
|
||||||
&keypair,
|
&keypair,
|
||||||
keypair.pubkey(),
|
keypair.pubkey(),
|
||||||
keypair.pubkey(),
|
keypair.pubkey(),
|
||||||
|
@ -571,7 +569,7 @@ mod tests {
|
||||||
fn test_next_entry_panic() {
|
fn test_next_entry_panic() {
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx = Transaction::system_new(&keypair, keypair.pubkey(), 0, zero);
|
let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 0, zero, 0);
|
||||||
next_entry(&zero, 0, vec![tx]);
|
next_entry(&zero, 0, vec![tx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,7 +577,7 @@ mod tests {
|
||||||
fn test_serialized_size() {
|
fn test_serialized_size() {
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx = Transaction::system_new(&keypair, keypair.pubkey(), 0, zero);
|
let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 0, zero, 0);
|
||||||
let entry = next_entry(&zero, 1, vec![tx.clone()]);
|
let entry = next_entry(&zero, 1, vec![tx.clone()]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Entry::serialized_size(&[tx]),
|
Entry::serialized_size(&[tx]),
|
||||||
|
@ -607,8 +605,8 @@ mod tests {
|
||||||
let one = hash(&zero.as_ref());
|
let one = hash(&zero.as_ref());
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let vote_account = Keypair::new();
|
let vote_account = Keypair::new();
|
||||||
let tx0 = Transaction::vote_new(&vote_account, 1, one, 1);
|
let tx0 = VoteTransaction::new_vote(&vote_account, 1, one, 1);
|
||||||
let tx1 = Transaction::budget_new_timestamp(
|
let tx1 = BudgetTransaction::new_timestamp(
|
||||||
&keypair,
|
&keypair,
|
||||||
keypair.pubkey(),
|
keypair.pubkey(),
|
||||||
keypair.pubkey(),
|
keypair.pubkey(),
|
||||||
|
@ -655,8 +653,8 @@ mod tests {
|
||||||
let next_id = hash(&id.as_ref());
|
let next_id = hash(&id.as_ref());
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let vote_account = Keypair::new();
|
let vote_account = Keypair::new();
|
||||||
let tx_small = Transaction::vote_new(&vote_account, 1, next_id, 2);
|
let tx_small = VoteTransaction::new_vote(&vote_account, 1, next_id, 2);
|
||||||
let tx_large = Transaction::budget_new(&keypair, keypair.pubkey(), 1, next_id);
|
let tx_large = BudgetTransaction::new(&keypair, keypair.pubkey(), 1, next_id);
|
||||||
|
|
||||||
let tx_small_size = tx_small.serialized_size().unwrap() as usize;
|
let tx_small_size = tx_small.serialized_size().unwrap() as usize;
|
||||||
let tx_large_size = tx_large.serialized_size().unwrap() as usize;
|
let tx_large_size = tx_large.serialized_size().unwrap() as usize;
|
||||||
|
|
|
@ -12,7 +12,6 @@ use solana_sdk::hash::{hash, Hash};
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use solana_sdk::vote_program::{self, VoteProgram};
|
use solana_sdk::vote_program::{self, VoteProgram};
|
||||||
use solana_sdk::vote_transaction::VoteTransaction;
|
use solana_sdk::vote_transaction::VoteTransaction;
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
@ -497,7 +496,7 @@ pub fn make_active_set_entries(
|
||||||
) -> (Vec<Entry>, VotingKeypair) {
|
) -> (Vec<Entry>, VotingKeypair) {
|
||||||
// 1) Create transfer token entry
|
// 1) Create transfer token entry
|
||||||
let transfer_tx =
|
let transfer_tx =
|
||||||
Transaction::system_new(&token_source, active_keypair.pubkey(), 3, *last_tick_id);
|
SystemTransaction::new_account(&token_source, active_keypair.pubkey(), 3, *last_tick_id, 0);
|
||||||
let transfer_entry = Entry::new(last_entry_id, 0, 1, vec![transfer_tx]);
|
let transfer_entry = Entry::new(last_entry_id, 0, 1, vec![transfer_tx]);
|
||||||
let mut last_entry_id = transfer_entry.id;
|
let mut last_entry_id = transfer_entry.id;
|
||||||
|
|
||||||
|
@ -506,12 +505,12 @@ pub fn make_active_set_entries(
|
||||||
let vote_account_id = voting_keypair.pubkey();
|
let vote_account_id = voting_keypair.pubkey();
|
||||||
|
|
||||||
let new_vote_account_tx =
|
let new_vote_account_tx =
|
||||||
Transaction::vote_account_new(active_keypair, vote_account_id, *last_tick_id, 1, 1);
|
VoteTransaction::new_account(active_keypair, vote_account_id, *last_tick_id, 1, 1);
|
||||||
let new_vote_account_entry = Entry::new(&last_entry_id, 0, 1, vec![new_vote_account_tx]);
|
let new_vote_account_entry = Entry::new(&last_entry_id, 0, 1, vec![new_vote_account_tx]);
|
||||||
last_entry_id = new_vote_account_entry.id;
|
last_entry_id = new_vote_account_entry.id;
|
||||||
|
|
||||||
// 3) Create vote entry
|
// 3) Create vote entry
|
||||||
let vote_tx = Transaction::vote_new(&voting_keypair, 1, *last_tick_id, 0);
|
let vote_tx = VoteTransaction::new_vote(&voting_keypair, 1, *last_tick_id, 0);
|
||||||
let vote_entry = Entry::new(&last_entry_id, 0, 1, vec![vote_tx]);
|
let vote_entry = Entry::new(&last_entry_id, 0, 1, vec![vote_tx]);
|
||||||
last_entry_id = vote_entry.id;
|
last_entry_id = vote_entry.id;
|
||||||
|
|
||||||
|
@ -554,7 +553,7 @@ pub mod tests {
|
||||||
num_tokens: u64,
|
num_tokens: u64,
|
||||||
last_id: Hash,
|
last_id: Hash,
|
||||||
) {
|
) {
|
||||||
let tx = Transaction::vote_account_new(
|
let tx = VoteTransaction::new_account(
|
||||||
from_keypair,
|
from_keypair,
|
||||||
voting_keypair.pubkey(),
|
voting_keypair.pubkey(),
|
||||||
last_id,
|
last_id,
|
||||||
|
@ -565,7 +564,7 @@ pub mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_vote(voting_keypair: &VotingKeypair, bank: &Bank, height: u64, last_id: Hash) {
|
fn push_vote(voting_keypair: &VotingKeypair, bank: &Bank, height: u64, last_id: Hash) {
|
||||||
let new_vote_tx = Transaction::vote_new(voting_keypair, height, last_id, 0);
|
let new_vote_tx = VoteTransaction::new_vote(voting_keypair, height, last_id, 0);
|
||||||
bank.process_transaction(&new_vote_tx).unwrap();
|
bank.process_transaction(&new_vote_tx).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -464,7 +464,6 @@ mod tests {
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::net::{Ipv4Addr, SocketAddr, UdpSocket};
|
use std::net::{Ipv4Addr, SocketAddr, UdpSocket};
|
||||||
|
@ -503,7 +502,7 @@ mod tests {
|
||||||
fn test_to_packets() {
|
fn test_to_packets() {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let hash = Hash::new(&[1; 32]);
|
let hash = Hash::new(&[1; 32]);
|
||||||
let tx = Transaction::system_new(&keypair, keypair.pubkey(), 1, hash);
|
let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, hash, 0);
|
||||||
let rv = to_packets(&vec![tx.clone(); 1]);
|
let rv = to_packets(&vec![tx.clone(); 1]);
|
||||||
assert_eq!(rv.len(), 1);
|
assert_eq!(rv.len(), 1);
|
||||||
assert_eq!(rv[0].read().unwrap().packets.len(), 1);
|
assert_eq!(rv[0].read().unwrap().packets.len(), 1);
|
||||||
|
|
|
@ -21,7 +21,6 @@ use solana_metrics::{influxdb, submit};
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::timing::duration_as_ms;
|
use solana_sdk::timing::duration_as_ms;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use solana_sdk::vote_transaction::VoteTransaction;
|
use solana_sdk::vote_transaction::VoteTransaction;
|
||||||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
|
@ -146,8 +145,12 @@ impl ReplayStage {
|
||||||
if 0 == num_ticks_to_next_vote {
|
if 0 == num_ticks_to_next_vote {
|
||||||
if let Some(voting_keypair) = voting_keypair {
|
if let Some(voting_keypair) = voting_keypair {
|
||||||
let keypair = voting_keypair.as_ref();
|
let keypair = voting_keypair.as_ref();
|
||||||
let vote =
|
let vote = VoteTransaction::new_vote(
|
||||||
Transaction::vote_new(keypair, bank.tick_height(), bank.last_id(), 0);
|
keypair,
|
||||||
|
bank.tick_height(),
|
||||||
|
bank.last_id(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
cluster_info.write().unwrap().push_vote(vote);
|
cluster_info.write().unwrap().push_vote(vote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -478,7 +481,7 @@ mod test {
|
||||||
);
|
);
|
||||||
|
|
||||||
let keypair = voting_keypair.as_ref();
|
let keypair = voting_keypair.as_ref();
|
||||||
let vote = Transaction::vote_new(keypair, bank.tick_height(), bank.last_id(), 0);
|
let vote = VoteTransaction::new_vote(keypair, bank.tick_height(), bank.last_id(), 0);
|
||||||
cluster_info_me.write().unwrap().push_vote(vote);
|
cluster_info_me.write().unwrap().push_vote(vote);
|
||||||
|
|
||||||
// Send ReplayStage an entry, should see it on the ledger writer receiver
|
// Send ReplayStage an entry, should see it on the ledger writer receiver
|
||||||
|
@ -585,7 +588,7 @@ mod test {
|
||||||
);
|
);
|
||||||
|
|
||||||
let keypair = voting_keypair.as_ref();
|
let keypair = voting_keypair.as_ref();
|
||||||
let vote = Transaction::vote_new(keypair, bank.tick_height(), bank.last_id(), 0);
|
let vote = VoteTransaction::new_vote(keypair, bank.tick_height(), bank.last_id(), 0);
|
||||||
cluster_info_me.write().unwrap().push_vote(vote);
|
cluster_info_me.write().unwrap().push_vote(vote);
|
||||||
|
|
||||||
// Send enough ticks to trigger leader rotation
|
// Send enough ticks to trigger leader rotation
|
||||||
|
|
|
@ -19,7 +19,6 @@ use solana_drone::drone::{request_airdrop_transaction, DRONE_PORT};
|
||||||
use solana_sdk::hash::{Hash, Hasher};
|
use solana_sdk::hash::{Hash, Hasher};
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
||||||
use solana_sdk::storage_program::StorageTransaction;
|
use solana_sdk::storage_program::StorageTransaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
|
@ -262,7 +261,7 @@ impl Replicator {
|
||||||
Ok(hash) => {
|
Ok(hash) => {
|
||||||
let last_id = client.get_last_id();
|
let last_id = client.get_last_id();
|
||||||
info!("sampled hash: {}", hash);
|
info!("sampled hash: {}", hash);
|
||||||
let mut tx = Transaction::storage_new_mining_proof(
|
let mut tx = StorageTransaction::new_mining_proof(
|
||||||
&keypair,
|
&keypair,
|
||||||
hash,
|
hash,
|
||||||
last_id,
|
last_id,
|
||||||
|
|
20
src/rpc.rs
20
src/rpc.rs
|
@ -453,7 +453,6 @@ mod tests {
|
||||||
use solana_sdk::hash::{hash, Hash};
|
use solana_sdk::hash::{hash, Hash};
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
|
|
||||||
fn start_rpc_handler_with_tx(pubkey: Pubkey) -> (MetaIoHandler<Meta>, Meta, Hash, Keypair) {
|
fn start_rpc_handler_with_tx(pubkey: Pubkey) -> (MetaIoHandler<Meta>, Meta, Hash, Keypair) {
|
||||||
|
@ -461,7 +460,7 @@ mod tests {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
|
|
||||||
let last_id = bank.last_id();
|
let last_id = bank.last_id();
|
||||||
let tx = Transaction::system_move(&alice, pubkey, 20, last_id, 0);
|
let tx = SystemTransaction::new_move(&alice, pubkey, 20, last_id, 0);
|
||||||
bank.process_transaction(&tx).expect("process transaction");
|
bank.process_transaction(&tx).expect("process transaction");
|
||||||
|
|
||||||
let request_processor = Arc::new(RwLock::new(JsonRpcRequestProcessor::new(
|
let request_processor = Arc::new(RwLock::new(JsonRpcRequestProcessor::new(
|
||||||
|
@ -534,7 +533,7 @@ mod tests {
|
||||||
JsonRpcRequestProcessor::new(arc_bank.clone(), StorageState::default());
|
JsonRpcRequestProcessor::new(arc_bank.clone(), StorageState::default());
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let last_id = arc_bank.last_id();
|
let last_id = arc_bank.last_id();
|
||||||
let tx = Transaction::system_move(&alice, bob_pubkey, 20, last_id, 0);
|
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0);
|
||||||
arc_bank
|
arc_bank
|
||||||
.process_transaction(&tx)
|
.process_transaction(&tx)
|
||||||
.expect("process transaction");
|
.expect("process transaction");
|
||||||
|
@ -609,7 +608,7 @@ mod tests {
|
||||||
fn test_rpc_confirm_tx() {
|
fn test_rpc_confirm_tx() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, last_id, alice) = start_rpc_handler_with_tx(bob_pubkey);
|
let (io, meta, last_id, alice) = start_rpc_handler_with_tx(bob_pubkey);
|
||||||
let tx = Transaction::system_move(&alice, bob_pubkey, 20, last_id, 0);
|
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0);
|
||||||
|
|
||||||
let req = format!(
|
let req = format!(
|
||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"confirmTransaction","params":["{}"]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"confirmTransaction","params":["{}"]}}"#,
|
||||||
|
@ -628,7 +627,7 @@ mod tests {
|
||||||
fn test_rpc_get_signature_status() {
|
fn test_rpc_get_signature_status() {
|
||||||
let bob_pubkey = Keypair::new().pubkey();
|
let bob_pubkey = Keypair::new().pubkey();
|
||||||
let (io, meta, last_id, alice) = start_rpc_handler_with_tx(bob_pubkey);
|
let (io, meta, last_id, alice) = start_rpc_handler_with_tx(bob_pubkey);
|
||||||
let tx = Transaction::system_move(&alice, bob_pubkey, 20, last_id, 0);
|
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0);
|
||||||
|
|
||||||
let req = format!(
|
let req = format!(
|
||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#,
|
||||||
|
@ -643,7 +642,7 @@ mod tests {
|
||||||
assert_eq!(expected, result);
|
assert_eq!(expected, result);
|
||||||
|
|
||||||
// Test getSignatureStatus request on unprocessed tx
|
// Test getSignatureStatus request on unprocessed tx
|
||||||
let tx = Transaction::system_move(&alice, bob_pubkey, 10, last_id, 0);
|
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 10, last_id, 0);
|
||||||
let req = format!(
|
let req = format!(
|
||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#,
|
||||||
tx.signatures[0]
|
tx.signatures[0]
|
||||||
|
@ -770,8 +769,13 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_verify_signature() {
|
fn test_rpc_verify_signature() {
|
||||||
let tx =
|
let tx = SystemTransaction::new_move(
|
||||||
Transaction::system_move(&Keypair::new(), Keypair::new().pubkey(), 20, hash(&[0]), 0);
|
&Keypair::new(),
|
||||||
|
Keypair::new().pubkey(),
|
||||||
|
20,
|
||||||
|
hash(&[0]),
|
||||||
|
0,
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
verify_signature(&tx.signatures[0].to_string()).unwrap(),
|
verify_signature(&tx.signatures[0].to_string()).unwrap(),
|
||||||
tx.signatures[0]
|
tx.signatures[0]
|
||||||
|
|
|
@ -93,6 +93,6 @@ pub fn request_airdrop_transaction(
|
||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let last_id = Hash::default();
|
let last_id = Hash::default();
|
||||||
let tx = Transaction::system_new(&key, to, 50, last_id);
|
let tx = SystemTransaction::new_account(&key, to, 50, last_id, 0);
|
||||||
Ok(tx)
|
Ok(tx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -391,7 +391,6 @@ mod tests {
|
||||||
use solana_sdk::budget_transaction::BudgetTransaction;
|
use solana_sdk::budget_transaction::BudgetTransaction;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use std::net::{IpAddr, Ipv4Addr};
|
use std::net::{IpAddr, Ipv4Addr};
|
||||||
use tokio::prelude::{Async, Stream};
|
use tokio::prelude::{Async, Stream};
|
||||||
|
|
||||||
|
@ -420,7 +419,7 @@ mod tests {
|
||||||
arc_bank.set_subscriptions(Box::new(subscription));
|
arc_bank.set_subscriptions(Box::new(subscription));
|
||||||
|
|
||||||
// Test signature subscription
|
// Test signature subscription
|
||||||
let tx = Transaction::system_move(&alice, bob_pubkey, 20, last_id, 0);
|
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0);
|
||||||
|
|
||||||
let (subscriber, _id_receiver, mut receiver) =
|
let (subscriber, _id_receiver, mut receiver) =
|
||||||
Subscriber::new_test("signatureNotification");
|
Subscriber::new_test("signatureNotification");
|
||||||
|
@ -455,7 +454,7 @@ mod tests {
|
||||||
let rpc = RpcSolPubSubImpl::new(rpc_bank.clone());
|
let rpc = RpcSolPubSubImpl::new(rpc_bank.clone());
|
||||||
io.extend_with(rpc.to_delegate());
|
io.extend_with(rpc.to_delegate());
|
||||||
|
|
||||||
let tx = Transaction::system_move(&alice, bob_pubkey, 20, last_id, 0);
|
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0);
|
||||||
let req = format!(
|
let req = format!(
|
||||||
r#"{{"jsonrpc":"2.0","id":1,"method":"signatureSubscribe","params":["{}"]}}"#,
|
r#"{{"jsonrpc":"2.0","id":1,"method":"signatureSubscribe","params":["{}"]}}"#,
|
||||||
tx.signatures[0].to_string()
|
tx.signatures[0].to_string()
|
||||||
|
@ -509,7 +508,7 @@ mod tests {
|
||||||
let (subscriber, _id_receiver, mut receiver) = Subscriber::new_test("accountNotification");
|
let (subscriber, _id_receiver, mut receiver) = Subscriber::new_test("accountNotification");
|
||||||
rpc.subscribe_to_account_updates(subscriber, contract_state.pubkey().to_string());
|
rpc.subscribe_to_account_updates(subscriber, contract_state.pubkey().to_string());
|
||||||
|
|
||||||
let tx = Transaction::system_create(
|
let tx = SystemTransaction::new_program_account(
|
||||||
&alice,
|
&alice,
|
||||||
contract_funds.pubkey(),
|
contract_funds.pubkey(),
|
||||||
last_id,
|
last_id,
|
||||||
|
@ -522,7 +521,7 @@ mod tests {
|
||||||
.process_transaction(&tx)
|
.process_transaction(&tx)
|
||||||
.expect("process transaction");
|
.expect("process transaction");
|
||||||
|
|
||||||
let tx = Transaction::system_create(
|
let tx = SystemTransaction::new_program_account(
|
||||||
&alice,
|
&alice,
|
||||||
contract_state.pubkey(),
|
contract_state.pubkey(),
|
||||||
last_id,
|
last_id,
|
||||||
|
@ -564,7 +563,7 @@ mod tests {
|
||||||
assert_eq!(serde_json::to_string(&expected).unwrap(), response);
|
assert_eq!(serde_json::to_string(&expected).unwrap(), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
let tx = Transaction::budget_new_when_signed(
|
let tx = BudgetTransaction::new_when_signed(
|
||||||
&contract_funds,
|
&contract_funds,
|
||||||
bob_pubkey,
|
bob_pubkey,
|
||||||
contract_state.pubkey(),
|
contract_state.pubkey(),
|
||||||
|
@ -603,12 +602,12 @@ mod tests {
|
||||||
assert_eq!(serde_json::to_string(&expected).unwrap(), response);
|
assert_eq!(serde_json::to_string(&expected).unwrap(), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
let tx = Transaction::system_new(&alice, witness.pubkey(), 1, last_id);
|
let tx = SystemTransaction::new_account(&alice, witness.pubkey(), 1, last_id, 0);
|
||||||
arc_bank
|
arc_bank
|
||||||
.process_transaction(&tx)
|
.process_transaction(&tx)
|
||||||
.expect("process transaction");
|
.expect("process transaction");
|
||||||
sleep(Duration::from_millis(200));
|
sleep(Duration::from_millis(200));
|
||||||
let tx = Transaction::budget_new_signature(
|
let tx = BudgetTransaction::new_signature(
|
||||||
&witness,
|
&witness,
|
||||||
contract_state.pubkey(),
|
contract_state.pubkey(),
|
||||||
bob_pubkey,
|
bob_pubkey,
|
||||||
|
@ -696,7 +695,7 @@ mod tests {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let alice = Keypair::new();
|
let alice = Keypair::new();
|
||||||
let last_id = bank.last_id();
|
let last_id = bank.last_id();
|
||||||
let tx = Transaction::system_create(
|
let tx = SystemTransaction::new_program_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
alice.pubkey(),
|
alice.pubkey(),
|
||||||
last_id,
|
last_id,
|
||||||
|
@ -741,7 +740,7 @@ mod tests {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let alice = Keypair::new();
|
let alice = Keypair::new();
|
||||||
let last_id = bank.last_id();
|
let last_id = bank.last_id();
|
||||||
let tx = Transaction::system_move(&mint_keypair, alice.pubkey(), 20, last_id, 0);
|
let tx = SystemTransaction::new_move(&mint_keypair, alice.pubkey(), 20, last_id, 0);
|
||||||
let signature = tx.signatures[0];
|
let signature = tx.signatures[0];
|
||||||
bank.process_transaction(&tx).unwrap();
|
bank.process_transaction(&tx).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -15,22 +15,17 @@ use rand::{Rng, SeedableRng};
|
||||||
use rand_chacha::ChaChaRng;
|
use rand_chacha::ChaChaRng;
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::Keypair;
|
use solana_sdk::signature::{Keypair, Signature};
|
||||||
use solana_sdk::signature::Signature;
|
use solana_sdk::storage_program::{self, StorageProgram, StorageTransaction};
|
||||||
use solana_sdk::storage_program;
|
|
||||||
use solana_sdk::storage_program::StorageProgram;
|
|
||||||
use solana_sdk::storage_program::StorageTransaction;
|
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use solana_sdk::vote_program;
|
use solana_sdk::vote_program;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::mpsc::RecvTimeoutError;
|
use std::sync::mpsc::{channel, RecvTimeoutError, Sender};
|
||||||
use std::sync::mpsc::{channel, Sender};
|
|
||||||
use std::sync::{Arc, RwLock};
|
use std::sync::{Arc, RwLock};
|
||||||
use std::thread::sleep;
|
use std::thread::{self, sleep, Builder, JoinHandle};
|
||||||
use std::thread::{self, Builder, JoinHandle};
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
// Block of hash answers to validate against
|
// Block of hash answers to validate against
|
||||||
|
@ -277,7 +272,7 @@ impl StorageStage {
|
||||||
let mut seed = [0u8; 32];
|
let mut seed = [0u8; 32];
|
||||||
let signature = keypair.sign(&entry_id.as_ref());
|
let signature = keypair.sign(&entry_id.as_ref());
|
||||||
|
|
||||||
let tx = Transaction::storage_new_advertise_last_id(
|
let tx = StorageTransaction::new_advertise_last_id(
|
||||||
keypair,
|
keypair,
|
||||||
entry_id,
|
entry_id,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
|
@ -453,7 +448,6 @@ mod tests {
|
||||||
use solana_sdk::hash::Hasher;
|
use solana_sdk::hash::Hasher;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use solana_sdk::vote_transaction::VoteTransaction;
|
use solana_sdk::vote_transaction::VoteTransaction;
|
||||||
use std::cmp::{max, min};
|
use std::cmp::{max, min};
|
||||||
use std::fs::remove_dir_all;
|
use std::fs::remove_dir_all;
|
||||||
|
@ -602,9 +596,9 @@ mod tests {
|
||||||
reference_keys = vec![0; keys.len()];
|
reference_keys = vec![0; keys.len()];
|
||||||
reference_keys.copy_from_slice(keys);
|
reference_keys.copy_from_slice(keys);
|
||||||
}
|
}
|
||||||
let mut vote_txs: Vec<Transaction> = Vec::new();
|
let mut vote_txs: Vec<_> = Vec::new();
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let vote_tx = Transaction::vote_new(&keypair, 123456, Hash::default(), 1);
|
let vote_tx = VoteTransaction::new_vote(&keypair, 123456, Hash::default(), 1);
|
||||||
vote_txs.push(vote_tx);
|
vote_txs.push(vote_tx);
|
||||||
let vote_entries = vec![Entry::new(&Hash::default(), 0, 1, vote_txs)];
|
let vote_entries = vec![Entry::new(&Hash::default(), 0, 1, vote_txs)];
|
||||||
storage_entry_sender.send(vote_entries).unwrap();
|
storage_entry_sender.send(vote_entries).unwrap();
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::*;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
|
|
||||||
pub fn test_tx() -> Transaction {
|
pub fn test_tx() -> Transaction {
|
||||||
let keypair1 = Keypair::new();
|
let keypair1 = Keypair::new();
|
||||||
let pubkey1 = keypair1.pubkey();
|
let pubkey1 = keypair1.pubkey();
|
||||||
let zero = Hash::default();
|
let zero = Hash::default();
|
||||||
Transaction::system_new(&keypair1, pubkey1, 42, zero)
|
SystemTransaction::new_account(&keypair1, pubkey1, 42, zero, 0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ impl ThinClient {
|
||||||
last_id: &Hash,
|
last_id: &Hash,
|
||||||
) -> io::Result<Signature> {
|
) -> io::Result<Signature> {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
let tx = Transaction::system_new(keypair, to, n, *last_id);
|
let tx = SystemTransaction::new_account(keypair, to, n, *last_id, 0);
|
||||||
let result = self.transfer_signed(&tx);
|
let result = self.transfer_signed(&tx);
|
||||||
solana_metrics::submit(
|
solana_metrics::submit(
|
||||||
influxdb::Point::new("thinclient")
|
influxdb::Point::new("thinclient")
|
||||||
|
@ -518,13 +518,13 @@ mod tests {
|
||||||
|
|
||||||
let last_id = client.get_last_id();
|
let last_id = client.get_last_id();
|
||||||
|
|
||||||
let tx = Transaction::system_new(&alice, bob_pubkey, 500, last_id);
|
let tx = SystemTransaction::new_account(&alice, bob_pubkey, 500, last_id, 0);
|
||||||
|
|
||||||
let _sig = client.transfer_signed(&tx).unwrap();
|
let _sig = client.transfer_signed(&tx).unwrap();
|
||||||
|
|
||||||
let last_id = client.get_last_id();
|
let last_id = client.get_last_id();
|
||||||
|
|
||||||
let mut tr2 = Transaction::system_new(&alice, bob_pubkey, 501, last_id);
|
let mut tr2 = SystemTransaction::new_account(&alice, bob_pubkey, 501, last_id, 0);
|
||||||
let mut instruction2 = deserialize(tr2.userdata(0)).unwrap();
|
let mut instruction2 = deserialize(tr2.userdata(0)).unwrap();
|
||||||
if let SystemInstruction::Move { ref mut tokens } = instruction2 {
|
if let SystemInstruction::Move { ref mut tokens } = instruction2 {
|
||||||
*tokens = 502;
|
*tokens = 502;
|
||||||
|
@ -577,7 +577,7 @@ mod tests {
|
||||||
let last_id = client.get_last_id();
|
let last_id = client.get_last_id();
|
||||||
|
|
||||||
let transaction =
|
let transaction =
|
||||||
VoteTransaction::vote_account_new(&validator_keypair, vote_account_id, last_id, 1, 1);
|
VoteTransaction::new_account(&validator_keypair, vote_account_id, last_id, 1, 1);
|
||||||
let signature = client.transfer_signed(&transaction).unwrap();
|
let signature = client.transfer_signed(&transaction).unwrap();
|
||||||
client.poll_for_signature(&signature).unwrap();
|
client.poll_for_signature(&signature).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,6 @@ pub mod tests {
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use std::fs::remove_dir_all;
|
use std::fs::remove_dir_all;
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
|
@ -326,11 +325,12 @@ pub mod tests {
|
||||||
let entry_tick0 = Entry::new(&cur_hash, 0, i + 1, vec![]);
|
let entry_tick0 = Entry::new(&cur_hash, 0, i + 1, vec![]);
|
||||||
cur_hash = entry_tick0.id;
|
cur_hash = entry_tick0.id;
|
||||||
|
|
||||||
let tx0 = Transaction::system_new(
|
let tx0 = SystemTransaction::new_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
bob_keypair.pubkey(),
|
bob_keypair.pubkey(),
|
||||||
transfer_amount,
|
transfer_amount,
|
||||||
cur_hash,
|
cur_hash,
|
||||||
|
0,
|
||||||
);
|
);
|
||||||
bank.register_tick(&cur_hash);
|
bank.register_tick(&cur_hash);
|
||||||
let entry_tick1 = Entry::new(&cur_hash, 0, i + 1, vec![]);
|
let entry_tick1 = Entry::new(&cur_hash, 0, i + 1, vec![]);
|
||||||
|
|
|
@ -23,7 +23,6 @@ use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::timing::duration_as_s;
|
use solana_sdk::timing::duration_as_s;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use std::collections::{HashSet, VecDeque};
|
use std::collections::{HashSet, VecDeque};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::remove_dir_all;
|
use std::fs::remove_dir_all;
|
||||||
|
@ -1817,7 +1816,7 @@ fn send_tx_and_retry_get_balance(
|
||||||
let mut client = mk_client(leader);
|
let mut client = mk_client(leader);
|
||||||
trace!("getting leader last_id");
|
trace!("getting leader last_id");
|
||||||
let last_id = client.get_last_id();
|
let last_id = client.get_last_id();
|
||||||
let mut tx = Transaction::system_new(&alice, *bob_pubkey, transfer_amount, last_id);
|
let mut tx = SystemTransaction::new_account(&alice, *bob_pubkey, transfer_amount, last_id, 0);
|
||||||
info!(
|
info!(
|
||||||
"executing transfer of {} from {} to {}",
|
"executing transfer of {} from {} to {}",
|
||||||
transfer_amount,
|
transfer_amount,
|
||||||
|
|
|
@ -56,7 +56,7 @@ impl Loader {
|
||||||
|
|
||||||
// allocate, populate, finalize, and spawn loader
|
// allocate, populate, finalize, and spawn loader
|
||||||
|
|
||||||
let tx = Transaction::system_create(
|
let tx = SystemTransaction::new_program_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
loader.pubkey(),
|
loader.pubkey(),
|
||||||
genesis_block.last_id(),
|
genesis_block.last_id(),
|
||||||
|
@ -68,7 +68,7 @@ impl Loader {
|
||||||
check_tx_results(&bank, &tx, bank.process_transactions(&vec![tx.clone()]));
|
check_tx_results(&bank, &tx, bank.process_transactions(&vec![tx.clone()]));
|
||||||
|
|
||||||
let name = String::from(loader_name);
|
let name = String::from(loader_name);
|
||||||
let tx = Transaction::loader_write(
|
let tx = LoaderTransaction::new_write(
|
||||||
&loader,
|
&loader,
|
||||||
solana_native_loader::id(),
|
solana_native_loader::id(),
|
||||||
0,
|
0,
|
||||||
|
@ -78,7 +78,7 @@ impl Loader {
|
||||||
);
|
);
|
||||||
check_tx_results(&bank, &tx, bank.process_transactions(&vec![tx.clone()]));
|
check_tx_results(&bank, &tx, bank.process_transactions(&vec![tx.clone()]));
|
||||||
|
|
||||||
let tx = Transaction::loader_finalize(
|
let tx = LoaderTransaction::new_finalize(
|
||||||
&loader,
|
&loader,
|
||||||
solana_native_loader::id(),
|
solana_native_loader::id(),
|
||||||
genesis_block.last_id(),
|
genesis_block.last_id(),
|
||||||
|
@ -86,7 +86,7 @@ impl Loader {
|
||||||
);
|
);
|
||||||
check_tx_results(&bank, &tx, bank.process_transactions(&vec![tx.clone()]));
|
check_tx_results(&bank, &tx, bank.process_transactions(&vec![tx.clone()]));
|
||||||
|
|
||||||
let tx = Transaction::system_spawn(&loader, genesis_block.last_id(), 0);
|
let tx = SystemTransaction::new_spawn(&loader, genesis_block.last_id(), 0);
|
||||||
check_tx_results(&bank, &tx, bank.process_transactions(&vec![tx.clone()]));
|
check_tx_results(&bank, &tx, bank.process_transactions(&vec![tx.clone()]));
|
||||||
|
|
||||||
Loader {
|
Loader {
|
||||||
|
@ -135,7 +135,7 @@ impl Program {
|
||||||
|
|
||||||
// allocate, populate, finalize and spawn program
|
// allocate, populate, finalize and spawn program
|
||||||
|
|
||||||
let tx = Transaction::system_create(
|
let tx = SystemTransaction::new_program_account(
|
||||||
&loader.mint_keypair,
|
&loader.mint_keypair,
|
||||||
program.pubkey(),
|
program.pubkey(),
|
||||||
loader.genesis_block.last_id(),
|
loader.genesis_block.last_id(),
|
||||||
|
@ -153,7 +153,7 @@ impl Program {
|
||||||
let chunk_size = 256; // Size of chunk just needs to fit into tx
|
let chunk_size = 256; // Size of chunk just needs to fit into tx
|
||||||
let mut offset = 0;
|
let mut offset = 0;
|
||||||
for chunk in userdata.chunks(chunk_size) {
|
for chunk in userdata.chunks(chunk_size) {
|
||||||
let tx = Transaction::loader_write(
|
let tx = LoaderTransaction::new_write(
|
||||||
&program,
|
&program,
|
||||||
loader.loader,
|
loader.loader,
|
||||||
offset,
|
offset,
|
||||||
|
@ -169,7 +169,7 @@ impl Program {
|
||||||
offset += chunk_size as u32;
|
offset += chunk_size as u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
let tx = Transaction::loader_finalize(
|
let tx = LoaderTransaction::new_finalize(
|
||||||
&program,
|
&program,
|
||||||
loader.loader,
|
loader.loader,
|
||||||
loader.genesis_block.last_id(),
|
loader.genesis_block.last_id(),
|
||||||
|
@ -181,7 +181,7 @@ impl Program {
|
||||||
loader.bank.process_transactions(&vec![tx.clone()]),
|
loader.bank.process_transactions(&vec![tx.clone()]),
|
||||||
);
|
);
|
||||||
|
|
||||||
let tx = Transaction::system_spawn(&program, loader.genesis_block.last_id(), 0);
|
let tx = SystemTransaction::new_spawn(&program, loader.genesis_block.last_id(), 0);
|
||||||
check_tx_results(
|
check_tx_results(
|
||||||
&loader.bank,
|
&loader.bank,
|
||||||
&tx,
|
&tx,
|
||||||
|
@ -236,7 +236,7 @@ fn test_program_lua_move_funds() {
|
||||||
|
|
||||||
// Call user program with two accounts
|
// Call user program with two accounts
|
||||||
|
|
||||||
let tx = Transaction::system_create(
|
let tx = SystemTransaction::new_program_account(
|
||||||
&loader.mint_keypair,
|
&loader.mint_keypair,
|
||||||
from.pubkey(),
|
from.pubkey(),
|
||||||
loader.genesis_block.last_id(),
|
loader.genesis_block.last_id(),
|
||||||
|
@ -251,7 +251,7 @@ fn test_program_lua_move_funds() {
|
||||||
loader.bank.process_transactions(&vec![tx.clone()]),
|
loader.bank.process_transactions(&vec![tx.clone()]),
|
||||||
);
|
);
|
||||||
|
|
||||||
let tx = Transaction::system_create(
|
let tx = SystemTransaction::new_program_account(
|
||||||
&loader.mint_keypair,
|
&loader.mint_keypair,
|
||||||
to,
|
to,
|
||||||
loader.genesis_block.last_id(),
|
loader.genesis_block.last_id(),
|
||||||
|
|
|
@ -20,7 +20,6 @@ use solana::voting_keypair::VotingKeypair;
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use std::fs::remove_dir_all;
|
use std::fs::remove_dir_all;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
|
@ -110,8 +109,13 @@ fn test_replicator_startup() {
|
||||||
let last_id = leader_client.get_last_id();
|
let last_id = leader_client.get_last_id();
|
||||||
// Give the replicator some tokens
|
// Give the replicator some tokens
|
||||||
let amount = 1;
|
let amount = 1;
|
||||||
let mut tx =
|
let mut tx = SystemTransaction::new_account(
|
||||||
Transaction::system_new(&mint_keypair, replicator_keypair.pubkey(), amount, last_id);
|
&mint_keypair,
|
||||||
|
replicator_keypair.pubkey(),
|
||||||
|
amount,
|
||||||
|
last_id,
|
||||||
|
0,
|
||||||
|
);
|
||||||
leader_client
|
leader_client
|
||||||
.retry_transfer(&mint_keypair, &mut tx, 5)
|
.retry_transfer(&mint_keypair, &mut tx, 5)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -8,7 +8,6 @@ use solana::thin_client::new_fullnode;
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction::SystemTransaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
|
||||||
use std::fs::remove_dir_all;
|
use std::fs::remove_dir_all;
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
@ -42,7 +41,7 @@ fn test_rpc_send_tx() {
|
||||||
let last_id = Hash::new(&last_id_vec);
|
let last_id = Hash::new(&last_id_vec);
|
||||||
|
|
||||||
info!("last_id: {:?}", last_id);
|
info!("last_id: {:?}", last_id);
|
||||||
let tx = Transaction::system_move(&alice, bob_pubkey, 20, last_id, 0);
|
let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0);
|
||||||
let serial_tx = serialize(&tx).unwrap();
|
let serial_tx = serialize(&tx).unwrap();
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
|
|
@ -389,7 +389,7 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
|
||||||
WalletCommand::Cancel(pubkey) => {
|
WalletCommand::Cancel(pubkey) => {
|
||||||
let last_id = get_last_id(&rpc_client)?;
|
let last_id = get_last_id(&rpc_client)?;
|
||||||
let mut tx =
|
let mut tx =
|
||||||
Transaction::budget_new_signature(&config.id, pubkey, config.id.pubkey(), last_id);
|
BudgetTransaction::new_signature(&config.id, pubkey, config.id.pubkey(), last_id);
|
||||||
let signature_str = send_and_confirm_tx(&rpc_client, &mut tx, &config.id)?;
|
let signature_str = send_and_confirm_tx(&rpc_client, &mut tx, &config.id)?;
|
||||||
Ok(signature_str.to_string())
|
Ok(signature_str.to_string())
|
||||||
}
|
}
|
||||||
|
@ -440,7 +440,7 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let mut tx = Transaction::system_create(
|
let mut tx = SystemTransaction::new_program_account(
|
||||||
&config.id,
|
&config.id,
|
||||||
program_id.pubkey(),
|
program_id.pubkey(),
|
||||||
last_id,
|
last_id,
|
||||||
|
@ -455,7 +455,7 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
|
||||||
|
|
||||||
let mut offset = 0;
|
let mut offset = 0;
|
||||||
for chunk in program_userdata.chunks(USERDATA_CHUNK_SIZE) {
|
for chunk in program_userdata.chunks(USERDATA_CHUNK_SIZE) {
|
||||||
let mut tx = Transaction::loader_write(
|
let mut tx = LoaderTransaction::new_write(
|
||||||
&program_id,
|
&program_id,
|
||||||
bpf_loader::id(),
|
bpf_loader::id(),
|
||||||
offset,
|
offset,
|
||||||
|
@ -473,12 +473,12 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
|
||||||
}
|
}
|
||||||
|
|
||||||
let last_id = get_last_id(&rpc_client)?;
|
let last_id = get_last_id(&rpc_client)?;
|
||||||
let mut tx = Transaction::loader_finalize(&program_id, bpf_loader::id(), last_id, 0);
|
let mut tx = LoaderTransaction::new_finalize(&program_id, bpf_loader::id(), last_id, 0);
|
||||||
send_and_confirm_tx(&rpc_client, &mut tx, &program_id).map_err(|_| {
|
send_and_confirm_tx(&rpc_client, &mut tx, &program_id).map_err(|_| {
|
||||||
WalletError::DynamicProgramError("Program finalize transaction failed".to_string())
|
WalletError::DynamicProgramError("Program finalize transaction failed".to_string())
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let mut tx = Transaction::system_spawn(&program_id, last_id, 0);
|
let mut tx = SystemTransaction::new_spawn(&program_id, last_id, 0);
|
||||||
send_and_confirm_tx(&rpc_client, &mut tx, &program_id).map_err(|_| {
|
send_and_confirm_tx(&rpc_client, &mut tx, &program_id).map_err(|_| {
|
||||||
WalletError::DynamicProgramError("Program spawn failed".to_string())
|
WalletError::DynamicProgramError("Program spawn failed".to_string())
|
||||||
})?;
|
})?;
|
||||||
|
@ -504,7 +504,7 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
|
||||||
let last_id = get_last_id(&rpc_client)?;
|
let last_id = get_last_id(&rpc_client)?;
|
||||||
|
|
||||||
if timestamp == None && *witnesses == None {
|
if timestamp == None && *witnesses == None {
|
||||||
let mut tx = Transaction::system_new(&config.id, to, tokens, last_id);
|
let mut tx = SystemTransaction::new_account(&config.id, to, tokens, last_id, 0);
|
||||||
let signature_str = send_and_confirm_tx(&rpc_client, &mut tx, &config.id)?;
|
let signature_str = send_and_confirm_tx(&rpc_client, &mut tx, &config.id)?;
|
||||||
Ok(signature_str.to_string())
|
Ok(signature_str.to_string())
|
||||||
} else if *witnesses == None {
|
} else if *witnesses == None {
|
||||||
|
@ -519,7 +519,7 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
|
||||||
let budget_program_id = budget_program::id();
|
let budget_program_id = budget_program::id();
|
||||||
|
|
||||||
// Create account for contract funds
|
// Create account for contract funds
|
||||||
let mut tx = Transaction::system_create(
|
let mut tx = SystemTransaction::new_program_account(
|
||||||
&config.id,
|
&config.id,
|
||||||
contract_funds.pubkey(),
|
contract_funds.pubkey(),
|
||||||
last_id,
|
last_id,
|
||||||
|
@ -531,7 +531,7 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
|
||||||
send_and_confirm_tx(&rpc_client, &mut tx, &config.id)?;
|
send_and_confirm_tx(&rpc_client, &mut tx, &config.id)?;
|
||||||
|
|
||||||
// Create account for contract state
|
// Create account for contract state
|
||||||
let mut tx = Transaction::system_create(
|
let mut tx = SystemTransaction::new_program_account(
|
||||||
&config.id,
|
&config.id,
|
||||||
contract_state.pubkey(),
|
contract_state.pubkey(),
|
||||||
last_id,
|
last_id,
|
||||||
|
@ -543,7 +543,7 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
|
||||||
send_and_confirm_tx(&rpc_client, &mut tx, &config.id)?;
|
send_and_confirm_tx(&rpc_client, &mut tx, &config.id)?;
|
||||||
|
|
||||||
// Initializing contract
|
// Initializing contract
|
||||||
let mut tx = Transaction::budget_new_on_date(
|
let mut tx = BudgetTransaction::new_on_date(
|
||||||
&contract_funds,
|
&contract_funds,
|
||||||
to,
|
to,
|
||||||
contract_state.pubkey(),
|
contract_state.pubkey(),
|
||||||
|
@ -576,7 +576,7 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
|
||||||
let budget_program_id = budget_program::id();
|
let budget_program_id = budget_program::id();
|
||||||
|
|
||||||
// Create account for contract funds
|
// Create account for contract funds
|
||||||
let mut tx = Transaction::system_create(
|
let mut tx = SystemTransaction::new_program_account(
|
||||||
&config.id,
|
&config.id,
|
||||||
contract_funds.pubkey(),
|
contract_funds.pubkey(),
|
||||||
last_id,
|
last_id,
|
||||||
|
@ -588,7 +588,7 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
|
||||||
send_and_confirm_tx(&rpc_client, &mut tx, &config.id)?;
|
send_and_confirm_tx(&rpc_client, &mut tx, &config.id)?;
|
||||||
|
|
||||||
// Create account for contract state
|
// Create account for contract state
|
||||||
let mut tx = Transaction::system_create(
|
let mut tx = SystemTransaction::new_program_account(
|
||||||
&config.id,
|
&config.id,
|
||||||
contract_state.pubkey(),
|
contract_state.pubkey(),
|
||||||
last_id,
|
last_id,
|
||||||
|
@ -600,7 +600,7 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
|
||||||
send_and_confirm_tx(&rpc_client, &mut tx, &config.id)?;
|
send_and_confirm_tx(&rpc_client, &mut tx, &config.id)?;
|
||||||
|
|
||||||
// Initializing contract
|
// Initializing contract
|
||||||
let mut tx = Transaction::budget_new_when_signed(
|
let mut tx = BudgetTransaction::new_when_signed(
|
||||||
&contract_funds,
|
&contract_funds,
|
||||||
to,
|
to,
|
||||||
contract_state.pubkey(),
|
contract_state.pubkey(),
|
||||||
|
@ -633,7 +633,7 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
|
||||||
|
|
||||||
let last_id = get_last_id(&rpc_client)?;
|
let last_id = get_last_id(&rpc_client)?;
|
||||||
|
|
||||||
let mut tx = Transaction::budget_new_timestamp(&config.id, pubkey, to, dt, last_id);
|
let mut tx = BudgetTransaction::new_timestamp(&config.id, pubkey, to, dt, last_id);
|
||||||
let signature_str = send_and_confirm_tx(&rpc_client, &mut tx, &config.id)?;
|
let signature_str = send_and_confirm_tx(&rpc_client, &mut tx, &config.id)?;
|
||||||
|
|
||||||
Ok(signature_str.to_string())
|
Ok(signature_str.to_string())
|
||||||
|
@ -650,7 +650,7 @@ pub fn process_command(config: &WalletConfig) -> Result<String, Box<dyn error::E
|
||||||
}
|
}
|
||||||
|
|
||||||
let last_id = get_last_id(&rpc_client)?;
|
let last_id = get_last_id(&rpc_client)?;
|
||||||
let mut tx = Transaction::budget_new_signature(&config.id, pubkey, to, last_id);
|
let mut tx = BudgetTransaction::new_signature(&config.id, pubkey, to, last_id);
|
||||||
let signature_str = send_and_confirm_tx(&rpc_client, &mut tx, &config.id)?;
|
let signature_str = send_and_confirm_tx(&rpc_client, &mut tx, &config.id)?;
|
||||||
|
|
||||||
Ok(signature_str.to_string())
|
Ok(signature_str.to_string())
|
||||||
|
@ -1384,7 +1384,7 @@ mod tests {
|
||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let last_id = Hash::default();
|
let last_id = Hash::default();
|
||||||
let tx = Transaction::system_new(&key, to, 50, last_id);
|
let tx = SystemTransaction::new_account(&key, to, 50, last_id, 0);
|
||||||
|
|
||||||
let signature = send_tx(&rpc_client, &tx);
|
let signature = send_tx(&rpc_client, &tx);
|
||||||
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
||||||
|
@ -1420,7 +1420,7 @@ mod tests {
|
||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
let to = Keypair::new().pubkey();
|
let to = Keypair::new().pubkey();
|
||||||
let last_id = Hash::default();
|
let last_id = Hash::default();
|
||||||
let mut tx = Transaction::system_new(&key, to, 50, last_id);
|
let mut tx = SystemTransaction::new_account(&key, to, 50, last_id, 0);
|
||||||
|
|
||||||
let signer = Keypair::new();
|
let signer = Keypair::new();
|
||||||
|
|
||||||
|
@ -1446,8 +1446,8 @@ mod tests {
|
||||||
.into_vec()
|
.into_vec()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let last_id = Hash::new(&vec);
|
let last_id = Hash::new(&vec);
|
||||||
let prev_tx = Transaction::system_new(&key, to, 50, last_id);
|
let prev_tx = SystemTransaction::new_account(&key, to, 50, last_id, 0);
|
||||||
let mut tx = Transaction::system_new(&key, to, 50, last_id);
|
let mut tx = SystemTransaction::new_account(&key, to, 50, last_id, 0);
|
||||||
|
|
||||||
resign_tx(&rpc_client, &mut tx, &key).unwrap();
|
resign_tx(&rpc_client, &mut tx, &key).unwrap();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue