Remove Instruction wrapper structs and name functions after enum fields
This commit is contained in:
parent
867f6f107b
commit
35298e01a8
|
@ -13,8 +13,8 @@ use solana_metrics::influxdb;
|
||||||
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, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_instruction::SystemInstruction;
|
use solana_sdk::system_instruction;
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction;
|
||||||
use solana_sdk::timing::timestamp;
|
use solana_sdk::timing::timestamp;
|
||||||
use solana_sdk::timing::{duration_as_ms, duration_as_s};
|
use solana_sdk::timing::{duration_as_ms, duration_as_s};
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
|
@ -321,7 +321,7 @@ fn send_barrier_transaction(
|
||||||
*blockhash = barrier_client.get_recent_blockhash().unwrap();
|
*blockhash = barrier_client.get_recent_blockhash().unwrap();
|
||||||
|
|
||||||
let transaction =
|
let transaction =
|
||||||
SystemTransaction::new_user_account(&source_keypair, dest_id, 0, *blockhash, 0);
|
system_transaction::create_user_account(&source_keypair, dest_id, 0, *blockhash, 0);
|
||||||
let signature = barrier_client
|
let signature = barrier_client
|
||||||
.transfer_signed(&transaction)
|
.transfer_signed(&transaction)
|
||||||
.expect("Unable to send barrier transaction");
|
.expect("Unable to send barrier transaction");
|
||||||
|
@ -399,7 +399,7 @@ fn generate_txs(
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map(|(id, keypair)| {
|
.map(|(id, keypair)| {
|
||||||
(
|
(
|
||||||
SystemTransaction::new_user_account(id, &keypair.pubkey(), 1, blockhash, 0),
|
system_transaction::create_user_account(id, &keypair.pubkey(), 1, blockhash, 0),
|
||||||
timestamp(),
|
timestamp(),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -551,9 +551,10 @@ fn fund_keys(client: &ThinClient, source: &Keypair, dests: &[Keypair], lamports:
|
||||||
.map(|(k, m)| {
|
.map(|(k, m)| {
|
||||||
(
|
(
|
||||||
k.clone(),
|
k.clone(),
|
||||||
Transaction::new_unsigned_instructions(
|
Transaction::new_unsigned_instructions(system_instruction::transfer_many(
|
||||||
SystemInstruction::new_transfer_many(&k.pubkey(), &m),
|
&k.pubkey(),
|
||||||
),
|
&m,
|
||||||
|
)),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -556,7 +556,7 @@ mod tests {
|
||||||
use serde_json::Number;
|
use serde_json::Number;
|
||||||
use solana_logger;
|
use solana_logger;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
|
@ -662,7 +662,7 @@ mod tests {
|
||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
let to = Pubkey::new_rand();
|
let to = Pubkey::new_rand();
|
||||||
let blockhash = Hash::default();
|
let blockhash = Hash::default();
|
||||||
let tx = SystemTransaction::new_user_account(&key, &to, 50, blockhash, 0);
|
let tx = system_transaction::create_user_account(&key, &to, 50, blockhash, 0);
|
||||||
|
|
||||||
let signature = rpc_client.send_transaction(&tx);
|
let signature = rpc_client.send_transaction(&tx);
|
||||||
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
|
||||||
|
@ -713,7 +713,7 @@ mod tests {
|
||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
let to = Pubkey::new_rand();
|
let to = Pubkey::new_rand();
|
||||||
let blockhash = Hash::default();
|
let blockhash = Hash::default();
|
||||||
let mut tx = SystemTransaction::new_user_account(&key, &to, 50, blockhash, 0);
|
let mut tx = system_transaction::create_user_account(&key, &to, 50, blockhash, 0);
|
||||||
|
|
||||||
let result = rpc_client.send_and_confirm_transaction(&mut tx, &key);
|
let result = rpc_client.send_and_confirm_transaction(&mut tx, &key);
|
||||||
result.unwrap();
|
result.unwrap();
|
||||||
|
@ -737,8 +737,8 @@ mod tests {
|
||||||
.into_vec()
|
.into_vec()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let blockhash = Hash::new(&vec);
|
let blockhash = Hash::new(&vec);
|
||||||
let prev_tx = SystemTransaction::new_user_account(&key, &to, 50, blockhash, 0);
|
let prev_tx = system_transaction::create_user_account(&key, &to, 50, blockhash, 0);
|
||||||
let mut tx = SystemTransaction::new_user_account(&key, &to, 50, blockhash, 0);
|
let mut tx = system_transaction::create_user_account(&key, &to, 50, blockhash, 0);
|
||||||
|
|
||||||
rpc_client.resign_transaction(&mut tx, &key).unwrap();
|
rpc_client.resign_transaction(&mut tx, &key).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ use solana_sdk::genesis_block::GenesisBlock;
|
||||||
use solana_sdk::hash::hash;
|
use solana_sdk::hash::hash;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{KeypairUtil, Signature};
|
use solana_sdk::signature::{KeypairUtil, Signature};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction;
|
||||||
use solana_sdk::timing::{DEFAULT_TICKS_PER_SLOT, MAX_RECENT_BLOCKHASHES};
|
use solana_sdk::timing::{DEFAULT_TICKS_PER_SLOT, MAX_RECENT_BLOCKHASHES};
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::sync::atomic::Ordering;
|
use std::sync::atomic::Ordering;
|
||||||
|
@ -56,7 +56,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 = SystemTransaction::new_transfer(
|
let dummy = system_transaction::transfer(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -78,7 +78,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 = SystemTransaction::new_transfer(
|
let fund = system_transaction::transfer(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&tx.message.account_keys[0],
|
&tx.message.account_keys[0],
|
||||||
mint_total / txes as u64,
|
mint_total / txes as u64,
|
||||||
|
@ -156,7 +156,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 = SystemTransaction::new_transfer(
|
let dummy = system_transaction::transfer(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -194,7 +194,7 @@ fn bench_banking_stage_multi_programs(bencher: &mut Bencher) {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
transactions.iter().for_each(|tx| {
|
transactions.iter().for_each(|tx| {
|
||||||
let fund = SystemTransaction::new_transfer(
|
let fund = system_transaction::transfer(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&tx.message.account_keys[0],
|
&tx.message.account_keys[0],
|
||||||
mint_total / txes as u64,
|
mint_total / txes as u64,
|
||||||
|
|
|
@ -5,7 +5,7 @@ extern crate test;
|
||||||
use solana::entry::{next_entries, reconstruct_entries_from_blobs, EntrySlice};
|
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;
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
|
@ -13,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 = SystemTransaction::new_transfer(&keypair, &keypair.pubkey(), 1, one, 0);
|
let tx0 = system_transaction::transfer(&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);
|
||||||
|
|
||||||
|
|
|
@ -507,7 +507,7 @@ mod tests {
|
||||||
use solana_sdk::genesis_block::GenesisBlock;
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
use solana_sdk::instruction::InstructionError;
|
use solana_sdk::instruction::InstructionError;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
|
|
||||||
|
@ -593,7 +593,7 @@ mod tests {
|
||||||
|
|
||||||
// fund another account so we can send 2 good transactions in a single batch.
|
// fund another account so we can send 2 good transactions in a single batch.
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let fund_tx = SystemTransaction::new_user_account(
|
let fund_tx = system_transaction::create_user_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
2,
|
2,
|
||||||
|
@ -604,16 +604,17 @@ mod tests {
|
||||||
|
|
||||||
// good tx
|
// good tx
|
||||||
let to = Pubkey::new_rand();
|
let to = Pubkey::new_rand();
|
||||||
let tx = SystemTransaction::new_user_account(&mint_keypair, &to, 1, start_hash, 0);
|
let tx = system_transaction::create_user_account(&mint_keypair, &to, 1, start_hash, 0);
|
||||||
|
|
||||||
// good tx, but no verify
|
// good tx, but no verify
|
||||||
let to2 = Pubkey::new_rand();
|
let to2 = Pubkey::new_rand();
|
||||||
let tx_no_ver = SystemTransaction::new_user_account(&keypair, &to2, 2, start_hash, 0);
|
let tx_no_ver =
|
||||||
|
system_transaction::create_user_account(&keypair, &to2, 2, start_hash, 0);
|
||||||
|
|
||||||
// bad tx, AccountNotFound
|
// bad tx, AccountNotFound
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let to3 = Pubkey::new_rand();
|
let to3 = Pubkey::new_rand();
|
||||||
let tx_anf = SystemTransaction::new_user_account(&keypair, &to3, 1, start_hash, 0);
|
let tx_anf = system_transaction::create_user_account(&keypair, &to3, 1, start_hash, 0);
|
||||||
|
|
||||||
// send 'em over
|
// send 'em over
|
||||||
let packets = to_packets(&[tx_no_ver, tx_anf, tx]);
|
let packets = to_packets(&[tx_no_ver, tx_anf, tx]);
|
||||||
|
@ -676,7 +677,7 @@ mod tests {
|
||||||
|
|
||||||
// Process a batch that includes a transaction that receives two lamports.
|
// Process a batch that includes a transaction that receives two lamports.
|
||||||
let alice = Keypair::new();
|
let alice = Keypair::new();
|
||||||
let tx = SystemTransaction::new_user_account(
|
let tx = system_transaction::create_user_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&alice.pubkey(),
|
&alice.pubkey(),
|
||||||
2,
|
2,
|
||||||
|
@ -690,7 +691,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Process a second batch that spends one of those lamports.
|
// Process a second batch that spends one of those lamports.
|
||||||
let tx = SystemTransaction::new_user_account(
|
let tx = system_transaction::create_user_account(
|
||||||
&alice,
|
&alice,
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -783,8 +784,8 @@ mod tests {
|
||||||
let pubkey = Pubkey::new_rand();
|
let pubkey = Pubkey::new_rand();
|
||||||
|
|
||||||
let transactions = vec![
|
let transactions = vec![
|
||||||
SystemTransaction::new_transfer(&mint_keypair, &pubkey, 1, genesis_block.hash(), 0),
|
system_transaction::transfer(&mint_keypair, &pubkey, 1, genesis_block.hash(), 0),
|
||||||
SystemTransaction::new_transfer(&mint_keypair, &pubkey, 1, genesis_block.hash(), 0),
|
system_transaction::transfer(&mint_keypair, &pubkey, 1, genesis_block.hash(), 0),
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut results = vec![Ok(()), Ok(())];
|
let mut results = vec![Ok(()), Ok(())];
|
||||||
|
@ -820,7 +821,7 @@ mod tests {
|
||||||
let bank = Arc::new(Bank::new(&genesis_block));
|
let bank = Arc::new(Bank::new(&genesis_block));
|
||||||
let pubkey = Pubkey::new_rand();
|
let pubkey = Pubkey::new_rand();
|
||||||
|
|
||||||
let transactions = vec![SystemTransaction::new_transfer(
|
let transactions = vec![system_transaction::transfer(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&pubkey,
|
&pubkey,
|
||||||
1,
|
1,
|
||||||
|
@ -873,7 +874,7 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(done, true);
|
assert_eq!(done, true);
|
||||||
|
|
||||||
let transactions = vec![SystemTransaction::new_transfer(
|
let transactions = vec![system_transaction::transfer(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&pubkey,
|
&pubkey,
|
||||||
2,
|
2,
|
||||||
|
|
|
@ -172,7 +172,7 @@ mod test {
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
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;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -184,9 +184,9 @@ mod test {
|
||||||
let keypair0 = Keypair::new();
|
let keypair0 = Keypair::new();
|
||||||
let keypair1 = Keypair::new();
|
let keypair1 = Keypair::new();
|
||||||
let tx0 =
|
let tx0 =
|
||||||
SystemTransaction::new_transfer(&keypair0, &keypair1.pubkey(), 1, Hash::default(), 0);
|
system_transaction::transfer(&keypair0, &keypair1.pubkey(), 1, Hash::default(), 0);
|
||||||
let tx1 =
|
let tx1 =
|
||||||
SystemTransaction::new_transfer(&keypair1, &keypair0.pubkey(), 2, Hash::default(), 0);
|
system_transaction::transfer(&keypair1, &keypair0.pubkey(), 2, Hash::default(), 0);
|
||||||
let serialized_tx0 = serialize(&tx0).unwrap();
|
let serialized_tx0 = serialize(&tx0).unwrap();
|
||||||
let serialized_tx1 = serialize(&tx1).unwrap();
|
let serialized_tx1 = serialize(&tx1).unwrap();
|
||||||
let entry = Entry::new(&Hash::default(), 1, vec![tx0, tx1]);
|
let entry = Entry::new(&Hash::default(), 1, vec![tx0, tx1]);
|
||||||
|
|
|
@ -115,7 +115,7 @@ mod test {
|
||||||
use solana_sdk::genesis_block::GenesisBlock;
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
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;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -141,8 +141,13 @@ mod test {
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let mut blockhash = entries[3].hash;
|
let mut blockhash = entries[3].hash;
|
||||||
let tx =
|
let tx = system_transaction::create_user_account(
|
||||||
SystemTransaction::new_user_account(&keypair, &keypair.pubkey(), 1, Hash::default(), 0);
|
&keypair,
|
||||||
|
&keypair.pubkey(),
|
||||||
|
1,
|
||||||
|
Hash::default(),
|
||||||
|
0,
|
||||||
|
);
|
||||||
let entry = Entry::new(&mut blockhash, 1, vec![tx]);
|
let entry = Entry::new(&mut blockhash, 1, vec![tx]);
|
||||||
blockhash = entry.hash;
|
blockhash = entry.hash;
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
|
|
|
@ -233,7 +233,7 @@ mod tests {
|
||||||
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, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction;
|
||||||
use solana_sdk::transaction::TransactionError;
|
use solana_sdk::transaction::TransactionError;
|
||||||
|
|
||||||
fn fill_blocktree_slot_with_ticks(
|
fn fill_blocktree_slot_with_ticks(
|
||||||
|
@ -421,7 +421,7 @@ mod tests {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let slot_entries = create_ticks(genesis_block.ticks_per_slot - 1, genesis_block.hash());
|
let slot_entries = create_ticks(genesis_block.ticks_per_slot - 1, genesis_block.hash());
|
||||||
let tx = SystemTransaction::new_user_account(
|
let tx = system_transaction::create_user_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -453,7 +453,7 @@ mod tests {
|
||||||
for _ in 0..3 {
|
for _ in 0..3 {
|
||||||
// Transfer one token from the mint to a random account
|
// Transfer one token from the mint to a random account
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx = SystemTransaction::new_user_account(
|
let tx = system_transaction::create_user_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -467,8 +467,13 @@ mod tests {
|
||||||
// Add a second Transaction that will produce a
|
// Add a second Transaction that will produce a
|
||||||
// InstructionError<0, ResultWithNegativeLamports> error when processed
|
// InstructionError<0, ResultWithNegativeLamports> error when processed
|
||||||
let keypair2 = Keypair::new();
|
let keypair2 = Keypair::new();
|
||||||
let tx =
|
let tx = system_transaction::create_user_account(
|
||||||
SystemTransaction::new_user_account(&keypair, &keypair2.pubkey(), 42, blockhash, 0);
|
&keypair,
|
||||||
|
&keypair2.pubkey(),
|
||||||
|
42,
|
||||||
|
blockhash,
|
||||||
|
0,
|
||||||
|
);
|
||||||
let entry = Entry::new(&last_entry_hash, 1, vec![tx]);
|
let entry = Entry::new(&last_entry_hash, 1, vec![tx]);
|
||||||
last_entry_hash = entry.hash;
|
last_entry_hash = entry.hash;
|
||||||
entries.push(entry);
|
entries.push(entry);
|
||||||
|
@ -545,7 +550,7 @@ mod tests {
|
||||||
let blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
|
|
||||||
// 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 = SystemTransaction::new_user_account(
|
let tx = system_transaction::create_user_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&keypair1.pubkey(),
|
&keypair1.pubkey(),
|
||||||
2,
|
2,
|
||||||
|
@ -553,7 +558,7 @@ mod tests {
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
let entry_1 = next_entry(&blockhash, 1, vec![tx]);
|
let entry_1 = next_entry(&blockhash, 1, vec![tx]);
|
||||||
let tx = SystemTransaction::new_user_account(
|
let tx = system_transaction::create_user_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&keypair2.pubkey(),
|
&keypair2.pubkey(),
|
||||||
2,
|
2,
|
||||||
|
@ -583,7 +588,7 @@ mod tests {
|
||||||
let entry_1_to_mint = next_entry(
|
let entry_1_to_mint = next_entry(
|
||||||
&bank.last_blockhash(),
|
&bank.last_blockhash(),
|
||||||
1,
|
1,
|
||||||
vec![SystemTransaction::new_user_account(
|
vec![system_transaction::create_user_account(
|
||||||
&keypair1,
|
&keypair1,
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -596,14 +601,14 @@ mod tests {
|
||||||
&entry_1_to_mint.hash,
|
&entry_1_to_mint.hash,
|
||||||
1,
|
1,
|
||||||
vec![
|
vec![
|
||||||
SystemTransaction::new_user_account(
|
system_transaction::create_user_account(
|
||||||
&keypair2,
|
&keypair2,
|
||||||
&keypair3.pubkey(),
|
&keypair3.pubkey(),
|
||||||
2,
|
2,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
), // should be fine
|
), // should be fine
|
||||||
SystemTransaction::new_user_account(
|
system_transaction::create_user_account(
|
||||||
&keypair1,
|
&keypair1,
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
2,
|
2,
|
||||||
|
@ -642,14 +647,14 @@ mod tests {
|
||||||
&bank.last_blockhash(),
|
&bank.last_blockhash(),
|
||||||
1,
|
1,
|
||||||
vec![
|
vec![
|
||||||
SystemTransaction::new_user_account(
|
system_transaction::create_user_account(
|
||||||
&keypair1,
|
&keypair1,
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
),
|
),
|
||||||
SystemTransaction::new_transfer(
|
system_transaction::transfer(
|
||||||
&keypair4,
|
&keypair4,
|
||||||
&keypair4.pubkey(),
|
&keypair4.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -663,14 +668,14 @@ mod tests {
|
||||||
&entry_1_to_mint.hash,
|
&entry_1_to_mint.hash,
|
||||||
1,
|
1,
|
||||||
vec![
|
vec![
|
||||||
SystemTransaction::new_user_account(
|
system_transaction::create_user_account(
|
||||||
&keypair2,
|
&keypair2,
|
||||||
&keypair3.pubkey(),
|
&keypair3.pubkey(),
|
||||||
2,
|
2,
|
||||||
bank.last_blockhash(),
|
bank.last_blockhash(),
|
||||||
0,
|
0,
|
||||||
), // should be fine
|
), // should be fine
|
||||||
SystemTransaction::new_user_account(
|
system_transaction::create_user_account(
|
||||||
&keypair1,
|
&keypair1,
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
2,
|
2,
|
||||||
|
@ -715,7 +720,7 @@ mod tests {
|
||||||
let keypair4 = Keypair::new();
|
let keypair4 = Keypair::new();
|
||||||
|
|
||||||
//load accounts
|
//load accounts
|
||||||
let tx = SystemTransaction::new_user_account(
|
let tx = system_transaction::create_user_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&keypair1.pubkey(),
|
&keypair1.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -723,7 +728,7 @@ mod tests {
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
let tx = SystemTransaction::new_user_account(
|
let tx = system_transaction::create_user_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&keypair2.pubkey(),
|
&keypair2.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -734,7 +739,7 @@ mod tests {
|
||||||
|
|
||||||
// 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 blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
let tx = SystemTransaction::new_user_account(
|
let tx = system_transaction::create_user_account(
|
||||||
&keypair1,
|
&keypair1,
|
||||||
&keypair3.pubkey(),
|
&keypair3.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -742,7 +747,7 @@ mod tests {
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
let entry_1 = next_entry(&blockhash, 1, vec![tx]);
|
let entry_1 = next_entry(&blockhash, 1, vec![tx]);
|
||||||
let tx = SystemTransaction::new_user_account(
|
let tx = system_transaction::create_user_account(
|
||||||
&keypair2,
|
&keypair2,
|
||||||
&keypair4.pubkey(),
|
&keypair4.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -766,7 +771,7 @@ mod tests {
|
||||||
let keypair4 = Keypair::new();
|
let keypair4 = Keypair::new();
|
||||||
|
|
||||||
//load accounts
|
//load accounts
|
||||||
let tx = SystemTransaction::new_user_account(
|
let tx = system_transaction::create_user_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&keypair1.pubkey(),
|
&keypair1.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -774,7 +779,7 @@ mod tests {
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
let tx = SystemTransaction::new_user_account(
|
let tx = system_transaction::create_user_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&keypair2.pubkey(),
|
&keypair2.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -790,10 +795,10 @@ mod tests {
|
||||||
|
|
||||||
// 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 =
|
let tx =
|
||||||
SystemTransaction::new_user_account(&keypair2, &keypair3.pubkey(), 1, blockhash, 0);
|
system_transaction::create_user_account(&keypair2, &keypair3.pubkey(), 1, blockhash, 0);
|
||||||
let entry_1 = next_entry(&blockhash, 1, vec![tx]);
|
let entry_1 = next_entry(&blockhash, 1, vec![tx]);
|
||||||
let tick = next_entry(&entry_1.hash, 1, vec![]);
|
let tick = next_entry(&entry_1.hash, 1, vec![]);
|
||||||
let tx = SystemTransaction::new_user_account(
|
let tx = system_transaction::create_user_account(
|
||||||
&keypair1,
|
&keypair1,
|
||||||
&keypair4.pubkey(),
|
&keypair4.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -809,7 +814,7 @@ mod tests {
|
||||||
assert_eq!(bank.get_balance(&keypair4.pubkey()), 1);
|
assert_eq!(bank.get_balance(&keypair4.pubkey()), 1);
|
||||||
|
|
||||||
// ensure that an error is returned for an empty account (keypair2)
|
// ensure that an error is returned for an empty account (keypair2)
|
||||||
let tx = SystemTransaction::new_user_account(
|
let tx = system_transaction::create_user_account(
|
||||||
&keypair2,
|
&keypair2,
|
||||||
&keypair3.pubkey(),
|
&keypair3.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
|
|
@ -97,7 +97,7 @@ mod tests {
|
||||||
use ring::signature::Ed25519KeyPair;
|
use ring::signature::Ed25519KeyPair;
|
||||||
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::system_transaction::SystemTransaction;
|
use solana_sdk::system_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;
|
||||||
|
@ -124,7 +124,7 @@ mod tests {
|
||||||
Entry::new_mut(
|
Entry::new_mut(
|
||||||
&mut id,
|
&mut id,
|
||||||
&mut num_hashes,
|
&mut num_hashes,
|
||||||
vec![SystemTransaction::new_user_account(
|
vec![system_transaction::create_user_account(
|
||||||
&keypair,
|
&keypair,
|
||||||
&keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
|
|
@ -12,7 +12,7 @@ use crate::poh_service::PohServiceConfig;
|
||||||
use solana_client::thin_client::create_client;
|
use solana_client::thin_client::create_client;
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
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;
|
||||||
use solana_sdk::timing::{
|
use solana_sdk::timing::{
|
||||||
duration_as_ms, DEFAULT_TICKS_PER_SLOT, NUM_CONSECUTIVE_LEADER_SLOTS, NUM_TICKS_PER_SECOND,
|
duration_as_ms, DEFAULT_TICKS_PER_SLOT, NUM_CONSECUTIVE_LEADER_SLOTS, NUM_TICKS_PER_SECOND,
|
||||||
};
|
};
|
||||||
|
@ -37,7 +37,7 @@ pub fn spend_and_verify_all_nodes(
|
||||||
.poll_get_balance(&funding_keypair.pubkey())
|
.poll_get_balance(&funding_keypair.pubkey())
|
||||||
.expect("balance in source");
|
.expect("balance in source");
|
||||||
assert!(bal > 0);
|
assert!(bal > 0);
|
||||||
let mut transaction = SystemTransaction::new_transfer(
|
let mut transaction = system_transaction::transfer(
|
||||||
&funding_keypair,
|
&funding_keypair,
|
||||||
&random_keypair.pubkey(),
|
&random_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -63,7 +63,7 @@ pub fn send_many_transactions(node: &ContactInfo, funding_keypair: &Keypair, num
|
||||||
.poll_get_balance(&funding_keypair.pubkey())
|
.poll_get_balance(&funding_keypair.pubkey())
|
||||||
.expect("balance in source");
|
.expect("balance in source");
|
||||||
assert!(bal > 0);
|
assert!(bal > 0);
|
||||||
let mut transaction = SystemTransaction::new_transfer(
|
let mut transaction = system_transaction::transfer(
|
||||||
&funding_keypair,
|
&funding_keypair,
|
||||||
&random_keypair.pubkey(),
|
&random_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -183,7 +183,7 @@ pub fn kill_entry_and_spend_and_verify_rest(
|
||||||
}
|
}
|
||||||
|
|
||||||
let random_keypair = Keypair::new();
|
let random_keypair = Keypair::new();
|
||||||
let mut transaction = SystemTransaction::new_transfer(
|
let mut transaction = system_transaction::transfer(
|
||||||
&funding_keypair,
|
&funding_keypair,
|
||||||
&random_keypair.pubkey(),
|
&random_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::result::Result;
|
||||||
use bincode::{deserialize, serialized_size};
|
use bincode::{deserialize, serialized_size};
|
||||||
use chrono::prelude::Utc;
|
use chrono::prelude::Utc;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
use solana_budget_api::budget_instruction::BudgetInstruction;
|
use solana_budget_api::budget_instruction;
|
||||||
use solana_sdk::hash::{Hash, Hasher};
|
use solana_sdk::hash::{Hash, Hasher};
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
|
@ -380,7 +380,7 @@ pub fn make_tiny_test_entries_from_hash(start: &Hash, num: usize) -> Vec<Entry>
|
||||||
let mut num_hashes = 0;
|
let mut num_hashes = 0;
|
||||||
(0..num)
|
(0..num)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
let ix = BudgetInstruction::new_apply_timestamp(&pubkey, &pubkey, &pubkey, Utc::now());
|
let ix = budget_instruction::apply_timestamp(&pubkey, &pubkey, &pubkey, Utc::now());
|
||||||
let tx = Transaction::new_signed_instructions(&[&keypair], vec![ix], *start);
|
let tx = Transaction::new_signed_instructions(&[&keypair], vec![ix], *start);
|
||||||
Entry::new_mut(&mut hash, &mut num_hashes, vec![tx])
|
Entry::new_mut(&mut hash, &mut num_hashes, vec![tx])
|
||||||
})
|
})
|
||||||
|
@ -399,7 +399,7 @@ pub fn make_large_test_entries(num_entries: usize) -> Vec<Entry> {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let pubkey = keypair.pubkey();
|
let pubkey = keypair.pubkey();
|
||||||
|
|
||||||
let ix = BudgetInstruction::new_apply_timestamp(&pubkey, &pubkey, &pubkey, Utc::now());
|
let ix = budget_instruction::apply_timestamp(&pubkey, &pubkey, &pubkey, Utc::now());
|
||||||
let tx = Transaction::new_signed_instructions(&[&keypair], vec![ix], one);
|
let tx = Transaction::new_signed_instructions(&[&keypair], vec![ix], one);
|
||||||
|
|
||||||
let serialized_size = serialized_size(&tx).unwrap();
|
let serialized_size = serialized_size(&tx).unwrap();
|
||||||
|
@ -450,31 +450,31 @@ mod tests {
|
||||||
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::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;
|
||||||
use solana_vote_api::vote_instruction::{Vote, VoteInstruction};
|
use solana_vote_api::vote_instruction::{self, Vote};
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
|
|
||||||
fn create_sample_payment(keypair: &Keypair, hash: Hash) -> Transaction {
|
fn create_sample_payment(keypair: &Keypair, hash: Hash) -> Transaction {
|
||||||
let pubkey = keypair.pubkey();
|
let pubkey = keypair.pubkey();
|
||||||
let ixs = BudgetInstruction::new_payment(&pubkey, &pubkey, 1);
|
let ixs = budget_instruction::payment(&pubkey, &pubkey, 1);
|
||||||
Transaction::new_signed_instructions(&[keypair], ixs, hash)
|
Transaction::new_signed_instructions(&[keypair], ixs, hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_sample_timestamp(keypair: &Keypair, hash: Hash) -> Transaction {
|
fn create_sample_timestamp(keypair: &Keypair, hash: Hash) -> Transaction {
|
||||||
let pubkey = keypair.pubkey();
|
let pubkey = keypair.pubkey();
|
||||||
let ix = BudgetInstruction::new_apply_timestamp(&pubkey, &pubkey, &pubkey, Utc::now());
|
let ix = budget_instruction::apply_timestamp(&pubkey, &pubkey, &pubkey, Utc::now());
|
||||||
Transaction::new_signed_instructions(&[keypair], vec![ix], hash)
|
Transaction::new_signed_instructions(&[keypair], vec![ix], hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_sample_signature(keypair: &Keypair, hash: Hash) -> Transaction {
|
fn create_sample_signature(keypair: &Keypair, hash: Hash) -> Transaction {
|
||||||
let pubkey = keypair.pubkey();
|
let pubkey = keypair.pubkey();
|
||||||
let ix = BudgetInstruction::new_apply_signature(&pubkey, &pubkey, &pubkey);
|
let ix = budget_instruction::apply_signature(&pubkey, &pubkey, &pubkey);
|
||||||
Transaction::new_signed_instructions(&[keypair], vec![ix], hash)
|
Transaction::new_signed_instructions(&[keypair], vec![ix], hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_sample_vote(keypair: &Keypair, hash: Hash) -> Transaction {
|
fn create_sample_vote(keypair: &Keypair, hash: Hash) -> Transaction {
|
||||||
let pubkey = keypair.pubkey();
|
let pubkey = keypair.pubkey();
|
||||||
let ix = VoteInstruction::new_vote(&pubkey, Vote::new(1));
|
let ix = vote_instruction::vote(&pubkey, Vote::new(1));
|
||||||
Transaction::new_signed_instructions(&[keypair], vec![ix], hash)
|
Transaction::new_signed_instructions(&[keypair], vec![ix], hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,8 +494,8 @@ mod tests {
|
||||||
|
|
||||||
// First, verify entries
|
// First, verify entries
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let tx0 = SystemTransaction::new_user_account(&keypair, &keypair.pubkey(), 0, zero, 0);
|
let tx0 = system_transaction::create_user_account(&keypair, &keypair.pubkey(), 0, zero, 0);
|
||||||
let tx1 = SystemTransaction::new_user_account(&keypair, &keypair.pubkey(), 1, zero, 0);
|
let tx1 = system_transaction::create_user_account(&keypair, &keypair.pubkey(), 1, zero, 0);
|
||||||
let mut e0 = Entry::new(&zero, 0, vec![tx0.clone(), tx1.clone()]);
|
let mut e0 = Entry::new(&zero, 0, vec![tx0.clone(), tx1.clone()]);
|
||||||
assert!(e0.verify(&zero));
|
assert!(e0.verify(&zero));
|
||||||
|
|
||||||
|
@ -545,7 +545,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 = SystemTransaction::new_user_account(&keypair, &keypair.pubkey(), 0, zero, 0);
|
let tx = system_transaction::create_user_account(&keypair, &keypair.pubkey(), 0, zero, 0);
|
||||||
next_entry(&zero, 0, vec![tx]);
|
next_entry(&zero, 0, vec![tx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -553,7 +553,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 = SystemTransaction::new_user_account(&keypair, &keypair.pubkey(), 0, zero, 0);
|
let tx = system_transaction::create_user_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]),
|
||||||
|
|
|
@ -25,10 +25,10 @@ use solana_sdk::genesis_block::GenesisBlock;
|
||||||
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, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction;
|
||||||
use solana_sdk::timing::timestamp;
|
use solana_sdk::timing::timestamp;
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use solana_vote_api::vote_instruction::{Vote, VoteInstruction};
|
use solana_vote_api::vote_instruction::{self, Vote};
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::mpsc::{channel, Receiver};
|
use std::sync::mpsc::{channel, Receiver};
|
||||||
|
@ -318,7 +318,7 @@ pub fn make_active_set_entries(
|
||||||
num_ending_ticks: u64,
|
num_ending_ticks: u64,
|
||||||
) -> (Vec<Entry>, Keypair) {
|
) -> (Vec<Entry>, Keypair) {
|
||||||
// 1) Assume the active_keypair node has no lamports staked
|
// 1) Assume the active_keypair node has no lamports staked
|
||||||
let transfer_tx = SystemTransaction::new_user_account(
|
let transfer_tx = system_transaction::create_user_account(
|
||||||
&lamport_source,
|
&lamport_source,
|
||||||
&active_keypair.pubkey(),
|
&active_keypair.pubkey(),
|
||||||
stake,
|
stake,
|
||||||
|
@ -332,7 +332,7 @@ pub fn make_active_set_entries(
|
||||||
let voting_keypair = Keypair::new();
|
let voting_keypair = Keypair::new();
|
||||||
let vote_account_id = voting_keypair.pubkey();
|
let vote_account_id = voting_keypair.pubkey();
|
||||||
|
|
||||||
let new_vote_account_ixs = VoteInstruction::new_account(
|
let new_vote_account_ixs = vote_instruction::create_account(
|
||||||
&active_keypair.pubkey(),
|
&active_keypair.pubkey(),
|
||||||
&vote_account_id,
|
&vote_account_id,
|
||||||
stake.saturating_sub(2),
|
stake.saturating_sub(2),
|
||||||
|
@ -345,7 +345,7 @@ pub fn make_active_set_entries(
|
||||||
let new_vote_account_entry = next_entry_mut(&mut last_entry_hash, 1, vec![new_vote_account_tx]);
|
let new_vote_account_entry = next_entry_mut(&mut last_entry_hash, 1, vec![new_vote_account_tx]);
|
||||||
|
|
||||||
// 3) Create vote entry
|
// 3) Create vote entry
|
||||||
let vote_ix = VoteInstruction::new_vote(&voting_keypair.pubkey(), Vote::new(slot_to_vote_on));
|
let vote_ix = vote_instruction::vote(&voting_keypair.pubkey(), Vote::new(slot_to_vote_on));
|
||||||
let vote_tx =
|
let vote_tx =
|
||||||
Transaction::new_signed_instructions(&[&voting_keypair], vec![vote_ix], *blockhash);
|
Transaction::new_signed_instructions(&[&voting_keypair], vec![vote_ix], *blockhash);
|
||||||
let vote_entry = next_entry_mut(&mut last_entry_hash, 1, vec![vote_tx]);
|
let vote_entry = next_entry_mut(&mut last_entry_hash, 1, vec![vote_tx]);
|
||||||
|
|
|
@ -11,11 +11,11 @@ use solana_client::thin_client::ThinClient;
|
||||||
use solana_sdk::genesis_block::GenesisBlock;
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
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;
|
||||||
use solana_sdk::timing::DEFAULT_SLOTS_PER_EPOCH;
|
use solana_sdk::timing::DEFAULT_SLOTS_PER_EPOCH;
|
||||||
use solana_sdk::timing::DEFAULT_TICKS_PER_SLOT;
|
use solana_sdk::timing::DEFAULT_TICKS_PER_SLOT;
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use solana_vote_api::vote_instruction::VoteInstruction;
|
use solana_vote_api::vote_instruction;
|
||||||
use solana_vote_api::vote_state::VoteState;
|
use solana_vote_api::vote_state::VoteState;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs::remove_dir_all;
|
use std::fs::remove_dir_all;
|
||||||
|
@ -296,7 +296,7 @@ impl LocalCluster {
|
||||||
) -> u64 {
|
) -> u64 {
|
||||||
trace!("getting leader blockhash");
|
trace!("getting leader blockhash");
|
||||||
let blockhash = client.get_recent_blockhash().unwrap();
|
let blockhash = client.get_recent_blockhash().unwrap();
|
||||||
let mut tx = SystemTransaction::new_user_account(
|
let mut tx = system_transaction::create_user_account(
|
||||||
&source_keypair,
|
&source_keypair,
|
||||||
dest_pubkey,
|
dest_pubkey,
|
||||||
lamports,
|
lamports,
|
||||||
|
@ -328,8 +328,11 @@ impl LocalCluster {
|
||||||
// Create the vote account if necessary
|
// Create the vote account if necessary
|
||||||
if client.poll_get_balance(&vote_account_pubkey).unwrap_or(0) == 0 {
|
if client.poll_get_balance(&vote_account_pubkey).unwrap_or(0) == 0 {
|
||||||
// 1) Create vote account
|
// 1) Create vote account
|
||||||
let instructions =
|
let instructions = vote_instruction::create_account(
|
||||||
VoteInstruction::new_account(&from_account.pubkey(), &vote_account_pubkey, amount);
|
&from_account.pubkey(),
|
||||||
|
&vote_account_pubkey,
|
||||||
|
amount,
|
||||||
|
);
|
||||||
let mut transaction = Transaction::new_signed_instructions(
|
let mut transaction = Transaction::new_signed_instructions(
|
||||||
&[from_account.as_ref()],
|
&[from_account.as_ref()],
|
||||||
instructions,
|
instructions,
|
||||||
|
@ -345,7 +348,7 @@ impl LocalCluster {
|
||||||
|
|
||||||
// 2) Set delegate for new vote account
|
// 2) Set delegate for new vote account
|
||||||
let vote_instruction =
|
let vote_instruction =
|
||||||
VoteInstruction::new_delegate_stake(&vote_account_pubkey, &delegate_id);
|
vote_instruction::delegate_stake(&vote_account_pubkey, &delegate_id);
|
||||||
|
|
||||||
let mut transaction = Transaction::new_signed_instructions(
|
let mut transaction = Transaction::new_signed_instructions(
|
||||||
&[vote_account],
|
&[vote_account],
|
||||||
|
|
|
@ -573,7 +573,7 @@ mod tests {
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
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;
|
||||||
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};
|
||||||
|
@ -612,7 +612,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 = SystemTransaction::new_user_account(&keypair, &keypair.pubkey(), 1, hash, 0);
|
let tx = system_transaction::create_user_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,7 @@ use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::KeypairUtil;
|
use solana_sdk::signature::KeypairUtil;
|
||||||
use solana_sdk::timing::{self, duration_as_ms};
|
use solana_sdk::timing::{self, duration_as_ms};
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use solana_vote_api::vote_instruction::{Vote, VoteInstruction};
|
use solana_vote_api::vote_instruction::{self, Vote};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender};
|
use std::sync::mpsc::{channel, Receiver, RecvTimeoutError, Sender};
|
||||||
use std::sync::{Arc, Mutex, RwLock};
|
use std::sync::{Arc, Mutex, RwLock};
|
||||||
|
@ -296,7 +296,7 @@ impl ReplayStage {
|
||||||
T: 'static + KeypairUtil + Send + Sync,
|
T: 'static + KeypairUtil + Send + Sync,
|
||||||
{
|
{
|
||||||
if let Some(ref voting_keypair) = voting_keypair {
|
if let Some(ref voting_keypair) = voting_keypair {
|
||||||
let vote_ix = VoteInstruction::new_vote(&vote_account, Vote::new(bank.slot()));
|
let vote_ix = vote_instruction::vote(&vote_account, Vote::new(bank.slot()));
|
||||||
let vote_tx = Transaction::new_signed_instructions(
|
let vote_tx = Transaction::new_signed_instructions(
|
||||||
&[voting_keypair.as_ref()],
|
&[voting_keypair.as_ref()],
|
||||||
vec![vote_ix],
|
vec![vote_ix],
|
||||||
|
@ -635,7 +635,7 @@ mod test {
|
||||||
ledger_writer_sender,
|
ledger_writer_sender,
|
||||||
);
|
);
|
||||||
|
|
||||||
let vote_ix = VoteInstruction::new_vote(&voting_keypair.pubkey(), Vote::new(0));
|
let vote_ix = vote_instruction::vote(&voting_keypair.pubkey(), Vote::new(0));
|
||||||
let vote_tx = Transaction::new_signed_instructions(
|
let vote_tx = Transaction::new_signed_instructions(
|
||||||
&[voting_keypair.as_ref()],
|
&[voting_keypair.as_ref()],
|
||||||
vec![vote_ix],
|
vec![vote_ix],
|
||||||
|
|
|
@ -22,9 +22,9 @@ use solana_client::thin_client::{create_client, ThinClient};
|
||||||
use solana_drone::drone::{request_airdrop_transaction, DRONE_PORT};
|
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::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use solana_storage_api::storage_instruction::StorageInstruction;
|
use solana_storage_api::storage_instruction;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
|
@ -434,7 +434,7 @@ impl Replicator {
|
||||||
{
|
{
|
||||||
let blockhash = client.get_recent_blockhash().expect("blockhash");
|
let blockhash = client.get_recent_blockhash().expect("blockhash");
|
||||||
//TODO the account space needs to be well defined somewhere
|
//TODO the account space needs to be well defined somewhere
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = system_transaction::create_account(
|
||||||
keypair,
|
keypair,
|
||||||
&storage_keypair.pubkey(),
|
&storage_keypair.pubkey(),
|
||||||
blockhash,
|
blockhash,
|
||||||
|
@ -455,7 +455,7 @@ impl Replicator {
|
||||||
);
|
);
|
||||||
Self::get_airdrop_lamports(&client, &self.keypair, &self.cluster_entrypoint);
|
Self::get_airdrop_lamports(&client, &self.keypair, &self.cluster_entrypoint);
|
||||||
|
|
||||||
let ix = StorageInstruction::new_mining_proof(
|
let ix = storage_instruction::mining_proof(
|
||||||
&self.storage_keypair.pubkey(),
|
&self.storage_keypair.pubkey(),
|
||||||
self.hash,
|
self.hash,
|
||||||
self.slot,
|
self.slot,
|
||||||
|
|
|
@ -454,7 +454,7 @@ mod tests {
|
||||||
use solana_sdk::genesis_block::GenesisBlock;
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
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;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
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) {
|
||||||
|
@ -463,7 +463,7 @@ mod tests {
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
let blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
let tx = SystemTransaction::new_transfer(&alice, pubkey, 20, blockhash, 0);
|
let tx = system_transaction::transfer(&alice, pubkey, 20, blockhash, 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(
|
||||||
|
@ -503,7 +503,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
let tx = SystemTransaction::new_transfer(&alice, &bob_pubkey, 20, blockhash, 0);
|
let tx = system_transaction::transfer(&alice, &bob_pubkey, 20, blockhash, 0);
|
||||||
bank.process_transaction(&tx).expect("process transaction");
|
bank.process_transaction(&tx).expect("process transaction");
|
||||||
})
|
})
|
||||||
.join()
|
.join()
|
||||||
|
@ -575,7 +575,7 @@ mod tests {
|
||||||
fn test_rpc_confirm_tx() {
|
fn test_rpc_confirm_tx() {
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let (io, meta, blockhash, alice) = start_rpc_handler_with_tx(&bob_pubkey);
|
let (io, meta, blockhash, alice) = start_rpc_handler_with_tx(&bob_pubkey);
|
||||||
let tx = SystemTransaction::new_transfer(&alice, &bob_pubkey, 20, blockhash, 0);
|
let tx = system_transaction::transfer(&alice, &bob_pubkey, 20, blockhash, 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":["{}"]}}"#,
|
||||||
|
@ -594,7 +594,7 @@ mod tests {
|
||||||
fn test_rpc_get_signature_status() {
|
fn test_rpc_get_signature_status() {
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let (io, meta, blockhash, alice) = start_rpc_handler_with_tx(&bob_pubkey);
|
let (io, meta, blockhash, alice) = start_rpc_handler_with_tx(&bob_pubkey);
|
||||||
let tx = SystemTransaction::new_transfer(&alice, &bob_pubkey, 20, blockhash, 0);
|
let tx = system_transaction::transfer(&alice, &bob_pubkey, 20, blockhash, 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":["{}"]}}"#,
|
||||||
|
@ -609,7 +609,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 = SystemTransaction::new_transfer(&alice, &bob_pubkey, 10, blockhash, 0);
|
let tx = system_transaction::transfer(&alice, &bob_pubkey, 10, blockhash, 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]
|
||||||
|
@ -716,13 +716,8 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rpc_verify_signature() {
|
fn test_rpc_verify_signature() {
|
||||||
let tx = SystemTransaction::new_transfer(
|
let tx =
|
||||||
&Keypair::new(),
|
system_transaction::transfer(&Keypair::new(), &Pubkey::new_rand(), 20, hash(&[0]), 0);
|
||||||
&Pubkey::new_rand(),
|
|
||||||
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]
|
||||||
|
|
|
@ -227,12 +227,12 @@ mod tests {
|
||||||
use jsonrpc_core::Response;
|
use jsonrpc_core::Response;
|
||||||
use jsonrpc_pubsub::{PubSubHandler, Session};
|
use jsonrpc_pubsub::{PubSubHandler, Session};
|
||||||
use solana_budget_api;
|
use solana_budget_api;
|
||||||
use solana_budget_api::budget_instruction::BudgetInstruction;
|
use solana_budget_api::budget_instruction;
|
||||||
use solana_runtime::bank::{self, Bank};
|
use solana_runtime::bank::{self, Bank};
|
||||||
use solana_sdk::genesis_block::GenesisBlock;
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
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;
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
@ -270,7 +270,7 @@ mod tests {
|
||||||
let rpc = RpcSolPubSubImpl::default();
|
let rpc = RpcSolPubSubImpl::default();
|
||||||
|
|
||||||
// Test signature subscriptions
|
// Test signature subscriptions
|
||||||
let tx = SystemTransaction::new_transfer(&alice, &bob_pubkey, 20, blockhash, 0);
|
let tx = system_transaction::transfer(&alice, &bob_pubkey, 20, blockhash, 0);
|
||||||
|
|
||||||
let session = create_session();
|
let session = create_session();
|
||||||
let (subscriber, _id_receiver, mut receiver) =
|
let (subscriber, _id_receiver, mut receiver) =
|
||||||
|
@ -302,7 +302,7 @@ mod tests {
|
||||||
let rpc = RpcSolPubSubImpl::default();
|
let rpc = RpcSolPubSubImpl::default();
|
||||||
io.extend_with(rpc.to_delegate());
|
io.extend_with(rpc.to_delegate());
|
||||||
|
|
||||||
let tx = SystemTransaction::new_transfer(&alice, &bob_pubkey, 20, blockhash, 0);
|
let tx = system_transaction::transfer(&alice, &bob_pubkey, 20, blockhash, 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()
|
||||||
|
@ -354,11 +354,16 @@ mod tests {
|
||||||
let (subscriber, _id_receiver, mut receiver) = Subscriber::new_test("accountNotification");
|
let (subscriber, _id_receiver, mut receiver) = Subscriber::new_test("accountNotification");
|
||||||
rpc.account_subscribe(session, subscriber, contract_state.pubkey().to_string());
|
rpc.account_subscribe(session, subscriber, contract_state.pubkey().to_string());
|
||||||
|
|
||||||
let tx =
|
let tx = system_transaction::create_user_account(
|
||||||
SystemTransaction::new_user_account(&alice, &contract_funds.pubkey(), 51, blockhash, 0);
|
&alice,
|
||||||
|
&contract_funds.pubkey(),
|
||||||
|
51,
|
||||||
|
blockhash,
|
||||||
|
0,
|
||||||
|
);
|
||||||
let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap();
|
let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap();
|
||||||
|
|
||||||
let ixs = BudgetInstruction::new_when_signed(
|
let ixs = budget_instruction::when_signed(
|
||||||
&contract_funds.pubkey(),
|
&contract_funds.pubkey(),
|
||||||
&bob_pubkey,
|
&bob_pubkey,
|
||||||
&contract_state.pubkey(),
|
&contract_state.pubkey(),
|
||||||
|
@ -391,10 +396,11 @@ mod tests {
|
||||||
assert_eq!(serde_json::to_string(&expected).unwrap(), response);
|
assert_eq!(serde_json::to_string(&expected).unwrap(), response);
|
||||||
}
|
}
|
||||||
|
|
||||||
let tx = SystemTransaction::new_user_account(&alice, &witness.pubkey(), 1, blockhash, 0);
|
let tx =
|
||||||
|
system_transaction::create_user_account(&alice, &witness.pubkey(), 1, blockhash, 0);
|
||||||
let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap();
|
let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap();
|
||||||
sleep(Duration::from_millis(200));
|
sleep(Duration::from_millis(200));
|
||||||
let ix = BudgetInstruction::new_apply_signature(
|
let ix = budget_instruction::apply_signature(
|
||||||
&witness.pubkey(),
|
&witness.pubkey(),
|
||||||
&contract_state.pubkey(),
|
&contract_state.pubkey(),
|
||||||
&bob_pubkey,
|
&bob_pubkey,
|
||||||
|
|
|
@ -202,7 +202,7 @@ mod tests {
|
||||||
use solana_budget_api;
|
use solana_budget_api;
|
||||||
use solana_sdk::genesis_block::GenesisBlock;
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction;
|
||||||
use tokio::prelude::{Async, Stream};
|
use tokio::prelude::{Async, Stream};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -211,7 +211,7 @@ mod tests {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let alice = Keypair::new();
|
let alice = Keypair::new();
|
||||||
let blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = system_transaction::create_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&alice.pubkey(),
|
&alice.pubkey(),
|
||||||
blockhash,
|
blockhash,
|
||||||
|
@ -257,7 +257,7 @@ mod tests {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let alice = Keypair::new();
|
let alice = Keypair::new();
|
||||||
let blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = system_transaction::create_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&alice.pubkey(),
|
&alice.pubkey(),
|
||||||
blockhash,
|
blockhash,
|
||||||
|
@ -302,7 +302,7 @@ mod tests {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let alice = Keypair::new();
|
let alice = Keypair::new();
|
||||||
let blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
let tx = SystemTransaction::new_transfer(&mint_keypair, &alice.pubkey(), 20, blockhash, 0);
|
let tx = system_transaction::transfer(&mint_keypair, &alice.pubkey(), 20, blockhash, 0);
|
||||||
let signature = tx.signatures[0];
|
let signature = tx.signatures[0];
|
||||||
bank.process_transaction(&tx).unwrap();
|
bank.process_transaction(&tx).unwrap();
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,9 @@ use solana_client::thin_client::{create_client_with_timeout, ThinClient};
|
||||||
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, KeypairUtil, Signature};
|
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use solana_storage_api::storage_instruction::StorageInstruction;
|
use solana_storage_api::storage_instruction::{self, StorageInstruction};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
|
@ -279,7 +279,7 @@ impl StorageStage {
|
||||||
if let Some(account) = account_to_create {
|
if let Some(account) = account_to_create {
|
||||||
if client.get_account_data(&account).is_err() {
|
if client.get_account_data(&account).is_err() {
|
||||||
// TODO the account space needs to be well defined somewhere
|
// TODO the account space needs to be well defined somewhere
|
||||||
let tx = SystemTransaction::new_account(
|
let tx = system_transaction::create_account(
|
||||||
keypair,
|
keypair,
|
||||||
&storage_keypair.pubkey(),
|
&storage_keypair.pubkey(),
|
||||||
blockhash,
|
blockhash,
|
||||||
|
@ -318,7 +318,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 ix = StorageInstruction::new_advertise_recent_blockhash(
|
let ix = storage_instruction::advertise_recent_blockhash(
|
||||||
&keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
entry_id,
|
entry_id,
|
||||||
entry_height,
|
entry_height,
|
||||||
|
@ -643,7 +643,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let mining_proof_ix = StorageInstruction::new_mining_proof(
|
let mining_proof_ix = storage_instruction::mining_proof(
|
||||||
&keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -3,14 +3,14 @@ use solana_sdk::instruction::CompiledInstruction;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_instruction::SystemInstruction;
|
use solana_sdk::system_instruction::SystemInstruction;
|
||||||
use solana_sdk::system_program;
|
use solana_sdk::system_program;
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction;
|
||||||
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();
|
||||||
SystemTransaction::new_user_account(&keypair1, &pubkey1, 42, zero, 0)
|
system_transaction::create_user_account(&keypair1, &pubkey1, 42, zero, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn test_multisig_tx() -> Transaction {
|
pub fn test_multisig_tx() -> Transaction {
|
||||||
|
@ -20,11 +20,15 @@ pub fn test_multisig_tx() -> Transaction {
|
||||||
let lamports = 5;
|
let lamports = 5;
|
||||||
let blockhash = Hash::default();
|
let blockhash = Hash::default();
|
||||||
|
|
||||||
let system_instruction = SystemInstruction::Transfer { lamports };
|
let transfer_instruction = SystemInstruction::Transfer { lamports };
|
||||||
|
|
||||||
let program_ids = vec![system_program::id(), solana_budget_api::id()];
|
let program_ids = vec![system_program::id(), solana_budget_api::id()];
|
||||||
|
|
||||||
let instructions = vec![CompiledInstruction::new(0, &system_instruction, vec![0, 1])];
|
let instructions = vec![CompiledInstruction::new(
|
||||||
|
0,
|
||||||
|
&transfer_instruction,
|
||||||
|
vec![0, 1],
|
||||||
|
)];
|
||||||
|
|
||||||
Transaction::new_with_compiled_instructions(
|
Transaction::new_with_compiled_instructions(
|
||||||
&keypairs,
|
&keypairs,
|
||||||
|
|
|
@ -110,7 +110,7 @@ pub mod tests {
|
||||||
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::transaction::Transaction;
|
||||||
use solana_vote_api::vote_instruction::{Vote, VoteInstruction};
|
use solana_vote_api::vote_instruction::{self, Vote};
|
||||||
|
|
||||||
fn process_instructions<T: KeypairUtil>(bank: &Bank, keypairs: &[&T], ixs: Vec<Instruction>) {
|
fn process_instructions<T: KeypairUtil>(bank: &Bank, keypairs: &[&T], ixs: Vec<Instruction>) {
|
||||||
let blockhash = bank.last_blockhash();
|
let blockhash = bank.last_blockhash();
|
||||||
|
@ -124,7 +124,7 @@ pub mod tests {
|
||||||
bank: &Bank,
|
bank: &Bank,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) {
|
) {
|
||||||
let ixs = VoteInstruction::new_account(&from_keypair.pubkey(), voting_pubkey, lamports);
|
let ixs = vote_instruction::create_account(&from_keypair.pubkey(), voting_pubkey, lamports);
|
||||||
process_instructions(bank, &[from_keypair], ixs);
|
process_instructions(bank, &[from_keypair], ixs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,16 +137,13 @@ pub mod tests {
|
||||||
) {
|
) {
|
||||||
let voting_pubkey = voting_keypair.pubkey();
|
let voting_pubkey = voting_keypair.pubkey();
|
||||||
let mut ixs =
|
let mut ixs =
|
||||||
VoteInstruction::new_account(&from_keypair.pubkey(), &voting_pubkey, lamports);
|
vote_instruction::create_account(&from_keypair.pubkey(), &voting_pubkey, lamports);
|
||||||
ixs.push(VoteInstruction::new_delegate_stake(
|
ixs.push(vote_instruction::delegate_stake(&voting_pubkey, delegate));
|
||||||
&voting_pubkey,
|
|
||||||
delegate,
|
|
||||||
));
|
|
||||||
process_instructions(bank, &[from_keypair, voting_keypair], ixs);
|
process_instructions(bank, &[from_keypair, voting_keypair], ixs);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_vote<T: KeypairUtil>(voting_keypair: &T, bank: &Bank, slot: u64) {
|
pub fn push_vote<T: KeypairUtil>(voting_keypair: &T, bank: &Bank, slot: u64) {
|
||||||
let ix = VoteInstruction::new_vote(&voting_keypair.pubkey(), Vote::new(slot));
|
let ix = vote_instruction::vote(&voting_keypair.pubkey(), Vote::new(slot));
|
||||||
process_instructions(bank, &[voting_keypair], vec![ix]);
|
process_instructions(bank, &[voting_keypair], vec![ix]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,8 +156,8 @@ pub mod tests {
|
||||||
) {
|
) {
|
||||||
let voting_pubkey = voting_keypair.pubkey();
|
let voting_pubkey = voting_keypair.pubkey();
|
||||||
let mut ixs =
|
let mut ixs =
|
||||||
VoteInstruction::new_account(&from_keypair.pubkey(), &voting_pubkey, lamports);
|
vote_instruction::create_account(&from_keypair.pubkey(), &voting_pubkey, lamports);
|
||||||
ixs.push(VoteInstruction::new_vote(&voting_pubkey, Vote::new(slot)));
|
ixs.push(vote_instruction::vote(&voting_pubkey, Vote::new(slot)));
|
||||||
process_instructions(bank, &[from_keypair, voting_keypair], ixs);
|
process_instructions(bank, &[from_keypair, voting_keypair], ixs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use solana::fullnode::new_fullnode_for_tests;
|
||||||
use solana_client::rpc_client::get_rpc_request_str;
|
use solana_client::rpc_client::get_rpc_request_str;
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_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;
|
||||||
|
@ -41,7 +41,7 @@ fn test_rpc_send_tx() {
|
||||||
let blockhash = Hash::new(&blockhash_vec);
|
let blockhash = Hash::new(&blockhash_vec);
|
||||||
|
|
||||||
info!("blockhash: {:?}", blockhash);
|
info!("blockhash: {:?}", blockhash);
|
||||||
let tx = SystemTransaction::new_transfer(&alice, &bob_pubkey, 20, blockhash, 0);
|
let tx = system_transaction::transfer(&alice, &bob_pubkey, 20, blockhash, 0);
|
||||||
let serial_tx = serialize(&tx).unwrap();
|
let serial_tx = serialize(&tx).unwrap();
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
|
|
@ -18,7 +18,7 @@ use solana::streamer;
|
||||||
use solana::tvu::{Sockets, Tvu};
|
use solana::tvu::{Sockets, Tvu};
|
||||||
use solana_sdk::genesis_block::GenesisBlock;
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_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};
|
||||||
|
@ -140,7 +140,7 @@ fn test_replay() {
|
||||||
let entry0 = next_entry_mut(&mut cur_hash, i, vec![]);
|
let entry0 = next_entry_mut(&mut cur_hash, i, vec![]);
|
||||||
let entry_tick0 = next_entry_mut(&mut cur_hash, i + 1, vec![]);
|
let entry_tick0 = next_entry_mut(&mut cur_hash, i + 1, vec![]);
|
||||||
|
|
||||||
let tx0 = SystemTransaction::new_user_account(
|
let tx0 = system_transaction::create_user_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&bob_keypair.pubkey(),
|
&bob_keypair.pubkey(),
|
||||||
transfer_amount,
|
transfer_amount,
|
||||||
|
|
|
@ -16,7 +16,7 @@ use solana_sdk::message::Message;
|
||||||
use solana_sdk::packet::PACKET_DATA_SIZE;
|
use solana_sdk::packet::PACKET_DATA_SIZE;
|
||||||
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_instruction::SystemInstruction;
|
use solana_sdk::system_instruction;
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::{Error, ErrorKind};
|
use std::io::{Error, ErrorKind};
|
||||||
|
@ -127,7 +127,7 @@ impl Drone {
|
||||||
|
|
||||||
info!("Requesting airdrop of {} to {:?}", lamports, to);
|
info!("Requesting airdrop of {} to {:?}", lamports, to);
|
||||||
|
|
||||||
let create_instruction = SystemInstruction::new_user_account(
|
let create_instruction = system_instruction::create_user_account(
|
||||||
&self.mint_keypair.pubkey(),
|
&self.mint_keypair.pubkey(),
|
||||||
&to,
|
&to,
|
||||||
lamports,
|
lamports,
|
||||||
|
@ -285,6 +285,7 @@ pub fn run_local_drone(mint_keypair: Keypair, sender: Sender<SocketAddr>) {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use bytes::BufMut;
|
use bytes::BufMut;
|
||||||
|
use solana_sdk::system_instruction::SystemInstruction;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -394,7 +395,7 @@ mod tests {
|
||||||
|
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let expected_instruction =
|
let expected_instruction =
|
||||||
SystemInstruction::new_user_account(&keypair.pubkey(), &to, lamports);
|
system_instruction::create_user_account(&keypair.pubkey(), &to, lamports);
|
||||||
let message = Message::new(vec![expected_instruction]);
|
let message = Message::new(vec![expected_instruction]);
|
||||||
let expected_tx = Transaction::new(&[&keypair], message, blockhash);
|
let expected_tx = Transaction::new(&[&keypair], message, blockhash);
|
||||||
let expected_bytes = serialize(&expected_tx).unwrap();
|
let expected_bytes = serialize(&expected_tx).unwrap();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
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, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction;
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use std::io::{Error, ErrorKind};
|
use std::io::{Error, ErrorKind};
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
@ -18,6 +18,6 @@ pub fn request_airdrop_transaction(
|
||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
let to = Pubkey::new_rand();
|
let to = Pubkey::new_rand();
|
||||||
let blockhash = Hash::default();
|
let blockhash = Hash::default();
|
||||||
let tx = SystemTransaction::new_user_account(&key, &to, lamports, blockhash, 0);
|
let tx = system_transaction::create_user_account(&key, &to, lamports, blockhash, 0);
|
||||||
Ok(tx)
|
Ok(tx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::message::Message;
|
use solana_sdk::message::Message;
|
||||||
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_instruction::SystemInstruction;
|
use solana_sdk::system_instruction;
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
|
|
||||||
|
@ -13,7 +13,8 @@ fn test_local_drone() {
|
||||||
let to = Pubkey::new_rand();
|
let to = Pubkey::new_rand();
|
||||||
let lamports = 50;
|
let lamports = 50;
|
||||||
let blockhash = Hash::new(&to.as_ref());
|
let blockhash = Hash::new(&to.as_ref());
|
||||||
let create_instruction = SystemInstruction::new_user_account(&keypair.pubkey(), &to, lamports);
|
let create_instruction =
|
||||||
|
system_instruction::create_user_account(&keypair.pubkey(), &to, lamports);
|
||||||
let message = Message::new(vec![create_instruction]);
|
let message = Message::new(vec![create_instruction]);
|
||||||
let expected_tx = Transaction::new(&[&keypair], message, blockhash);
|
let expected_tx = Transaction::new(&[&keypair], message, blockhash);
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use console::{style, Emoji};
|
||||||
use indicatif::{ProgressBar, ProgressStyle};
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
use ring::digest::{Context, Digest, SHA256};
|
use ring::digest::{Context, Digest, SHA256};
|
||||||
use solana_client::rpc_client::RpcClient;
|
use solana_client::rpc_client::RpcClient;
|
||||||
use solana_config_api::ConfigInstruction;
|
use solana_config_api::config_instruction;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{read_keypair, Keypair, KeypairUtil, Signable};
|
use solana_sdk::signature::{read_keypair, Keypair, KeypairUtil, Signable};
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
|
@ -198,7 +198,7 @@ fn new_update_manifest(
|
||||||
{
|
{
|
||||||
let recect_blockhash = rpc_client.get_recent_blockhash()?;
|
let recect_blockhash = rpc_client.get_recent_blockhash()?;
|
||||||
|
|
||||||
let new_account = ConfigInstruction::new_account::<SignedUpdateManifest>(
|
let new_account = config_instruction::create_account::<SignedUpdateManifest>(
|
||||||
&from_keypair.pubkey(),
|
&from_keypair.pubkey(),
|
||||||
&update_manifest_keypair.pubkey(),
|
&update_manifest_keypair.pubkey(),
|
||||||
1, // lamports
|
1, // lamports
|
||||||
|
@ -220,7 +220,7 @@ fn store_update_manifest(
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let recect_blockhash = rpc_client.get_recent_blockhash()?;
|
let recect_blockhash = rpc_client.get_recent_blockhash()?;
|
||||||
|
|
||||||
let new_store = ConfigInstruction::new_store::<SignedUpdateManifest>(
|
let new_store = config_instruction::store::<SignedUpdateManifest>(
|
||||||
&from_keypair.pubkey(),
|
&from_keypair.pubkey(),
|
||||||
&update_manifest_keypair.pubkey(),
|
&update_manifest_keypair.pubkey(),
|
||||||
update_manifest,
|
update_manifest,
|
||||||
|
|
|
@ -6,7 +6,7 @@ use chrono::prelude::{DateTime, Utc};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_sdk::instruction::{AccountMeta, Instruction};
|
use solana_sdk::instruction::{AccountMeta, Instruction};
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::system_instruction::SystemInstruction;
|
use solana_sdk::system_instruction;
|
||||||
|
|
||||||
/// A smart contract.
|
/// A smart contract.
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||||
|
@ -30,93 +30,90 @@ pub enum BudgetInstruction {
|
||||||
ApplySignature,
|
ApplySignature,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BudgetInstruction {
|
fn initialize_account(contract: &Pubkey, expr: BudgetExpr) -> Instruction {
|
||||||
fn new_initialize_account(contract: &Pubkey, expr: BudgetExpr) -> Instruction {
|
let mut keys = vec![];
|
||||||
let mut keys = vec![];
|
if let BudgetExpr::Pay(payment) = &expr {
|
||||||
if let BudgetExpr::Pay(payment) = &expr {
|
keys.push(AccountMeta::new(payment.to, false));
|
||||||
keys.push(AccountMeta::new(payment.to, false));
|
|
||||||
}
|
|
||||||
keys.push(AccountMeta::new(*contract, false));
|
|
||||||
Instruction::new(id(), &BudgetInstruction::InitializeAccount(expr), keys)
|
|
||||||
}
|
}
|
||||||
|
keys.push(AccountMeta::new(*contract, false));
|
||||||
|
Instruction::new(id(), &BudgetInstruction::InitializeAccount(expr), keys)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new_account(
|
pub fn create_account(
|
||||||
from: &Pubkey,
|
from: &Pubkey,
|
||||||
contract: &Pubkey,
|
contract: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
expr: BudgetExpr,
|
expr: BudgetExpr,
|
||||||
) -> Vec<Instruction> {
|
) -> Vec<Instruction> {
|
||||||
if !expr.verify(lamports) {
|
if !expr.verify(lamports) {
|
||||||
panic!("invalid budget expression");
|
panic!("invalid budget expression");
|
||||||
}
|
|
||||||
let space = serialized_size(&BudgetState::new(expr.clone())).unwrap();
|
|
||||||
vec![
|
|
||||||
SystemInstruction::new_account(&from, contract, lamports, space, &id()),
|
|
||||||
BudgetInstruction::new_initialize_account(contract, expr),
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
let space = serialized_size(&BudgetState::new(expr.clone())).unwrap();
|
||||||
|
vec![
|
||||||
|
system_instruction::create_account(&from, contract, lamports, space, &id()),
|
||||||
|
initialize_account(contract, expr),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
/// Create a new payment script.
|
/// Create a new payment script.
|
||||||
pub fn new_payment(from: &Pubkey, to: &Pubkey, lamports: u64) -> Vec<Instruction> {
|
pub fn payment(from: &Pubkey, to: &Pubkey, lamports: u64) -> Vec<Instruction> {
|
||||||
let contract = Pubkey::new_rand();
|
let contract = Pubkey::new_rand();
|
||||||
let expr = BudgetExpr::new_payment(lamports, to);
|
let expr = BudgetExpr::new_payment(lamports, to);
|
||||||
Self::new_account(from, &contract, lamports, expr)
|
create_account(from, &contract, lamports, expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a future payment script.
|
/// Create a future payment script.
|
||||||
pub fn new_on_date(
|
pub fn on_date(
|
||||||
from: &Pubkey,
|
from: &Pubkey,
|
||||||
to: &Pubkey,
|
to: &Pubkey,
|
||||||
contract: &Pubkey,
|
contract: &Pubkey,
|
||||||
dt: DateTime<Utc>,
|
dt: DateTime<Utc>,
|
||||||
dt_pubkey: &Pubkey,
|
dt_pubkey: &Pubkey,
|
||||||
cancelable: Option<Pubkey>,
|
cancelable: Option<Pubkey>,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Vec<Instruction> {
|
) -> Vec<Instruction> {
|
||||||
let expr =
|
let expr = BudgetExpr::new_cancelable_future_payment(dt, dt_pubkey, lamports, to, cancelable);
|
||||||
BudgetExpr::new_cancelable_future_payment(dt, dt_pubkey, lamports, to, cancelable);
|
create_account(from, contract, lamports, expr)
|
||||||
Self::new_account(from, contract, lamports, expr)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Create a multisig payment script.
|
/// Create a multisig payment script.
|
||||||
pub fn new_when_signed(
|
pub fn when_signed(
|
||||||
from: &Pubkey,
|
from: &Pubkey,
|
||||||
to: &Pubkey,
|
to: &Pubkey,
|
||||||
contract: &Pubkey,
|
contract: &Pubkey,
|
||||||
witness: &Pubkey,
|
witness: &Pubkey,
|
||||||
cancelable: Option<Pubkey>,
|
cancelable: Option<Pubkey>,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Vec<Instruction> {
|
) -> Vec<Instruction> {
|
||||||
let expr = BudgetExpr::new_cancelable_authorized_payment(witness, lamports, to, cancelable);
|
let expr = BudgetExpr::new_cancelable_authorized_payment(witness, lamports, to, cancelable);
|
||||||
Self::new_account(from, contract, lamports, expr)
|
create_account(from, contract, lamports, expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_apply_timestamp(
|
pub fn apply_timestamp(
|
||||||
from: &Pubkey,
|
from: &Pubkey,
|
||||||
contract: &Pubkey,
|
contract: &Pubkey,
|
||||||
to: &Pubkey,
|
to: &Pubkey,
|
||||||
dt: DateTime<Utc>,
|
dt: DateTime<Utc>,
|
||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let mut account_metas = vec![
|
let mut account_metas = vec![
|
||||||
AccountMeta::new(*from, true),
|
AccountMeta::new(*from, true),
|
||||||
AccountMeta::new(*contract, false),
|
AccountMeta::new(*contract, false),
|
||||||
];
|
];
|
||||||
if from != to {
|
if from != to {
|
||||||
account_metas.push(AccountMeta::new(*to, false));
|
account_metas.push(AccountMeta::new(*to, false));
|
||||||
}
|
|
||||||
Instruction::new(id(), &BudgetInstruction::ApplyTimestamp(dt), account_metas)
|
|
||||||
}
|
}
|
||||||
|
Instruction::new(id(), &BudgetInstruction::ApplyTimestamp(dt), account_metas)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new_apply_signature(from: &Pubkey, contract: &Pubkey, to: &Pubkey) -> Instruction {
|
pub fn apply_signature(from: &Pubkey, contract: &Pubkey, to: &Pubkey) -> Instruction {
|
||||||
let mut account_metas = vec![
|
let mut account_metas = vec![
|
||||||
AccountMeta::new(*from, true),
|
AccountMeta::new(*from, true),
|
||||||
AccountMeta::new(*contract, false),
|
AccountMeta::new(*contract, false),
|
||||||
];
|
];
|
||||||
if from != to {
|
if from != to {
|
||||||
account_metas.push(AccountMeta::new(*to, false));
|
account_metas.push(AccountMeta::new(*to, false));
|
||||||
}
|
|
||||||
Instruction::new(id(), &BudgetInstruction::ApplySignature, account_metas)
|
|
||||||
}
|
}
|
||||||
|
Instruction::new(id(), &BudgetInstruction::ApplySignature, account_metas)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -128,7 +125,7 @@ mod tests {
|
||||||
fn test_budget_instruction_verify() {
|
fn test_budget_instruction_verify() {
|
||||||
let alice_pubkey = Pubkey::new_rand();
|
let alice_pubkey = Pubkey::new_rand();
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
BudgetInstruction::new_payment(&alice_pubkey, &bob_pubkey, 1); // No panic! indicates success.
|
payment(&alice_pubkey, &bob_pubkey, 1); // No panic! indicates success.
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -138,7 +135,7 @@ mod tests {
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let budget_pubkey = Pubkey::new_rand();
|
let budget_pubkey = Pubkey::new_rand();
|
||||||
let expr = BudgetExpr::new_payment(2, &bob_pubkey);
|
let expr = BudgetExpr::new_payment(2, &bob_pubkey);
|
||||||
BudgetInstruction::new_account(&alice_pubkey, &budget_pubkey, 1, expr);
|
create_account(&alice_pubkey, &budget_pubkey, 1, expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -148,6 +145,6 @@ mod tests {
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let budget_pubkey = Pubkey::new_rand();
|
let budget_pubkey = Pubkey::new_rand();
|
||||||
let expr = BudgetExpr::new_payment(1, &bob_pubkey);
|
let expr = BudgetExpr::new_payment(1, &bob_pubkey);
|
||||||
BudgetInstruction::new_account(&alice_pubkey, &budget_pubkey, 2, expr);
|
create_account(&alice_pubkey, &budget_pubkey, 2, expr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,7 @@ pub fn process_instruction(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::budget_instruction::BudgetInstruction;
|
use crate::budget_instruction;
|
||||||
use crate::id;
|
use crate::id;
|
||||||
use solana_runtime::bank::Bank;
|
use solana_runtime::bank::Bank;
|
||||||
use solana_runtime::bank_client::BankClient;
|
use solana_runtime::bank_client::BankClient;
|
||||||
|
@ -166,7 +166,7 @@ mod tests {
|
||||||
let bank_client = BankClient::new(&bank);
|
let bank_client = BankClient::new(&bank);
|
||||||
let alice_pubkey = alice_keypair.pubkey();
|
let alice_pubkey = alice_keypair.pubkey();
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let instructions = BudgetInstruction::new_payment(&alice_pubkey, &bob_pubkey, 100);
|
let instructions = budget_instruction::payment(&alice_pubkey, &bob_pubkey, 100);
|
||||||
let message = Message::new(instructions);
|
let message = Message::new(instructions);
|
||||||
bank_client
|
bank_client
|
||||||
.process_message(&[&alice_keypair], message)
|
.process_message(&[&alice_keypair], message)
|
||||||
|
@ -184,7 +184,7 @@ mod tests {
|
||||||
let budget_pubkey = Pubkey::new_rand();
|
let budget_pubkey = Pubkey::new_rand();
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let witness = Pubkey::new_rand();
|
let witness = Pubkey::new_rand();
|
||||||
let instructions = BudgetInstruction::new_when_signed(
|
let instructions = budget_instruction::when_signed(
|
||||||
&alice_pubkey,
|
&alice_pubkey,
|
||||||
&bob_pubkey,
|
&bob_pubkey,
|
||||||
&budget_pubkey,
|
&budget_pubkey,
|
||||||
|
@ -204,7 +204,7 @@ mod tests {
|
||||||
.transfer(1, &alice_keypair, &mallory_pubkey)
|
.transfer(1, &alice_keypair, &mallory_pubkey)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let instruction =
|
let instruction =
|
||||||
BudgetInstruction::new_apply_signature(&mallory_pubkey, &budget_pubkey, &bob_pubkey);
|
budget_instruction::apply_signature(&mallory_pubkey, &budget_pubkey, &bob_pubkey);
|
||||||
let mut message = Message::new(vec![instruction]);
|
let mut message = Message::new(vec![instruction]);
|
||||||
|
|
||||||
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
||||||
|
@ -231,7 +231,7 @@ mod tests {
|
||||||
let budget_pubkey = Pubkey::new_rand();
|
let budget_pubkey = Pubkey::new_rand();
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let dt = Utc::now();
|
let dt = Utc::now();
|
||||||
let instructions = BudgetInstruction::new_on_date(
|
let instructions = budget_instruction::on_date(
|
||||||
&alice_pubkey,
|
&alice_pubkey,
|
||||||
&bob_pubkey,
|
&bob_pubkey,
|
||||||
&budget_pubkey,
|
&budget_pubkey,
|
||||||
|
@ -251,12 +251,8 @@ mod tests {
|
||||||
bank_client
|
bank_client
|
||||||
.transfer(1, &alice_keypair, &mallory_pubkey)
|
.transfer(1, &alice_keypair, &mallory_pubkey)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let instruction = BudgetInstruction::new_apply_timestamp(
|
let instruction =
|
||||||
&mallory_pubkey,
|
budget_instruction::apply_timestamp(&mallory_pubkey, &budget_pubkey, &bob_pubkey, dt);
|
||||||
&budget_pubkey,
|
|
||||||
&bob_pubkey,
|
|
||||||
dt,
|
|
||||||
);
|
|
||||||
let mut message = Message::new(vec![instruction]);
|
let mut message = Message::new(vec![instruction]);
|
||||||
|
|
||||||
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
||||||
|
@ -282,7 +278,7 @@ mod tests {
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let mallory_pubkey = Pubkey::new_rand();
|
let mallory_pubkey = Pubkey::new_rand();
|
||||||
let dt = Utc::now();
|
let dt = Utc::now();
|
||||||
let instructions = BudgetInstruction::new_on_date(
|
let instructions = budget_instruction::on_date(
|
||||||
&alice_pubkey,
|
&alice_pubkey,
|
||||||
&bob_pubkey,
|
&bob_pubkey,
|
||||||
&budget_pubkey,
|
&budget_pubkey,
|
||||||
|
@ -303,12 +299,8 @@ mod tests {
|
||||||
assert!(budget_state.is_pending());
|
assert!(budget_state.is_pending());
|
||||||
|
|
||||||
// Attack! Try to payout to mallory_pubkey
|
// Attack! Try to payout to mallory_pubkey
|
||||||
let instruction = BudgetInstruction::new_apply_timestamp(
|
let instruction =
|
||||||
&alice_pubkey,
|
budget_instruction::apply_timestamp(&alice_pubkey, &budget_pubkey, &mallory_pubkey, dt);
|
||||||
&budget_pubkey,
|
|
||||||
&mallory_pubkey,
|
|
||||||
dt,
|
|
||||||
);
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank_client
|
bank_client
|
||||||
.process_instruction(&alice_keypair, instruction)
|
.process_instruction(&alice_keypair, instruction)
|
||||||
|
@ -329,7 +321,7 @@ mod tests {
|
||||||
// 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 instruction =
|
let instruction =
|
||||||
BudgetInstruction::new_apply_timestamp(&alice_pubkey, &budget_pubkey, &bob_pubkey, dt);
|
budget_instruction::apply_timestamp(&alice_pubkey, &budget_pubkey, &bob_pubkey, dt);
|
||||||
bank_client
|
bank_client
|
||||||
.process_instruction(&alice_keypair, instruction)
|
.process_instruction(&alice_keypair, instruction)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -348,7 +340,7 @@ mod tests {
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let dt = Utc::now();
|
let dt = Utc::now();
|
||||||
|
|
||||||
let instructions = BudgetInstruction::new_on_date(
|
let instructions = budget_instruction::on_date(
|
||||||
&alice_pubkey,
|
&alice_pubkey,
|
||||||
&bob_pubkey,
|
&bob_pubkey,
|
||||||
&budget_pubkey,
|
&budget_pubkey,
|
||||||
|
@ -377,7 +369,7 @@ mod tests {
|
||||||
assert_eq!(bank.get_balance(&alice_pubkey), 1);
|
assert_eq!(bank.get_balance(&alice_pubkey), 1);
|
||||||
|
|
||||||
let instruction =
|
let instruction =
|
||||||
BudgetInstruction::new_apply_signature(&mallory_pubkey, &budget_pubkey, &bob_pubkey);
|
budget_instruction::apply_signature(&mallory_pubkey, &budget_pubkey, &bob_pubkey);
|
||||||
bank_client
|
bank_client
|
||||||
.process_instruction(&mallory_keypair, instruction)
|
.process_instruction(&mallory_keypair, instruction)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
@ -388,7 +380,7 @@ mod tests {
|
||||||
|
|
||||||
// Now, cancel the transaction. mint gets her funds back
|
// Now, cancel the transaction. mint gets her funds back
|
||||||
let instruction =
|
let instruction =
|
||||||
BudgetInstruction::new_apply_signature(&alice_pubkey, &budget_pubkey, &alice_pubkey);
|
budget_instruction::apply_signature(&alice_pubkey, &budget_pubkey, &alice_pubkey);
|
||||||
bank_client
|
bank_client
|
||||||
.process_instruction(&alice_keypair, instruction)
|
.process_instruction(&alice_keypair, instruction)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -2,36 +2,32 @@ use crate::id;
|
||||||
use crate::ConfigState;
|
use crate::ConfigState;
|
||||||
use solana_sdk::instruction::{AccountMeta, Instruction};
|
use solana_sdk::instruction::{AccountMeta, Instruction};
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::system_instruction::SystemInstruction;
|
use solana_sdk::system_instruction;
|
||||||
|
|
||||||
pub struct ConfigInstruction {}
|
/// Create a new, empty configuration account
|
||||||
|
pub fn create_account<T: ConfigState>(
|
||||||
impl ConfigInstruction {
|
from_account_pubkey: &Pubkey,
|
||||||
/// Create a new, empty configuration account
|
config_account_pubkey: &Pubkey,
|
||||||
pub fn new_account<T: ConfigState>(
|
lamports: u64,
|
||||||
from_account_pubkey: &Pubkey,
|
) -> Instruction {
|
||||||
config_account_pubkey: &Pubkey,
|
system_instruction::create_account(
|
||||||
lamports: u64,
|
from_account_pubkey,
|
||||||
) -> Instruction {
|
config_account_pubkey,
|
||||||
SystemInstruction::new_account(
|
lamports,
|
||||||
from_account_pubkey,
|
T::max_space(),
|
||||||
config_account_pubkey,
|
&id(),
|
||||||
lamports,
|
)
|
||||||
T::max_space(),
|
}
|
||||||
&id(),
|
|
||||||
)
|
/// Store new data in a configuration account
|
||||||
}
|
pub fn store<T: ConfigState>(
|
||||||
|
from_account_pubkey: &Pubkey,
|
||||||
/// Store new data in a configuration account
|
config_account_pubkey: &Pubkey,
|
||||||
pub fn new_store<T: ConfigState>(
|
data: &T,
|
||||||
from_account_pubkey: &Pubkey,
|
) -> Instruction {
|
||||||
config_account_pubkey: &Pubkey,
|
let account_metas = vec![
|
||||||
data: &T,
|
AccountMeta::new(*from_account_pubkey, true),
|
||||||
) -> Instruction {
|
AccountMeta::new(*config_account_pubkey, true),
|
||||||
let account_metas = vec![
|
];
|
||||||
AccountMeta::new(*from_account_pubkey, true),
|
Instruction::new(id(), data, account_metas)
|
||||||
AccountMeta::new(*config_account_pubkey, true),
|
|
||||||
];
|
|
||||||
Instruction::new(id(), data, account_metas)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ pub fn process_instruction(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{id, ConfigInstruction, ConfigState};
|
use crate::{config_instruction, id, ConfigState};
|
||||||
use bincode::{deserialize, serialized_size};
|
use bincode::{deserialize, serialized_size};
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_runtime::bank::Bank;
|
use solana_runtime::bank::Bank;
|
||||||
|
@ -36,7 +36,7 @@ mod tests {
|
||||||
use solana_sdk::genesis_block::GenesisBlock;
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
use solana_sdk::message::Message;
|
use solana_sdk::message::Message;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_instruction::SystemInstruction;
|
use solana_sdk::system_instruction;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Default, Debug, PartialEq)]
|
#[derive(Serialize, Deserialize, Default, Debug, PartialEq)]
|
||||||
struct MyConfig {
|
struct MyConfig {
|
||||||
|
@ -78,7 +78,7 @@ mod tests {
|
||||||
bank_client
|
bank_client
|
||||||
.process_instruction(
|
.process_instruction(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
ConfigInstruction::new_account::<MyConfig>(
|
config_instruction::create_account::<MyConfig>(
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
&config_pubkey,
|
&config_pubkey,
|
||||||
1,
|
1,
|
||||||
|
@ -111,7 +111,7 @@ mod tests {
|
||||||
|
|
||||||
let my_config = MyConfig::new(42);
|
let my_config = MyConfig::new(42);
|
||||||
let instruction =
|
let instruction =
|
||||||
ConfigInstruction::new_store(&from_keypair.pubkey(), &config_pubkey, &my_config);
|
config_instruction::store(&from_keypair.pubkey(), &config_pubkey, &my_config);
|
||||||
let message = Message::new(vec![instruction]);
|
let message = Message::new(vec![instruction]);
|
||||||
bank_client
|
bank_client
|
||||||
.process_message(&[&from_keypair, &config_keypair], message)
|
.process_message(&[&from_keypair, &config_keypair], message)
|
||||||
|
@ -133,11 +133,8 @@ mod tests {
|
||||||
let my_config = MyConfig::new(42);
|
let my_config = MyConfig::new(42);
|
||||||
|
|
||||||
// Replace instruction data with a vector that's too large
|
// Replace instruction data with a vector that's too large
|
||||||
let mut instruction = ConfigInstruction::new_store(
|
let mut instruction =
|
||||||
&from_keypair.pubkey(),
|
config_instruction::store(&from_keypair.pubkey(), &config_keypair.pubkey(), &my_config);
|
||||||
&config_keypair.pubkey(),
|
|
||||||
&my_config,
|
|
||||||
);
|
|
||||||
instruction.data = vec![0; 123];
|
instruction.data = vec![0; 123];
|
||||||
|
|
||||||
let message = Message::new(vec![instruction]);
|
let message = Message::new(vec![instruction]);
|
||||||
|
@ -155,14 +152,10 @@ mod tests {
|
||||||
bank.transfer(42, &mint_keypair, &system_pubkey).unwrap();
|
bank.transfer(42, &mint_keypair, &system_pubkey).unwrap();
|
||||||
let (bank_client, from_keypair, config_keypair) = create_config_client(&bank, mint_keypair);
|
let (bank_client, from_keypair, config_keypair) = create_config_client(&bank, mint_keypair);
|
||||||
|
|
||||||
let move_instruction =
|
let move_instruction = system_instruction::transfer(&system_pubkey, &Pubkey::default(), 42);
|
||||||
SystemInstruction::new_transfer(&system_pubkey, &Pubkey::default(), 42);
|
|
||||||
let my_config = MyConfig::new(42);
|
let my_config = MyConfig::new(42);
|
||||||
let mut store_instruction = ConfigInstruction::new_store(
|
let mut store_instruction =
|
||||||
&from_keypair.pubkey(),
|
config_instruction::store(&from_keypair.pubkey(), &config_keypair.pubkey(), &my_config);
|
||||||
&config_keypair.pubkey(),
|
|
||||||
&my_config,
|
|
||||||
);
|
|
||||||
store_instruction.accounts[0].is_signer = false;
|
store_instruction.accounts[0].is_signer = false;
|
||||||
store_instruction.accounts[1].is_signer = false;
|
store_instruction.accounts[1].is_signer = false;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
|
|
||||||
mod config_instruction;
|
pub mod config_instruction;
|
||||||
pub mod config_processor;
|
pub mod config_processor;
|
||||||
|
|
||||||
pub use config_instruction::ConfigInstruction;
|
|
||||||
|
|
||||||
const CONFIG_PROGRAM_ID: [u8; 32] = [
|
const CONFIG_PROGRAM_ID: [u8; 32] = [
|
||||||
133, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
133, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0,
|
0,
|
||||||
|
|
|
@ -59,89 +59,88 @@ pub enum ExchangeInstruction {
|
||||||
/// key 6 - Token account in which to deposit the brokers profit from the swap.
|
/// key 6 - Token account in which to deposit the brokers profit from the swap.
|
||||||
SwapRequest,
|
SwapRequest,
|
||||||
}
|
}
|
||||||
impl ExchangeInstruction {
|
|
||||||
pub fn new_account_request(owner: &Pubkey, new: &Pubkey) -> Instruction {
|
|
||||||
let account_metas = vec![
|
|
||||||
AccountMeta::new(*owner, true),
|
|
||||||
AccountMeta::new(*new, false),
|
|
||||||
];
|
|
||||||
Instruction::new(id(), &ExchangeInstruction::AccountRequest, account_metas)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_transfer_request(
|
pub fn account_request(owner: &Pubkey, new: &Pubkey) -> Instruction {
|
||||||
owner: &Pubkey,
|
let account_metas = vec![
|
||||||
to: &Pubkey,
|
AccountMeta::new(*owner, true),
|
||||||
from: &Pubkey,
|
AccountMeta::new(*new, false),
|
||||||
token: Token,
|
];
|
||||||
tokens: u64,
|
Instruction::new(id(), &ExchangeInstruction::AccountRequest, account_metas)
|
||||||
) -> Instruction {
|
}
|
||||||
let account_metas = vec![
|
|
||||||
AccountMeta::new(*owner, true),
|
pub fn transfer_request(
|
||||||
AccountMeta::new(*to, false),
|
owner: &Pubkey,
|
||||||
AccountMeta::new(*from, false),
|
to: &Pubkey,
|
||||||
];
|
from: &Pubkey,
|
||||||
Instruction::new(
|
token: Token,
|
||||||
id(),
|
tokens: u64,
|
||||||
&ExchangeInstruction::TransferRequest(token, tokens),
|
) -> Instruction {
|
||||||
account_metas,
|
let account_metas = vec![
|
||||||
)
|
AccountMeta::new(*owner, true),
|
||||||
}
|
AccountMeta::new(*to, false),
|
||||||
|
AccountMeta::new(*from, false),
|
||||||
pub fn new_trade_request(
|
];
|
||||||
owner: &Pubkey,
|
Instruction::new(
|
||||||
trade: &Pubkey,
|
id(),
|
||||||
direction: Direction,
|
&ExchangeInstruction::TransferRequest(token, tokens),
|
||||||
pair: TokenPair,
|
account_metas,
|
||||||
tokens: u64,
|
)
|
||||||
price: u64,
|
}
|
||||||
src_account: &Pubkey,
|
|
||||||
dst_account: &Pubkey,
|
pub fn trade_request(
|
||||||
) -> Instruction {
|
owner: &Pubkey,
|
||||||
let account_metas = vec![
|
trade: &Pubkey,
|
||||||
AccountMeta::new(*owner, true),
|
direction: Direction,
|
||||||
AccountMeta::new(*trade, false),
|
pair: TokenPair,
|
||||||
AccountMeta::new(*src_account, false),
|
tokens: u64,
|
||||||
];
|
price: u64,
|
||||||
Instruction::new(
|
src_account: &Pubkey,
|
||||||
id(),
|
dst_account: &Pubkey,
|
||||||
&ExchangeInstruction::TradeRequest(TradeRequestInfo {
|
) -> Instruction {
|
||||||
direction,
|
let account_metas = vec![
|
||||||
pair,
|
AccountMeta::new(*owner, true),
|
||||||
tokens,
|
AccountMeta::new(*trade, false),
|
||||||
price,
|
AccountMeta::new(*src_account, false),
|
||||||
dst_account: *dst_account,
|
];
|
||||||
}),
|
Instruction::new(
|
||||||
account_metas,
|
id(),
|
||||||
)
|
&ExchangeInstruction::TradeRequest(TradeRequestInfo {
|
||||||
}
|
direction,
|
||||||
|
pair,
|
||||||
pub fn new_trade_cancellation(owner: &Pubkey, trade: &Pubkey, account: &Pubkey) -> Instruction {
|
tokens,
|
||||||
let account_metas = vec![
|
price,
|
||||||
AccountMeta::new(*owner, true),
|
dst_account: *dst_account,
|
||||||
AccountMeta::new(*trade, false),
|
}),
|
||||||
AccountMeta::new(*account, false),
|
account_metas,
|
||||||
];
|
)
|
||||||
Instruction::new(id(), &ExchangeInstruction::TradeCancellation, account_metas)
|
}
|
||||||
}
|
|
||||||
|
pub fn trade_cancellation(owner: &Pubkey, trade: &Pubkey, account: &Pubkey) -> Instruction {
|
||||||
pub fn new_swap_request(
|
let account_metas = vec![
|
||||||
owner: &Pubkey,
|
AccountMeta::new(*owner, true),
|
||||||
swap: &Pubkey,
|
AccountMeta::new(*trade, false),
|
||||||
to_trade: &Pubkey,
|
AccountMeta::new(*account, false),
|
||||||
from_trade: &Pubkey,
|
];
|
||||||
to_trade_account: &Pubkey,
|
Instruction::new(id(), &ExchangeInstruction::TradeCancellation, account_metas)
|
||||||
from_trade_account: &Pubkey,
|
}
|
||||||
profit_account: &Pubkey,
|
|
||||||
) -> Instruction {
|
pub fn swap_request(
|
||||||
let account_metas = vec![
|
owner: &Pubkey,
|
||||||
AccountMeta::new(*owner, true),
|
swap: &Pubkey,
|
||||||
AccountMeta::new(*swap, false),
|
to_trade: &Pubkey,
|
||||||
AccountMeta::new(*to_trade, false),
|
from_trade: &Pubkey,
|
||||||
AccountMeta::new(*from_trade, false),
|
to_trade_account: &Pubkey,
|
||||||
AccountMeta::new(*to_trade_account, false),
|
from_trade_account: &Pubkey,
|
||||||
AccountMeta::new(*from_trade_account, false),
|
profit_account: &Pubkey,
|
||||||
AccountMeta::new(*profit_account, false),
|
) -> Instruction {
|
||||||
];
|
let account_metas = vec![
|
||||||
Instruction::new(id(), &ExchangeInstruction::SwapRequest, account_metas)
|
AccountMeta::new(*owner, true),
|
||||||
}
|
AccountMeta::new(*swap, false),
|
||||||
|
AccountMeta::new(*to_trade, false),
|
||||||
|
AccountMeta::new(*from_trade, false),
|
||||||
|
AccountMeta::new(*to_trade_account, false),
|
||||||
|
AccountMeta::new(*from_trade_account, false),
|
||||||
|
AccountMeta::new(*profit_account, false),
|
||||||
|
];
|
||||||
|
Instruction::new(id(), &ExchangeInstruction::SwapRequest, account_metas)
|
||||||
}
|
}
|
||||||
|
|
|
@ -412,11 +412,12 @@ pub fn process_instruction(
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::exchange_instruction;
|
||||||
use solana_runtime::bank::Bank;
|
use solana_runtime::bank::Bank;
|
||||||
use solana_runtime::bank_client::BankClient;
|
use solana_runtime::bank_client::BankClient;
|
||||||
use solana_sdk::genesis_block::GenesisBlock;
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_instruction::SystemInstruction;
|
use solana_sdk::system_instruction;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
fn try_calc(
|
fn try_calc(
|
||||||
|
@ -527,7 +528,7 @@ mod test {
|
||||||
|
|
||||||
fn create_account(client: &BankClient, owner: &Keypair) -> Pubkey {
|
fn create_account(client: &BankClient, owner: &Keypair) -> Pubkey {
|
||||||
let new = Pubkey::new_rand();
|
let new = Pubkey::new_rand();
|
||||||
let instruction = SystemInstruction::new_account(
|
let instruction = system_instruction::create_account(
|
||||||
&owner.pubkey(),
|
&owner.pubkey(),
|
||||||
&new,
|
&new,
|
||||||
1,
|
1,
|
||||||
|
@ -542,7 +543,7 @@ mod test {
|
||||||
|
|
||||||
fn create_token_account(client: &BankClient, owner: &Keypair) -> Pubkey {
|
fn create_token_account(client: &BankClient, owner: &Keypair) -> Pubkey {
|
||||||
let new = Pubkey::new_rand();
|
let new = Pubkey::new_rand();
|
||||||
let instruction = SystemInstruction::new_account(
|
let instruction = system_instruction::create_account(
|
||||||
&owner.pubkey(),
|
&owner.pubkey(),
|
||||||
&new,
|
&new,
|
||||||
1,
|
1,
|
||||||
|
@ -552,7 +553,7 @@ mod test {
|
||||||
client
|
client
|
||||||
.process_instruction(owner, instruction)
|
.process_instruction(owner, instruction)
|
||||||
.expect(&format!("{}:{}", line!(), file!()));
|
.expect(&format!("{}:{}", line!(), file!()));
|
||||||
let instruction = ExchangeInstruction::new_account_request(&owner.pubkey(), &new);
|
let instruction = exchange_instruction::account_request(&owner.pubkey(), &new);
|
||||||
client
|
client
|
||||||
.process_instruction(owner, instruction)
|
.process_instruction(owner, instruction)
|
||||||
.expect(&format!("{}:{}", line!(), file!()));
|
.expect(&format!("{}:{}", line!(), file!()));
|
||||||
|
@ -561,7 +562,7 @@ mod test {
|
||||||
|
|
||||||
fn transfer(client: &BankClient, owner: &Keypair, to: &Pubkey, token: Token, tokens: u64) {
|
fn transfer(client: &BankClient, owner: &Keypair, to: &Pubkey, token: Token, tokens: u64) {
|
||||||
let instruction =
|
let instruction =
|
||||||
ExchangeInstruction::new_transfer_request(&owner.pubkey(), to, &id(), token, tokens);
|
exchange_instruction::transfer_request(&owner.pubkey(), to, &id(), token, tokens);
|
||||||
client
|
client
|
||||||
.process_instruction(owner, instruction)
|
.process_instruction(owner, instruction)
|
||||||
.expect(&format!("{}:{}", line!(), file!()));
|
.expect(&format!("{}:{}", line!(), file!()));
|
||||||
|
@ -582,7 +583,7 @@ mod test {
|
||||||
let dst = create_token_account(&client, &owner);
|
let dst = create_token_account(&client, &owner);
|
||||||
transfer(&client, &owner, &src, from_token, src_tokens);
|
transfer(&client, &owner, &src, from_token, src_tokens);
|
||||||
|
|
||||||
let instruction = ExchangeInstruction::new_trade_request(
|
let instruction = exchange_instruction::trade_request(
|
||||||
&owner.pubkey(),
|
&owner.pubkey(),
|
||||||
&trade,
|
&trade,
|
||||||
direction,
|
direction,
|
||||||
|
@ -633,7 +634,7 @@ mod test {
|
||||||
let (client, owner) = create_client(&bank, mint_keypair);
|
let (client, owner) = create_client(&bank, mint_keypair);
|
||||||
|
|
||||||
let new = create_token_account(&client, &owner);
|
let new = create_token_account(&client, &owner);
|
||||||
let instruction = ExchangeInstruction::new_account_request(&owner.pubkey(), &new);
|
let instruction = exchange_instruction::account_request(&owner.pubkey(), &new);
|
||||||
client
|
client
|
||||||
.process_instruction(&owner, instruction)
|
.process_instruction(&owner, instruction)
|
||||||
.expect_err(&format!("{}:{}", line!(), file!()));
|
.expect_err(&format!("{}:{}", line!(), file!()));
|
||||||
|
@ -648,7 +649,7 @@ mod test {
|
||||||
let new = create_token_account(&client, &owner);
|
let new = create_token_account(&client, &owner);
|
||||||
|
|
||||||
let instruction =
|
let instruction =
|
||||||
ExchangeInstruction::new_transfer_request(&owner.pubkey(), &new, &id(), Token::A, 42);
|
exchange_instruction::transfer_request(&owner.pubkey(), &new, &id(), Token::A, 42);
|
||||||
client
|
client
|
||||||
.process_instruction(&owner, instruction)
|
.process_instruction(&owner, instruction)
|
||||||
.expect(&format!("{}:{}", line!(), file!()));
|
.expect(&format!("{}:{}", line!(), file!()));
|
||||||
|
@ -743,7 +744,7 @@ mod test {
|
||||||
3000,
|
3000,
|
||||||
);
|
);
|
||||||
|
|
||||||
let instruction = ExchangeInstruction::new_swap_request(
|
let instruction = exchange_instruction::swap_request(
|
||||||
&owner.pubkey(),
|
&owner.pubkey(),
|
||||||
&swap,
|
&swap,
|
||||||
&to_trade,
|
&to_trade,
|
||||||
|
|
|
@ -1,120 +1,103 @@
|
||||||
use crate::exchange_instruction::*;
|
use crate::exchange_instruction;
|
||||||
use crate::exchange_state::*;
|
use crate::exchange_state::*;
|
||||||
use crate::id;
|
use crate::id;
|
||||||
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, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_instruction::SystemInstruction;
|
use solana_sdk::system_instruction;
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
pub struct ExchangeTransaction {}
|
pub fn account_request(
|
||||||
|
owner: &Keypair,
|
||||||
impl ExchangeTransaction {
|
new: &Pubkey,
|
||||||
pub fn new_account_request(
|
recent_blockhash: Hash,
|
||||||
owner: &Keypair,
|
_fee: u64,
|
||||||
new: &Pubkey,
|
) -> Transaction {
|
||||||
recent_blockhash: Hash,
|
let owner_id = &owner.pubkey();
|
||||||
_fee: u64,
|
let space = mem::size_of::<ExchangeState>() as u64;
|
||||||
) -> Transaction {
|
let create_ix = system_instruction::create_account(owner_id, new, 1, space, &id());
|
||||||
let owner_id = &owner.pubkey();
|
let request_ix = exchange_instruction::account_request(owner_id, new);
|
||||||
let space = mem::size_of::<ExchangeState>() as u64;
|
Transaction::new_signed_instructions(&[owner], vec![create_ix, request_ix], recent_blockhash)
|
||||||
let create_ix = SystemInstruction::new_account(owner_id, new, 1, space, &id());
|
}
|
||||||
let request_ix = ExchangeInstruction::new_account_request(owner_id, new);
|
|
||||||
Transaction::new_signed_instructions(
|
pub fn transfer_request(
|
||||||
&[owner],
|
owner: &Keypair,
|
||||||
vec![create_ix, request_ix],
|
to: &Pubkey,
|
||||||
recent_blockhash,
|
from: &Pubkey,
|
||||||
)
|
token: Token,
|
||||||
}
|
tokens: u64,
|
||||||
|
recent_blockhash: Hash,
|
||||||
pub fn new_transfer_request(
|
_fee: u64,
|
||||||
owner: &Keypair,
|
) -> Transaction {
|
||||||
to: &Pubkey,
|
let owner_id = &owner.pubkey();
|
||||||
from: &Pubkey,
|
let request_ix = exchange_instruction::transfer_request(owner_id, to, from, token, tokens);
|
||||||
token: Token,
|
Transaction::new_signed_instructions(&[owner], vec![request_ix], recent_blockhash)
|
||||||
tokens: u64,
|
}
|
||||||
recent_blockhash: Hash,
|
|
||||||
_fee: u64,
|
#[allow(clippy::too_many_arguments)]
|
||||||
) -> Transaction {
|
pub fn trade_request(
|
||||||
let owner_id = &owner.pubkey();
|
owner: &Keypair,
|
||||||
let request_ix =
|
trade: &Pubkey,
|
||||||
ExchangeInstruction::new_transfer_request(owner_id, to, from, token, tokens);
|
direction: Direction,
|
||||||
Transaction::new_signed_instructions(&[owner], vec![request_ix], recent_blockhash)
|
pair: TokenPair,
|
||||||
}
|
tokens: u64,
|
||||||
|
price: u64,
|
||||||
#[allow(clippy::too_many_arguments)]
|
src_account: &Pubkey,
|
||||||
pub fn new_trade_request(
|
dst_account: &Pubkey,
|
||||||
owner: &Keypair,
|
recent_blockhash: Hash,
|
||||||
trade: &Pubkey,
|
_fee: u64,
|
||||||
direction: Direction,
|
) -> Transaction {
|
||||||
pair: TokenPair,
|
let owner_id = &owner.pubkey();
|
||||||
tokens: u64,
|
let space = mem::size_of::<ExchangeState>() as u64;
|
||||||
price: u64,
|
let create_ix = system_instruction::create_account(owner_id, trade, 1, space, &id());
|
||||||
src_account: &Pubkey,
|
let request_ix = exchange_instruction::trade_request(
|
||||||
dst_account: &Pubkey,
|
owner_id,
|
||||||
recent_blockhash: Hash,
|
trade,
|
||||||
_fee: u64,
|
direction,
|
||||||
) -> Transaction {
|
pair,
|
||||||
let owner_id = &owner.pubkey();
|
tokens,
|
||||||
let space = mem::size_of::<ExchangeState>() as u64;
|
price,
|
||||||
let create_ix = SystemInstruction::new_account(owner_id, trade, 1, space, &id());
|
src_account,
|
||||||
let request_ix = ExchangeInstruction::new_trade_request(
|
dst_account,
|
||||||
owner_id,
|
);
|
||||||
trade,
|
Transaction::new_signed_instructions(&[owner], vec![create_ix, request_ix], recent_blockhash)
|
||||||
direction,
|
}
|
||||||
pair,
|
|
||||||
tokens,
|
pub fn trade_cancellation(
|
||||||
price,
|
owner: &Keypair,
|
||||||
src_account,
|
trade: &Pubkey,
|
||||||
dst_account,
|
account: &Pubkey,
|
||||||
);
|
recent_blockhash: Hash,
|
||||||
Transaction::new_signed_instructions(
|
_fee: u64,
|
||||||
&[owner],
|
) -> Transaction {
|
||||||
vec![create_ix, request_ix],
|
let owner_id = &owner.pubkey();
|
||||||
recent_blockhash,
|
let request_ix = exchange_instruction::trade_cancellation(owner_id, trade, account);
|
||||||
)
|
Transaction::new_signed_instructions(&[owner], vec![request_ix], recent_blockhash)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_trade_cancellation(
|
pub fn swap_request(
|
||||||
owner: &Keypair,
|
owner: &Keypair,
|
||||||
trade: &Pubkey,
|
swap: &Pubkey,
|
||||||
account: &Pubkey,
|
to_trade: &Pubkey,
|
||||||
recent_blockhash: Hash,
|
from_trade: &Pubkey,
|
||||||
_fee: u64,
|
to_trade_account: &Pubkey,
|
||||||
) -> Transaction {
|
from_trade_account: &Pubkey,
|
||||||
let owner_id = &owner.pubkey();
|
profit_account: &Pubkey,
|
||||||
let request_ix = ExchangeInstruction::new_trade_cancellation(owner_id, trade, account);
|
recent_blockhash: Hash,
|
||||||
Transaction::new_signed_instructions(&[owner], vec![request_ix], recent_blockhash)
|
_fee: u64,
|
||||||
}
|
) -> Transaction {
|
||||||
|
let owner_id = &owner.pubkey();
|
||||||
pub fn new_swap_request(
|
let space = mem::size_of::<ExchangeState>() as u64;
|
||||||
owner: &Keypair,
|
let create_ix = system_instruction::create_account(owner_id, swap, 1, space, &id());
|
||||||
swap: &Pubkey,
|
let request_ix = exchange_instruction::swap_request(
|
||||||
to_trade: &Pubkey,
|
owner_id,
|
||||||
from_trade: &Pubkey,
|
swap,
|
||||||
to_trade_account: &Pubkey,
|
to_trade,
|
||||||
from_trade_account: &Pubkey,
|
from_trade,
|
||||||
profit_account: &Pubkey,
|
to_trade_account,
|
||||||
recent_blockhash: Hash,
|
from_trade_account,
|
||||||
_fee: u64,
|
profit_account,
|
||||||
) -> Transaction {
|
);
|
||||||
let owner_id = &owner.pubkey();
|
Transaction::new_signed_instructions(&[owner], vec![create_ix, request_ix], recent_blockhash)
|
||||||
let space = mem::size_of::<ExchangeState>() as u64;
|
|
||||||
let create_ix = SystemInstruction::new_account(owner_id, swap, 1, space, &id());
|
|
||||||
let request_ix = ExchangeInstruction::new_swap_request(
|
|
||||||
owner_id,
|
|
||||||
swap,
|
|
||||||
to_trade,
|
|
||||||
from_trade,
|
|
||||||
to_trade_account,
|
|
||||||
from_trade_account,
|
|
||||||
profit_account,
|
|
||||||
);
|
|
||||||
Transaction::new_signed_instructions(
|
|
||||||
&[owner],
|
|
||||||
vec![create_ix, request_ix],
|
|
||||||
recent_blockhash,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_sdk::account::KeyedAccount;
|
use solana_sdk::account::KeyedAccount;
|
||||||
use solana_sdk::instruction::{AccountMeta, Instruction, InstructionError};
|
use solana_sdk::instruction::{AccountMeta, Instruction, InstructionError};
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::system_instruction::SystemInstruction;
|
use solana_sdk::system_instruction;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||||
pub enum StakeInstruction {
|
pub enum StakeInstruction {
|
||||||
|
@ -22,44 +22,38 @@ pub enum StakeInstruction {
|
||||||
RedeemVoteCredits,
|
RedeemVoteCredits,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StakeInstruction {
|
pub fn create_account(from_id: &Pubkey, staker_id: &Pubkey, lamports: u64) -> Vec<Instruction> {
|
||||||
pub fn new_account(from_id: &Pubkey, staker_id: &Pubkey, lamports: u64) -> Vec<Instruction> {
|
vec![system_instruction::create_account(
|
||||||
vec![SystemInstruction::new_account(
|
from_id,
|
||||||
from_id,
|
staker_id,
|
||||||
staker_id,
|
lamports,
|
||||||
lamports,
|
std::mem::size_of::<StakeState>() as u64,
|
||||||
std::mem::size_of::<StakeState>() as u64,
|
&id(),
|
||||||
&id(),
|
)]
|
||||||
)]
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_redeem_vote_credits(
|
pub fn redeem_vote_credits(
|
||||||
from_id: &Pubkey,
|
from_id: &Pubkey,
|
||||||
mining_pool_id: &Pubkey,
|
mining_pool_id: &Pubkey,
|
||||||
stake_id: &Pubkey,
|
stake_id: &Pubkey,
|
||||||
vote_id: &Pubkey,
|
vote_id: &Pubkey,
|
||||||
) -> Instruction {
|
) -> Instruction {
|
||||||
let account_metas = vec![
|
let account_metas = vec![
|
||||||
AccountMeta::new(*from_id, true),
|
AccountMeta::new(*from_id, true),
|
||||||
AccountMeta::new(*mining_pool_id, false),
|
AccountMeta::new(*mining_pool_id, false),
|
||||||
AccountMeta::new(*stake_id, false),
|
AccountMeta::new(*stake_id, false),
|
||||||
AccountMeta::new(*vote_id, false),
|
AccountMeta::new(*vote_id, false),
|
||||||
];
|
];
|
||||||
Instruction::new(id(), &StakeInstruction::RedeemVoteCredits, account_metas)
|
Instruction::new(id(), &StakeInstruction::RedeemVoteCredits, account_metas)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_delegate_stake(
|
pub fn delegate_stake(from_id: &Pubkey, stake_id: &Pubkey, vote_id: &Pubkey) -> Instruction {
|
||||||
from_id: &Pubkey,
|
let account_metas = vec![
|
||||||
stake_id: &Pubkey,
|
AccountMeta::new(*from_id, true),
|
||||||
vote_id: &Pubkey,
|
AccountMeta::new(*stake_id, true),
|
||||||
) -> Instruction {
|
AccountMeta::new(*vote_id, false),
|
||||||
let account_metas = vec![
|
];
|
||||||
AccountMeta::new(*from_id, true),
|
Instruction::new(id(), &StakeInstruction::DelegateStake, account_metas)
|
||||||
AccountMeta::new(*stake_id, true),
|
|
||||||
AccountMeta::new(*vote_id, false),
|
|
||||||
];
|
|
||||||
Instruction::new(id(), &StakeInstruction::DelegateStake, account_metas)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_instruction(
|
pub fn process_instruction(
|
||||||
|
|
|
@ -26,51 +26,49 @@ pub enum StorageInstruction {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StorageInstruction {
|
pub fn mining_proof(
|
||||||
pub fn new_mining_proof(
|
from_pubkey: &Pubkey,
|
||||||
from_pubkey: &Pubkey,
|
sha_state: Hash,
|
||||||
sha_state: Hash,
|
entry_height: u64,
|
||||||
entry_height: u64,
|
signature: Signature,
|
||||||
signature: Signature,
|
) -> Instruction {
|
||||||
) -> Instruction {
|
let storage_instruction = StorageInstruction::SubmitMiningProof {
|
||||||
let storage_instruction = StorageInstruction::SubmitMiningProof {
|
sha_state,
|
||||||
sha_state,
|
entry_height,
|
||||||
entry_height,
|
signature,
|
||||||
signature,
|
};
|
||||||
};
|
let account_metas = vec![AccountMeta::new(*from_pubkey, true)];
|
||||||
let account_metas = vec![AccountMeta::new(*from_pubkey, true)];
|
Instruction::new(id(), &storage_instruction, account_metas)
|
||||||
Instruction::new(id(), &storage_instruction, account_metas)
|
}
|
||||||
}
|
|
||||||
|
pub fn advertise_recent_blockhash(
|
||||||
pub fn new_advertise_recent_blockhash(
|
from_pubkey: &Pubkey,
|
||||||
from_pubkey: &Pubkey,
|
storage_hash: Hash,
|
||||||
storage_hash: Hash,
|
entry_height: u64,
|
||||||
entry_height: u64,
|
) -> Instruction {
|
||||||
) -> Instruction {
|
let storage_instruction = StorageInstruction::AdvertiseStorageRecentBlockhash {
|
||||||
let storage_instruction = StorageInstruction::AdvertiseStorageRecentBlockhash {
|
hash: storage_hash,
|
||||||
hash: storage_hash,
|
entry_height,
|
||||||
entry_height,
|
};
|
||||||
};
|
let account_metas = vec![AccountMeta::new(*from_pubkey, true)];
|
||||||
let account_metas = vec![AccountMeta::new(*from_pubkey, true)];
|
Instruction::new(id(), &storage_instruction, account_metas)
|
||||||
Instruction::new(id(), &storage_instruction, account_metas)
|
}
|
||||||
}
|
|
||||||
|
pub fn proof_validation(
|
||||||
pub fn new_proof_validation(
|
from_pubkey: &Pubkey,
|
||||||
from_pubkey: &Pubkey,
|
entry_height: u64,
|
||||||
entry_height: u64,
|
proof_mask: Vec<ProofStatus>,
|
||||||
proof_mask: Vec<ProofStatus>,
|
) -> Instruction {
|
||||||
) -> Instruction {
|
let storage_instruction = StorageInstruction::ProofValidation {
|
||||||
let storage_instruction = StorageInstruction::ProofValidation {
|
entry_height,
|
||||||
entry_height,
|
proof_mask,
|
||||||
proof_mask,
|
};
|
||||||
};
|
let account_metas = vec![AccountMeta::new(*from_pubkey, true)];
|
||||||
let account_metas = vec![AccountMeta::new(*from_pubkey, true)];
|
Instruction::new(id(), &storage_instruction, account_metas)
|
||||||
Instruction::new(id(), &storage_instruction, account_metas)
|
}
|
||||||
}
|
|
||||||
|
pub fn reward_claim(from_pubkey: &Pubkey, entry_height: u64) -> Instruction {
|
||||||
pub fn new_reward_claim(from_pubkey: &Pubkey, entry_height: u64) -> Instruction {
|
let storage_instruction = StorageInstruction::ClaimStorageReward { entry_height };
|
||||||
let storage_instruction = StorageInstruction::ClaimStorageReward { entry_height };
|
let account_metas = vec![AccountMeta::new(*from_pubkey, true)];
|
||||||
let account_metas = vec![AccountMeta::new(*from_pubkey, true)];
|
Instruction::new(id(), &storage_instruction, account_metas)
|
||||||
Instruction::new(id(), &storage_instruction, account_metas)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,6 +171,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::id;
|
use crate::id;
|
||||||
use crate::storage_contract::ProofStatus;
|
use crate::storage_contract::ProofStatus;
|
||||||
|
use crate::storage_instruction;
|
||||||
use crate::ENTRIES_PER_SEGMENT;
|
use crate::ENTRIES_PER_SEGMENT;
|
||||||
use bincode::deserialize;
|
use bincode::deserialize;
|
||||||
use solana_runtime::bank::Bank;
|
use solana_runtime::bank::Bank;
|
||||||
|
@ -181,7 +182,7 @@ mod tests {
|
||||||
use solana_sdk::instruction::Instruction;
|
use solana_sdk::instruction::Instruction;
|
||||||
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_instruction::SystemInstruction;
|
use solana_sdk::system_instruction;
|
||||||
|
|
||||||
fn test_instruction(
|
fn test_instruction(
|
||||||
ix: &Instruction,
|
ix: &Instruction,
|
||||||
|
@ -216,7 +217,7 @@ mod tests {
|
||||||
let mut user_account = Account::default();
|
let mut user_account = Account::default();
|
||||||
keyed_accounts.push(KeyedAccount::new(&pubkey, true, &mut user_account));
|
keyed_accounts.push(KeyedAccount::new(&pubkey, true, &mut user_account));
|
||||||
|
|
||||||
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
let ix = storage_instruction::advertise_recent_blockhash(
|
||||||
&pubkey,
|
&pubkey,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
ENTRIES_PER_SEGMENT,
|
ENTRIES_PER_SEGMENT,
|
||||||
|
@ -234,7 +235,7 @@ mod tests {
|
||||||
let mut accounts = [Account::default()];
|
let mut accounts = [Account::default()];
|
||||||
|
|
||||||
let ix =
|
let ix =
|
||||||
StorageInstruction::new_mining_proof(&pubkey, Hash::default(), 0, Signature::default());
|
storage_instruction::mining_proof(&pubkey, Hash::default(), 0, Signature::default());
|
||||||
assert!(test_instruction(&ix, &mut accounts).is_err());
|
assert!(test_instruction(&ix, &mut accounts).is_err());
|
||||||
|
|
||||||
let mut accounts = [Account::default(), Account::default(), Account::default()];
|
let mut accounts = [Account::default(), Account::default(), Account::default()];
|
||||||
|
@ -250,7 +251,7 @@ mod tests {
|
||||||
accounts[1].data.resize(16 * 1024, 0);
|
accounts[1].data.resize(16 * 1024, 0);
|
||||||
|
|
||||||
let ix =
|
let ix =
|
||||||
StorageInstruction::new_mining_proof(&pubkey, Hash::default(), 0, Signature::default());
|
storage_instruction::mining_proof(&pubkey, Hash::default(), 0, Signature::default());
|
||||||
|
|
||||||
// Haven't seen a transaction to roll over the epoch, so this should fail
|
// Haven't seen a transaction to roll over the epoch, so this should fail
|
||||||
assert!(test_instruction(&ix, &mut accounts).is_err());
|
assert!(test_instruction(&ix, &mut accounts).is_err());
|
||||||
|
@ -263,7 +264,7 @@ mod tests {
|
||||||
let mut accounts = [Account::default(), Account::default()];
|
let mut accounts = [Account::default(), Account::default()];
|
||||||
accounts[0].data.resize(16 * 1024, 0);
|
accounts[0].data.resize(16 * 1024, 0);
|
||||||
|
|
||||||
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
let ix = storage_instruction::advertise_recent_blockhash(
|
||||||
&pubkey,
|
&pubkey,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
ENTRIES_PER_SEGMENT,
|
ENTRIES_PER_SEGMENT,
|
||||||
|
@ -272,7 +273,7 @@ mod tests {
|
||||||
test_instruction(&ix, &mut accounts).unwrap();
|
test_instruction(&ix, &mut accounts).unwrap();
|
||||||
|
|
||||||
let ix =
|
let ix =
|
||||||
StorageInstruction::new_mining_proof(&pubkey, Hash::default(), 0, Signature::default());
|
storage_instruction::mining_proof(&pubkey, Hash::default(), 0, Signature::default());
|
||||||
|
|
||||||
test_instruction(&ix, &mut accounts).unwrap();
|
test_instruction(&ix, &mut accounts).unwrap();
|
||||||
}
|
}
|
||||||
|
@ -286,7 +287,7 @@ mod tests {
|
||||||
|
|
||||||
let entry_height = 0;
|
let entry_height = 0;
|
||||||
|
|
||||||
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
let ix = storage_instruction::advertise_recent_blockhash(
|
||||||
&pubkey,
|
&pubkey,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
ENTRIES_PER_SEGMENT,
|
ENTRIES_PER_SEGMENT,
|
||||||
|
@ -294,7 +295,7 @@ mod tests {
|
||||||
|
|
||||||
test_instruction(&ix, &mut accounts).unwrap();
|
test_instruction(&ix, &mut accounts).unwrap();
|
||||||
|
|
||||||
let ix = StorageInstruction::new_mining_proof(
|
let ix = storage_instruction::mining_proof(
|
||||||
&pubkey,
|
&pubkey,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
entry_height,
|
entry_height,
|
||||||
|
@ -302,28 +303,25 @@ mod tests {
|
||||||
);
|
);
|
||||||
test_instruction(&ix, &mut accounts).unwrap();
|
test_instruction(&ix, &mut accounts).unwrap();
|
||||||
|
|
||||||
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
let ix = storage_instruction::advertise_recent_blockhash(
|
||||||
&pubkey,
|
&pubkey,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
ENTRIES_PER_SEGMENT * 2,
|
ENTRIES_PER_SEGMENT * 2,
|
||||||
);
|
);
|
||||||
test_instruction(&ix, &mut accounts).unwrap();
|
test_instruction(&ix, &mut accounts).unwrap();
|
||||||
|
|
||||||
let ix = StorageInstruction::new_proof_validation(
|
let ix =
|
||||||
&pubkey,
|
storage_instruction::proof_validation(&pubkey, entry_height, vec![ProofStatus::Valid]);
|
||||||
entry_height,
|
|
||||||
vec![ProofStatus::Valid],
|
|
||||||
);
|
|
||||||
test_instruction(&ix, &mut accounts).unwrap();
|
test_instruction(&ix, &mut accounts).unwrap();
|
||||||
|
|
||||||
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
let ix = storage_instruction::advertise_recent_blockhash(
|
||||||
&pubkey,
|
&pubkey,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
ENTRIES_PER_SEGMENT * 3,
|
ENTRIES_PER_SEGMENT * 3,
|
||||||
);
|
);
|
||||||
test_instruction(&ix, &mut accounts).unwrap();
|
test_instruction(&ix, &mut accounts).unwrap();
|
||||||
|
|
||||||
let ix = StorageInstruction::new_reward_claim(&pubkey, entry_height);
|
let ix = storage_instruction::reward_claim(&pubkey, entry_height);
|
||||||
test_instruction(&ix, &mut accounts).unwrap();
|
test_instruction(&ix, &mut accounts).unwrap();
|
||||||
|
|
||||||
assert!(accounts[0].lamports == TOTAL_VALIDATOR_REWARDS);
|
assert!(accounts[0].lamports == TOTAL_VALIDATOR_REWARDS);
|
||||||
|
@ -386,11 +384,11 @@ mod tests {
|
||||||
.transfer(10, &alice_keypair, &jack_pubkey)
|
.transfer(10, &alice_keypair, &jack_pubkey)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let ix = SystemInstruction::new_account(&alice_pubkey, &bob_pubkey, 1, 4 * 1024, &id());
|
let ix = system_instruction::create_account(&alice_pubkey, &bob_pubkey, 1, 4 * 1024, &id());
|
||||||
|
|
||||||
bank_client.process_instruction(&alice_keypair, ix).unwrap();
|
bank_client.process_instruction(&alice_keypair, ix).unwrap();
|
||||||
|
|
||||||
let ix = StorageInstruction::new_advertise_recent_blockhash(
|
let ix = storage_instruction::advertise_recent_blockhash(
|
||||||
&bob_pubkey,
|
&bob_pubkey,
|
||||||
storage_blockhash,
|
storage_blockhash,
|
||||||
ENTRIES_PER_SEGMENT,
|
ENTRIES_PER_SEGMENT,
|
||||||
|
@ -399,7 +397,7 @@ mod tests {
|
||||||
bank_client.process_instruction(&bob_keypair, ix).unwrap();
|
bank_client.process_instruction(&bob_keypair, ix).unwrap();
|
||||||
|
|
||||||
let entry_height = 0;
|
let entry_height = 0;
|
||||||
let ix = StorageInstruction::new_mining_proof(
|
let ix = storage_instruction::mining_proof(
|
||||||
&bob_pubkey,
|
&bob_pubkey,
|
||||||
Hash::default(),
|
Hash::default(),
|
||||||
entry_height,
|
entry_height,
|
||||||
|
|
|
@ -3,7 +3,7 @@ use crate::vote_state::VoteState;
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use solana_sdk::instruction::{AccountMeta, Instruction};
|
use solana_sdk::instruction::{AccountMeta, Instruction};
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::system_instruction::SystemInstruction;
|
use solana_sdk::system_instruction;
|
||||||
|
|
||||||
#[derive(Serialize, Default, Deserialize, Debug, PartialEq, Eq, Clone)]
|
#[derive(Serialize, Default, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||||
pub struct Vote {
|
pub struct Vote {
|
||||||
|
@ -37,44 +37,42 @@ pub enum VoteInstruction {
|
||||||
ClearCredits,
|
ClearCredits,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VoteInstruction {
|
fn initialize_account(vote_id: &Pubkey) -> Instruction {
|
||||||
fn new_initialize_account(vote_id: &Pubkey) -> Instruction {
|
let account_metas = vec![AccountMeta::new(*vote_id, false)];
|
||||||
let account_metas = vec![AccountMeta::new(*vote_id, false)];
|
Instruction::new(id(), &VoteInstruction::InitializeAccount, account_metas)
|
||||||
Instruction::new(id(), &VoteInstruction::InitializeAccount, account_metas)
|
}
|
||||||
}
|
|
||||||
|
pub fn create_account(from_id: &Pubkey, staker_id: &Pubkey, lamports: u64) -> Vec<Instruction> {
|
||||||
pub fn new_account(from_id: &Pubkey, staker_id: &Pubkey, lamports: u64) -> Vec<Instruction> {
|
let space = VoteState::max_size() as u64;
|
||||||
let space = VoteState::max_size() as u64;
|
let create_ix = system_instruction::create_account(&from_id, staker_id, lamports, space, &id());
|
||||||
let create_ix = SystemInstruction::new_account(&from_id, staker_id, lamports, space, &id());
|
let init_ix = initialize_account(staker_id);
|
||||||
let init_ix = VoteInstruction::new_initialize_account(staker_id);
|
vec![create_ix, init_ix]
|
||||||
vec![create_ix, init_ix]
|
}
|
||||||
}
|
|
||||||
|
pub fn clear_credits(vote_id: &Pubkey) -> Instruction {
|
||||||
pub fn new_clear_credits(vote_id: &Pubkey) -> Instruction {
|
let account_metas = vec![AccountMeta::new(*vote_id, true)];
|
||||||
let account_metas = vec![AccountMeta::new(*vote_id, true)];
|
Instruction::new(id(), &VoteInstruction::ClearCredits, account_metas)
|
||||||
Instruction::new(id(), &VoteInstruction::ClearCredits, account_metas)
|
}
|
||||||
}
|
|
||||||
|
pub fn delegate_stake(vote_id: &Pubkey, delegate_id: &Pubkey) -> Instruction {
|
||||||
pub fn new_delegate_stake(vote_id: &Pubkey, delegate_id: &Pubkey) -> Instruction {
|
let account_metas = vec![AccountMeta::new(*vote_id, true)];
|
||||||
let account_metas = vec![AccountMeta::new(*vote_id, true)];
|
Instruction::new(
|
||||||
Instruction::new(
|
id(),
|
||||||
id(),
|
&VoteInstruction::DelegateStake(*delegate_id),
|
||||||
&VoteInstruction::DelegateStake(*delegate_id),
|
account_metas,
|
||||||
account_metas,
|
)
|
||||||
)
|
}
|
||||||
}
|
|
||||||
|
pub fn authorize_voter(vote_id: &Pubkey, authorized_voter_id: &Pubkey) -> Instruction {
|
||||||
pub fn new_authorize_voter(vote_id: &Pubkey, authorized_voter_id: &Pubkey) -> Instruction {
|
let account_metas = vec![AccountMeta::new(*vote_id, true)];
|
||||||
let account_metas = vec![AccountMeta::new(*vote_id, true)];
|
Instruction::new(
|
||||||
Instruction::new(
|
id(),
|
||||||
id(),
|
&VoteInstruction::AuthorizeVoter(*authorized_voter_id),
|
||||||
&VoteInstruction::AuthorizeVoter(*authorized_voter_id),
|
account_metas,
|
||||||
account_metas,
|
)
|
||||||
)
|
}
|
||||||
}
|
|
||||||
|
pub fn vote(vote_id: &Pubkey, vote: Vote) -> Instruction {
|
||||||
pub fn new_vote(vote_id: &Pubkey, vote: Vote) -> Instruction {
|
let account_metas = vec![AccountMeta::new(*vote_id, true)];
|
||||||
let account_metas = vec![AccountMeta::new(*vote_id, true)];
|
Instruction::new(id(), &VoteInstruction::Vote(vote), account_metas)
|
||||||
Instruction::new(id(), &VoteInstruction::Vote(vote), account_metas)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ pub fn process_instruction(
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::id;
|
use crate::id;
|
||||||
use crate::vote_instruction::{Vote, VoteInstruction};
|
use crate::vote_instruction::{self, Vote};
|
||||||
use crate::vote_state::VoteState;
|
use crate::vote_state::VoteState;
|
||||||
use solana_runtime::bank::{Bank, Result};
|
use solana_runtime::bank::{Bank, Result};
|
||||||
use solana_runtime::bank_client::BankClient;
|
use solana_runtime::bank_client::BankClient;
|
||||||
|
@ -54,7 +54,7 @@ mod tests {
|
||||||
use solana_sdk::message::Message;
|
use solana_sdk::message::Message;
|
||||||
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_instruction::SystemInstruction;
|
use solana_sdk::system_instruction;
|
||||||
use solana_sdk::transaction::TransactionError;
|
use solana_sdk::transaction::TransactionError;
|
||||||
|
|
||||||
fn create_bank(lamports: u64) -> (Bank, Keypair) {
|
fn create_bank(lamports: u64) -> (Bank, Keypair) {
|
||||||
|
@ -70,7 +70,7 @@ mod tests {
|
||||||
vote_id: &Pubkey,
|
vote_id: &Pubkey,
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let ixs = VoteInstruction::new_account(&from_keypair.pubkey(), vote_id, lamports);
|
let ixs = vote_instruction::create_account(&from_keypair.pubkey(), vote_id, lamports);
|
||||||
let message = Message::new(ixs);
|
let message = Message::new(ixs);
|
||||||
bank_client.process_message(&[from_keypair], message)
|
bank_client.process_message(&[from_keypair], message)
|
||||||
}
|
}
|
||||||
|
@ -83,8 +83,8 @@ mod tests {
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let vote_id = vote_keypair.pubkey();
|
let vote_id = vote_keypair.pubkey();
|
||||||
let mut ixs = VoteInstruction::new_account(&from_keypair.pubkey(), &vote_id, lamports);
|
let mut ixs = vote_instruction::create_account(&from_keypair.pubkey(), &vote_id, lamports);
|
||||||
let delegate_ix = VoteInstruction::new_delegate_stake(&vote_id, delegate_id);
|
let delegate_ix = vote_instruction::delegate_stake(&vote_id, delegate_id);
|
||||||
ixs.push(delegate_ix);
|
ixs.push(delegate_ix);
|
||||||
let message = Message::new(ixs);
|
let message = Message::new(ixs);
|
||||||
bank_client.process_message(&[&from_keypair, vote_keypair], message)
|
bank_client.process_message(&[&from_keypair, vote_keypair], message)
|
||||||
|
@ -95,7 +95,7 @@ mod tests {
|
||||||
vote_keypair: &Keypair,
|
vote_keypair: &Keypair,
|
||||||
tick_height: u64,
|
tick_height: u64,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let vote_ix = VoteInstruction::new_vote(&vote_keypair.pubkey(), Vote::new(tick_height));
|
let vote_ix = vote_instruction::vote(&vote_keypair.pubkey(), Vote::new(tick_height));
|
||||||
bank_client.process_instruction(&vote_keypair, vote_ix)
|
bank_client.process_instruction(&vote_keypair, vote_ix)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,13 +142,13 @@ mod tests {
|
||||||
create_vote_account(&bank_client, &mallory_keypair, &vote_id, 100).unwrap();
|
create_vote_account(&bank_client, &mallory_keypair, &vote_id, 100).unwrap();
|
||||||
|
|
||||||
let mallory_id = mallory_keypair.pubkey();
|
let mallory_id = mallory_keypair.pubkey();
|
||||||
let mut vote_ix = VoteInstruction::new_vote(&vote_id, Vote::new(0));
|
let mut vote_ix = vote_instruction::vote(&vote_id, Vote::new(0));
|
||||||
vote_ix.accounts[0].is_signer = false; // <--- attack!! No signer required.
|
vote_ix.accounts[0].is_signer = false; // <--- attack!! No signer required.
|
||||||
|
|
||||||
// Sneak in an instruction so that the transaction is signed but
|
// Sneak in an instruction so that the transaction is signed but
|
||||||
// the 0th account in the second instruction is not! The program
|
// the 0th account in the second instruction is not! The program
|
||||||
// needs to check that it's signed.
|
// needs to check that it's signed.
|
||||||
let move_ix = SystemInstruction::new_transfer(&mallory_id, &vote_id, 1);
|
let move_ix = system_instruction::transfer(&mallory_id, &vote_id, 1);
|
||||||
let message = Message::new(vec![move_ix, vote_ix]);
|
let message = Message::new(vec![move_ix, vote_ix]);
|
||||||
let result = bank_client.process_message(&[&mallory_keypair], message);
|
let result = bank_client.process_message(&[&mallory_keypair], message);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use solana_runtime::bank::*;
|
||||||
use solana_sdk::genesis_block::GenesisBlock;
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
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;
|
||||||
use solana_sdk::timing::{DEFAULT_TICKS_PER_SLOT, MAX_RECENT_BLOCKHASHES};
|
use solana_sdk::timing::{DEFAULT_TICKS_PER_SLOT, MAX_RECENT_BLOCKHASHES};
|
||||||
use test::Bencher;
|
use test::Bencher;
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ 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 = SystemTransaction::new_transfer(
|
let tx = system_transaction::transfer(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&rando0.pubkey(),
|
&rando0.pubkey(),
|
||||||
10_000,
|
10_000,
|
||||||
|
@ -32,7 +32,7 @@ fn bench_process_transaction(bencher: &mut Bencher) {
|
||||||
|
|
||||||
// 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 = SystemTransaction::new_transfer(
|
let tx = system_transaction::transfer(
|
||||||
&rando0,
|
&rando0,
|
||||||
&rando1.pubkey(),
|
&rando1.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
|
|
@ -20,7 +20,7 @@ use solana_sdk::hash::{extend_and_hash, Hash};
|
||||||
use solana_sdk::native_loader;
|
use solana_sdk::native_loader;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, Signature};
|
use solana_sdk::signature::{Keypair, Signature};
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction;
|
||||||
use solana_sdk::timing::{duration_as_ms, duration_as_us, MAX_RECENT_BLOCKHASHES};
|
use solana_sdk::timing::{duration_as_ms, duration_as_us, MAX_RECENT_BLOCKHASHES};
|
||||||
use solana_sdk::transaction::{Transaction, TransactionError};
|
use solana_sdk::transaction::{Transaction, TransactionError};
|
||||||
use solana_vote_api::vote_instruction::Vote;
|
use solana_vote_api::vote_instruction::Vote;
|
||||||
|
@ -777,7 +777,7 @@ impl Bank {
|
||||||
/// `n` lamports where `blockhash` is the last Entry ID observed by the client.
|
/// `n` lamports where `blockhash` is the last Entry ID observed by the client.
|
||||||
pub fn transfer(&self, n: u64, keypair: &Keypair, to: &Pubkey) -> Result<Signature> {
|
pub fn transfer(&self, n: u64, keypair: &Keypair, to: &Pubkey) -> Result<Signature> {
|
||||||
let blockhash = self.last_blockhash();
|
let blockhash = self.last_blockhash();
|
||||||
let tx = SystemTransaction::new_user_account(keypair, to, n, blockhash, 0);
|
let tx = system_transaction::create_user_account(keypair, to, n, blockhash, 0);
|
||||||
let signature = tx.signatures[0];
|
let signature = tx.signatures[0];
|
||||||
self.process_transaction(&tx).map(|_| signature)
|
self.process_transaction(&tx).map(|_| signature)
|
||||||
}
|
}
|
||||||
|
@ -973,8 +973,8 @@ mod tests {
|
||||||
use solana_sdk::hash;
|
use solana_sdk::hash;
|
||||||
use solana_sdk::instruction::InstructionError;
|
use solana_sdk::instruction::InstructionError;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_instruction::SystemInstruction;
|
use solana_sdk::system_instruction;
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bank_new() {
|
fn test_bank_new() {
|
||||||
|
@ -1027,8 +1027,8 @@ mod tests {
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
assert_eq!(bank.last_blockhash(), genesis_block.hash());
|
assert_eq!(bank.last_blockhash(), genesis_block.hash());
|
||||||
|
|
||||||
let t1 = SystemTransaction::new_transfer(&mint_keypair, &key1, 1, genesis_block.hash(), 0);
|
let t1 = system_transaction::transfer(&mint_keypair, &key1, 1, genesis_block.hash(), 0);
|
||||||
let t2 = SystemTransaction::new_transfer(&mint_keypair, &key2, 1, genesis_block.hash(), 0);
|
let t2 = system_transaction::transfer(&mint_keypair, &key2, 1, genesis_block.hash(), 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(()));
|
||||||
|
@ -1051,7 +1051,7 @@ mod tests {
|
||||||
let key2 = Pubkey::new_rand();
|
let key2 = Pubkey::new_rand();
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let instructions =
|
let instructions =
|
||||||
SystemInstruction::new_transfer_many(&mint_keypair.pubkey(), &[(key1, 1), (key2, 1)]);
|
system_instruction::transfer_many(&mint_keypair.pubkey(), &[(key1, 1), (key2, 1)]);
|
||||||
let tx = Transaction::new_signed_instructions(
|
let tx = Transaction::new_signed_instructions(
|
||||||
&[&mint_keypair],
|
&[&mint_keypair],
|
||||||
instructions,
|
instructions,
|
||||||
|
@ -1076,7 +1076,7 @@ mod tests {
|
||||||
let key2 = Pubkey::new_rand();
|
let key2 = Pubkey::new_rand();
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
let instructions =
|
let instructions =
|
||||||
SystemInstruction::new_transfer_many(&mint_keypair.pubkey(), &[(key1, 1), (key2, 1)]);
|
system_instruction::transfer_many(&mint_keypair.pubkey(), &[(key1, 1), (key2, 1)]);
|
||||||
let tx = Transaction::new_signed_instructions(
|
let tx = Transaction::new_signed_instructions(
|
||||||
&[&mint_keypair],
|
&[&mint_keypair],
|
||||||
instructions,
|
instructions,
|
||||||
|
@ -1098,7 +1098,7 @@ mod tests {
|
||||||
let dest = Keypair::new();
|
let dest = Keypair::new();
|
||||||
|
|
||||||
// source with 0 program context
|
// source with 0 program context
|
||||||
let tx = SystemTransaction::new_user_account(
|
let tx = system_transaction::create_user_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&dest.pubkey(),
|
&dest.pubkey(),
|
||||||
2,
|
2,
|
||||||
|
@ -1217,13 +1217,8 @@ mod tests {
|
||||||
let key1 = Keypair::new();
|
let key1 = Keypair::new();
|
||||||
let key2 = Keypair::new();
|
let key2 = Keypair::new();
|
||||||
|
|
||||||
let tx = SystemTransaction::new_transfer(
|
let tx =
|
||||||
&mint_keypair,
|
system_transaction::transfer(&mint_keypair, &key1.pubkey(), 2, genesis_block.hash(), 0);
|
||||||
&key1.pubkey(),
|
|
||||||
2,
|
|
||||||
genesis_block.hash(),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
let initial_balance = bank.get_balance(&leader);
|
let initial_balance = bank.get_balance(&leader);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
assert_eq!(bank.get_balance(&leader), initial_balance + 3);
|
assert_eq!(bank.get_balance(&leader), initial_balance + 3);
|
||||||
|
@ -1231,7 +1226,7 @@ mod tests {
|
||||||
assert_eq!(bank.get_balance(&mint_keypair.pubkey()), 100 - 5 - 3);
|
assert_eq!(bank.get_balance(&mint_keypair.pubkey()), 100 - 5 - 3);
|
||||||
|
|
||||||
bank.fee_calculator.lamports_per_signature = 1;
|
bank.fee_calculator.lamports_per_signature = 1;
|
||||||
let tx = SystemTransaction::new_transfer(&key1, &key2.pubkey(), 1, genesis_block.hash(), 0);
|
let tx = system_transaction::transfer(&key1, &key2.pubkey(), 1, genesis_block.hash(), 0);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
assert_eq!(bank.get_balance(&leader), initial_balance + 4);
|
assert_eq!(bank.get_balance(&leader), initial_balance + 4);
|
||||||
assert_eq!(bank.get_balance(&key1.pubkey()), 0);
|
assert_eq!(bank.get_balance(&key1.pubkey()), 0);
|
||||||
|
@ -1246,20 +1241,10 @@ mod tests {
|
||||||
let mut bank = Bank::new(&genesis_block);
|
let mut bank = Bank::new(&genesis_block);
|
||||||
|
|
||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
let tx1 = SystemTransaction::new_transfer(
|
let tx1 =
|
||||||
&mint_keypair,
|
system_transaction::transfer(&mint_keypair, &key.pubkey(), 2, genesis_block.hash(), 0);
|
||||||
&key.pubkey(),
|
let tx2 =
|
||||||
2,
|
system_transaction::transfer(&mint_keypair, &key.pubkey(), 5, genesis_block.hash(), 0);
|
||||||
genesis_block.hash(),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
let tx2 = SystemTransaction::new_transfer(
|
|
||||||
&mint_keypair,
|
|
||||||
&key.pubkey(),
|
|
||||||
5,
|
|
||||||
genesis_block.hash(),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
|
|
||||||
let results = vec![
|
let results = vec![
|
||||||
Ok(()),
|
Ok(()),
|
||||||
|
@ -1282,14 +1267,14 @@ 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 = SystemTransaction::new_user_account(
|
let tx0 = system_transaction::create_user_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
2,
|
2,
|
||||||
genesis_block.hash(),
|
genesis_block.hash(),
|
||||||
0,
|
0,
|
||||||
);
|
);
|
||||||
let tx1 = SystemTransaction::new_user_account(
|
let tx1 = system_transaction::create_user_account(
|
||||||
&keypair,
|
&keypair,
|
||||||
&mint_keypair.pubkey(),
|
&mint_keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -1322,7 +1307,7 @@ mod tests {
|
||||||
let alice = Keypair::new();
|
let alice = Keypair::new();
|
||||||
let bob = Keypair::new();
|
let bob = Keypair::new();
|
||||||
|
|
||||||
let tx1 = SystemTransaction::new_user_account(
|
let tx1 = system_transaction::create_user_account(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&alice.pubkey(),
|
&alice.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -1362,7 +1347,7 @@ mod tests {
|
||||||
let keypair = Keypair::new();
|
let keypair = Keypair::new();
|
||||||
let bank = Bank::new(&genesis_block);
|
let bank = Bank::new(&genesis_block);
|
||||||
|
|
||||||
let tx = SystemTransaction::new_transfer(
|
let tx = system_transaction::transfer(
|
||||||
&mint_keypair,
|
&mint_keypair,
|
||||||
&keypair.pubkey(),
|
&keypair.pubkey(),
|
||||||
1,
|
1,
|
||||||
|
@ -1393,7 +1378,7 @@ mod tests {
|
||||||
|
|
||||||
bank.transfer(1, &mint_keypair, &key1.pubkey()).unwrap();
|
bank.transfer(1, &mint_keypair, &key1.pubkey()).unwrap();
|
||||||
assert_eq!(bank.get_balance(&key1.pubkey()), 1);
|
assert_eq!(bank.get_balance(&key1.pubkey()), 1);
|
||||||
let tx = SystemTransaction::new_transfer(&key1, &key1.pubkey(), 1, genesis_block.hash(), 0);
|
let tx = system_transaction::transfer(&key1, &key1.pubkey(), 1, genesis_block.hash(), 0);
|
||||||
let res = bank.process_transactions(&vec![tx.clone()]);
|
let res = bank.process_transactions(&vec![tx.clone()]);
|
||||||
assert_eq!(res.len(), 1);
|
assert_eq!(res.len(), 1);
|
||||||
assert_eq!(bank.get_balance(&key1.pubkey()), 1);
|
assert_eq!(bank.get_balance(&key1.pubkey()), 1);
|
||||||
|
@ -1427,13 +1412,8 @@ mod tests {
|
||||||
let key1 = Keypair::new();
|
let key1 = Keypair::new();
|
||||||
let parent = Arc::new(Bank::new(&genesis_block));
|
let parent = Arc::new(Bank::new(&genesis_block));
|
||||||
|
|
||||||
let tx = SystemTransaction::new_transfer(
|
let tx =
|
||||||
&mint_keypair,
|
system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0);
|
||||||
&key1.pubkey(),
|
|
||||||
1,
|
|
||||||
genesis_block.hash(),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
assert_eq!(parent.process_transaction(&tx), Ok(()));
|
assert_eq!(parent.process_transaction(&tx), Ok(()));
|
||||||
let bank = new_from_parent(&parent);
|
let bank = new_from_parent(&parent);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -1450,16 +1430,11 @@ mod tests {
|
||||||
let key2 = Keypair::new();
|
let key2 = Keypair::new();
|
||||||
let parent = Arc::new(Bank::new(&genesis_block));
|
let parent = Arc::new(Bank::new(&genesis_block));
|
||||||
|
|
||||||
let tx = SystemTransaction::new_transfer(
|
let tx =
|
||||||
&mint_keypair,
|
system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0);
|
||||||
&key1.pubkey(),
|
|
||||||
1,
|
|
||||||
genesis_block.hash(),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
assert_eq!(parent.process_transaction(&tx), Ok(()));
|
assert_eq!(parent.process_transaction(&tx), Ok(()));
|
||||||
let bank = new_from_parent(&parent);
|
let bank = new_from_parent(&parent);
|
||||||
let tx = SystemTransaction::new_transfer(&key1, &key2.pubkey(), 1, genesis_block.hash(), 0);
|
let tx = system_transaction::transfer(&key1, &key2.pubkey(), 1, genesis_block.hash(), 0);
|
||||||
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
assert_eq!(bank.process_transaction(&tx), Ok(()));
|
||||||
assert_eq!(parent.get_signature_status(&tx.signatures[0]), None);
|
assert_eq!(parent.get_signature_status(&tx.signatures[0]), None);
|
||||||
}
|
}
|
||||||
|
@ -1516,13 +1491,8 @@ mod tests {
|
||||||
let key2 = Keypair::new();
|
let key2 = Keypair::new();
|
||||||
let parent = Arc::new(Bank::new(&genesis_block));
|
let parent = Arc::new(Bank::new(&genesis_block));
|
||||||
|
|
||||||
let tx_move_mint_to_1 = SystemTransaction::new_transfer(
|
let tx_move_mint_to_1 =
|
||||||
&mint_keypair,
|
system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0);
|
||||||
&key1.pubkey(),
|
|
||||||
1,
|
|
||||||
genesis_block.hash(),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
trace!("parent process tx ");
|
trace!("parent process tx ");
|
||||||
assert_eq!(parent.process_transaction(&tx_move_mint_to_1), Ok(()));
|
assert_eq!(parent.process_transaction(&tx_move_mint_to_1), Ok(()));
|
||||||
trace!("done parent process tx ");
|
trace!("done parent process tx ");
|
||||||
|
@ -1542,7 +1512,7 @@ mod tests {
|
||||||
|
|
||||||
assert_eq!(bank.transaction_count(), parent.transaction_count());
|
assert_eq!(bank.transaction_count(), parent.transaction_count());
|
||||||
let tx_move_1_to_2 =
|
let tx_move_1_to_2 =
|
||||||
SystemTransaction::new_transfer(&key1, &key2.pubkey(), 1, genesis_block.hash(), 0);
|
system_transaction::transfer(&key1, &key2.pubkey(), 1, genesis_block.hash(), 0);
|
||||||
assert_eq!(bank.process_transaction(&tx_move_1_to_2), Ok(()));
|
assert_eq!(bank.process_transaction(&tx_move_1_to_2), Ok(()));
|
||||||
assert_eq!(bank.transaction_count(), 2);
|
assert_eq!(bank.transaction_count(), 2);
|
||||||
assert_eq!(parent.transaction_count(), 1);
|
assert_eq!(parent.transaction_count(), 1);
|
||||||
|
@ -1660,7 +1630,7 @@ mod tests {
|
||||||
let key = Keypair::new();
|
let key = Keypair::new();
|
||||||
|
|
||||||
let mut move_instruction =
|
let mut move_instruction =
|
||||||
SystemInstruction::new_transfer(&mint_keypair.pubkey(), &key.pubkey(), 0);
|
system_instruction::transfer(&mint_keypair.pubkey(), &key.pubkey(), 0);
|
||||||
move_instruction.accounts[0].is_signer = false;
|
move_instruction.accounts[0].is_signer = false;
|
||||||
|
|
||||||
let tx = Transaction::new_signed_instructions(
|
let tx = Transaction::new_signed_instructions(
|
||||||
|
@ -1741,13 +1711,8 @@ mod tests {
|
||||||
let (genesis_block, mint_keypair) = GenesisBlock::new(500);
|
let (genesis_block, mint_keypair) = GenesisBlock::new(500);
|
||||||
let bank = Arc::new(Bank::new(&genesis_block));
|
let bank = Arc::new(Bank::new(&genesis_block));
|
||||||
let key1 = Keypair::new();
|
let key1 = Keypair::new();
|
||||||
let tx_move_mint_to_1 = SystemTransaction::new_transfer(
|
let tx_move_mint_to_1 =
|
||||||
&mint_keypair,
|
system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0);
|
||||||
&key1.pubkey(),
|
|
||||||
1,
|
|
||||||
genesis_block.hash(),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
assert_eq!(bank.process_transaction(&tx_move_mint_to_1), Ok(()));
|
assert_eq!(bank.process_transaction(&tx_move_mint_to_1), Ok(()));
|
||||||
assert_eq!(bank.is_delta.load(Ordering::Relaxed), true);
|
assert_eq!(bank.is_delta.load(Ordering::Relaxed), true);
|
||||||
}
|
}
|
||||||
|
@ -1760,13 +1725,8 @@ mod tests {
|
||||||
assert_eq!(bank.is_votable(), false);
|
assert_eq!(bank.is_votable(), false);
|
||||||
|
|
||||||
// Set is_delta to true
|
// Set is_delta to true
|
||||||
let tx_move_mint_to_1 = SystemTransaction::new_transfer(
|
let tx_move_mint_to_1 =
|
||||||
&mint_keypair,
|
system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0);
|
||||||
&key1.pubkey(),
|
|
||||||
1,
|
|
||||||
genesis_block.hash(),
|
|
||||||
0,
|
|
||||||
);
|
|
||||||
assert_eq!(bank.process_transaction(&tx_move_mint_to_1), Ok(()));
|
assert_eq!(bank.process_transaction(&tx_move_mint_to_1), Ok(()));
|
||||||
assert_eq!(bank.is_votable(), false);
|
assert_eq!(bank.is_votable(), false);
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ use solana_sdk::instruction::Instruction;
|
||||||
use solana_sdk::message::Message;
|
use solana_sdk::message::Message;
|
||||||
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_instruction::SystemInstruction;
|
use solana_sdk::system_instruction;
|
||||||
use solana_sdk::transaction::{Transaction, TransactionError};
|
use solana_sdk::transaction::{Transaction, TransactionError};
|
||||||
|
|
||||||
pub struct BankClient<'a> {
|
pub struct BankClient<'a> {
|
||||||
|
@ -42,7 +42,7 @@ impl<'a> BankClient<'a> {
|
||||||
keypair: &Keypair,
|
keypair: &Keypair,
|
||||||
pubkey: &Pubkey,
|
pubkey: &Pubkey,
|
||||||
) -> Result<(), TransactionError> {
|
) -> Result<(), TransactionError> {
|
||||||
let move_instruction = SystemInstruction::new_transfer(&keypair.pubkey(), pubkey, lamports);
|
let move_instruction = system_instruction::transfer(&keypair.pubkey(), pubkey, lamports);
|
||||||
self.process_instruction(keypair, move_instruction)
|
self.process_instruction(keypair, move_instruction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ mod tests {
|
||||||
|
|
||||||
// Create 2-2 Multisig Transfer instruction.
|
// Create 2-2 Multisig Transfer instruction.
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let mut move_instruction = SystemInstruction::new_transfer(&john_pubkey, &bob_pubkey, 42);
|
let mut move_instruction = system_instruction::transfer(&john_pubkey, &bob_pubkey, 42);
|
||||||
move_instruction
|
move_instruction
|
||||||
.accounts
|
.accounts
|
||||||
.push(AccountMeta::new(jane_pubkey, true));
|
.push(AccountMeta::new(jane_pubkey, true));
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use crate::bank_client::BankClient;
|
use crate::bank_client::BankClient;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use solana_sdk::instruction::{AccountMeta, Instruction};
|
use solana_sdk::instruction::{AccountMeta, Instruction};
|
||||||
use solana_sdk::loader_instruction::LoaderInstruction;
|
use solana_sdk::loader_instruction;
|
||||||
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_instruction::SystemInstruction;
|
use solana_sdk::system_instruction;
|
||||||
|
|
||||||
pub fn load_program(
|
pub fn load_program(
|
||||||
bank_client: &BankClient,
|
bank_client: &BankClient,
|
||||||
|
@ -15,7 +15,7 @@ pub fn load_program(
|
||||||
let program_keypair = Keypair::new();
|
let program_keypair = Keypair::new();
|
||||||
let program_pubkey = program_keypair.pubkey();
|
let program_pubkey = program_keypair.pubkey();
|
||||||
|
|
||||||
let instruction = SystemInstruction::new_account(
|
let instruction = system_instruction::create_account(
|
||||||
&from_keypair.pubkey(),
|
&from_keypair.pubkey(),
|
||||||
&program_pubkey,
|
&program_pubkey,
|
||||||
1,
|
1,
|
||||||
|
@ -30,14 +30,14 @@ pub fn load_program(
|
||||||
let mut offset = 0;
|
let mut offset = 0;
|
||||||
for chunk in program.chunks(chunk_size) {
|
for chunk in program.chunks(chunk_size) {
|
||||||
let instruction =
|
let instruction =
|
||||||
LoaderInstruction::new_write(&program_pubkey, loader_id, offset, chunk.to_vec());
|
loader_instruction::write(&program_pubkey, loader_id, offset, chunk.to_vec());
|
||||||
bank_client
|
bank_client
|
||||||
.process_instruction(&program_keypair, instruction)
|
.process_instruction(&program_keypair, instruction)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
offset += chunk_size as u32;
|
offset += chunk_size as u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
let instruction = LoaderInstruction::new_finalize(&program_pubkey, loader_id);
|
let instruction = loader_instruction::finalize(&program_pubkey, loader_id);
|
||||||
bank_client
|
bank_client
|
||||||
.process_instruction(&program_keypair, instruction)
|
.process_instruction(&program_keypair, instruction)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -110,7 +110,6 @@ mod tests {
|
||||||
use solana_sdk::genesis_block::GenesisBlock;
|
use solana_sdk::genesis_block::GenesisBlock;
|
||||||
use solana_sdk::instruction::{AccountMeta, Instruction, InstructionError};
|
use solana_sdk::instruction::{AccountMeta, Instruction, InstructionError};
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil};
|
use solana_sdk::signature::{Keypair, KeypairUtil};
|
||||||
use solana_sdk::system_instruction::SystemInstruction;
|
|
||||||
use solana_sdk::system_program;
|
use solana_sdk::system_program;
|
||||||
use solana_sdk::transaction::TransactionError;
|
use solana_sdk::transaction::TransactionError;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ impl FeeCalculator {
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::pubkey::Pubkey;
|
use crate::pubkey::Pubkey;
|
||||||
use crate::system_instruction::SystemInstruction;
|
use crate::system_instruction;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fee_calculator_calculate_fee() {
|
fn test_fee_calculator_calculate_fee() {
|
||||||
|
@ -35,13 +35,13 @@ mod tests {
|
||||||
// One signature, a fee.
|
// One signature, a fee.
|
||||||
let pubkey0 = Pubkey::new(&[0; 32]);
|
let pubkey0 = Pubkey::new(&[0; 32]);
|
||||||
let pubkey1 = Pubkey::new(&[1; 32]);
|
let pubkey1 = Pubkey::new(&[1; 32]);
|
||||||
let ix0 = SystemInstruction::new_transfer(&pubkey0, &pubkey1, 1);
|
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
||||||
let message = Message::new(vec![ix0]);
|
let message = Message::new(vec![ix0]);
|
||||||
assert_eq!(FeeCalculator::new(2).calculate_fee(&message), 2);
|
assert_eq!(FeeCalculator::new(2).calculate_fee(&message), 2);
|
||||||
|
|
||||||
// Two signatures, double the fee.
|
// Two signatures, double the fee.
|
||||||
let ix0 = SystemInstruction::new_transfer(&pubkey0, &pubkey1, 1);
|
let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1);
|
||||||
let ix1 = SystemInstruction::new_transfer(&pubkey1, &pubkey0, 1);
|
let ix1 = system_instruction::transfer(&pubkey1, &pubkey0, 1);
|
||||||
let message = Message::new(vec![ix0, ix1]);
|
let message = Message::new(vec![ix0, ix1]);
|
||||||
assert_eq!(FeeCalculator::new(2).calculate_fee(&message), 4);
|
assert_eq!(FeeCalculator::new(2).calculate_fee(&message), 4);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,23 +20,16 @@ pub enum LoaderInstruction {
|
||||||
Finalize,
|
Finalize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LoaderInstruction {
|
pub fn write(account_id: &Pubkey, program_id: &Pubkey, offset: u32, bytes: Vec<u8>) -> Instruction {
|
||||||
pub fn new_write(
|
let account_metas = vec![AccountMeta::new(*account_id, true)];
|
||||||
account_id: &Pubkey,
|
Instruction::new(
|
||||||
program_id: &Pubkey,
|
*program_id,
|
||||||
offset: u32,
|
&LoaderInstruction::Write { offset, bytes },
|
||||||
bytes: Vec<u8>,
|
account_metas,
|
||||||
) -> Instruction {
|
)
|
||||||
let account_metas = vec![AccountMeta::new(*account_id, true)];
|
}
|
||||||
Instruction::new(
|
|
||||||
*program_id,
|
pub fn finalize(account_id: &Pubkey, program_id: &Pubkey) -> Instruction {
|
||||||
&LoaderInstruction::Write { offset, bytes },
|
let account_metas = vec![AccountMeta::new(*account_id, true)];
|
||||||
account_metas,
|
Instruction::new(*program_id, &LoaderInstruction::Finalize, account_metas)
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_finalize(account_id: &Pubkey, program_id: &Pubkey) -> Instruction {
|
|
||||||
let account_metas = vec![AccountMeta::new(*account_id, true)];
|
|
||||||
Instruction::new(*program_id, &LoaderInstruction::Finalize, account_metas)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,65 +31,63 @@ pub enum SystemInstruction {
|
||||||
Transfer { lamports: u64 },
|
Transfer { lamports: u64 },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SystemInstruction {
|
pub fn create_account(
|
||||||
pub fn new_account(
|
from_id: &Pubkey,
|
||||||
from_id: &Pubkey,
|
to_id: &Pubkey,
|
||||||
to_id: &Pubkey,
|
lamports: u64,
|
||||||
lamports: u64,
|
space: u64,
|
||||||
space: u64,
|
program_id: &Pubkey,
|
||||||
program_id: &Pubkey,
|
) -> Instruction {
|
||||||
) -> Instruction {
|
let account_metas = vec![
|
||||||
let account_metas = vec![
|
AccountMeta::new(*from_id, true),
|
||||||
AccountMeta::new(*from_id, true),
|
AccountMeta::new(*to_id, false),
|
||||||
AccountMeta::new(*to_id, false),
|
];
|
||||||
];
|
Instruction::new(
|
||||||
Instruction::new(
|
system_program::id(),
|
||||||
system_program::id(),
|
&SystemInstruction::CreateAccount {
|
||||||
&SystemInstruction::CreateAccount {
|
lamports,
|
||||||
lamports,
|
space,
|
||||||
space,
|
program_id: *program_id,
|
||||||
program_id: *program_id,
|
},
|
||||||
},
|
account_metas,
|
||||||
account_metas,
|
)
|
||||||
)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Create and sign a transaction to create a system account
|
/// Create and sign a transaction to create a system account
|
||||||
pub fn new_user_account(from_id: &Pubkey, to_id: &Pubkey, lamports: u64) -> Instruction {
|
pub fn create_user_account(from_id: &Pubkey, to_id: &Pubkey, lamports: u64) -> Instruction {
|
||||||
let program_id = system_program::id();
|
let program_id = system_program::id();
|
||||||
Self::new_account(from_id, to_id, lamports, 0, &program_id)
|
create_account(from_id, to_id, lamports, 0, &program_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_assign(from_id: &Pubkey, program_id: &Pubkey) -> Instruction {
|
pub fn assign(from_id: &Pubkey, program_id: &Pubkey) -> Instruction {
|
||||||
let account_metas = vec![AccountMeta::new(*from_id, true)];
|
let account_metas = vec![AccountMeta::new(*from_id, true)];
|
||||||
Instruction::new(
|
Instruction::new(
|
||||||
system_program::id(),
|
system_program::id(),
|
||||||
&SystemInstruction::Assign {
|
&SystemInstruction::Assign {
|
||||||
program_id: *program_id,
|
program_id: *program_id,
|
||||||
},
|
},
|
||||||
account_metas,
|
account_metas,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_transfer(from_id: &Pubkey, to_id: &Pubkey, lamports: u64) -> Instruction {
|
pub fn transfer(from_id: &Pubkey, to_id: &Pubkey, lamports: u64) -> Instruction {
|
||||||
let account_metas = vec![
|
let account_metas = vec![
|
||||||
AccountMeta::new(*from_id, true),
|
AccountMeta::new(*from_id, true),
|
||||||
AccountMeta::new(*to_id, false),
|
AccountMeta::new(*to_id, false),
|
||||||
];
|
];
|
||||||
Instruction::new(
|
Instruction::new(
|
||||||
system_program::id(),
|
system_program::id(),
|
||||||
&SystemInstruction::Transfer { lamports },
|
&SystemInstruction::Transfer { lamports },
|
||||||
account_metas,
|
account_metas,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create and sign new SystemInstruction::Transfer transaction to many destinations
|
/// Create and sign new SystemInstruction::Transfer transaction to many destinations
|
||||||
pub fn new_transfer_many(from_id: &Pubkey, to_lamports: &[(Pubkey, u64)]) -> Vec<Instruction> {
|
pub fn transfer_many(from_id: &Pubkey, to_lamports: &[(Pubkey, u64)]) -> Vec<Instruction> {
|
||||||
to_lamports
|
to_lamports
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(to_id, lamports)| SystemInstruction::new_transfer(from_id, to_id, *lamports))
|
.map(|(to_id, lamports)| transfer(from_id, to_id, *lamports))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -107,7 +105,7 @@ mod tests {
|
||||||
let carol_pubkey = Pubkey::new_rand();
|
let carol_pubkey = Pubkey::new_rand();
|
||||||
let to_lamports = vec![(bob_pubkey, 1), (carol_pubkey, 2)];
|
let to_lamports = vec![(bob_pubkey, 1), (carol_pubkey, 2)];
|
||||||
|
|
||||||
let instructions = SystemInstruction::new_transfer_many(&alice_pubkey, &to_lamports);
|
let instructions = transfer_many(&alice_pubkey, &to_lamports);
|
||||||
assert_eq!(instructions.len(), 2);
|
assert_eq!(instructions.len(), 2);
|
||||||
assert_eq!(get_keys(&instructions[0]), vec![alice_pubkey, bob_pubkey]);
|
assert_eq!(get_keys(&instructions[0]), vec![alice_pubkey, bob_pubkey]);
|
||||||
assert_eq!(get_keys(&instructions[1]), vec![alice_pubkey, carol_pubkey]);
|
assert_eq!(get_keys(&instructions[1]), vec![alice_pubkey, carol_pubkey]);
|
||||||
|
|
|
@ -3,74 +3,70 @@
|
||||||
use crate::hash::Hash;
|
use crate::hash::Hash;
|
||||||
use crate::pubkey::Pubkey;
|
use crate::pubkey::Pubkey;
|
||||||
use crate::signature::{Keypair, KeypairUtil};
|
use crate::signature::{Keypair, KeypairUtil};
|
||||||
use crate::system_instruction::SystemInstruction;
|
use crate::system_instruction;
|
||||||
use crate::system_program;
|
use crate::system_program;
|
||||||
use crate::transaction::Transaction;
|
use crate::transaction::Transaction;
|
||||||
|
|
||||||
pub struct SystemTransaction {}
|
/// Create and sign new SystemInstruction::CreateAccount transaction
|
||||||
|
pub fn create_account(
|
||||||
impl SystemTransaction {
|
from_keypair: &Keypair,
|
||||||
/// Create and sign new SystemInstruction::CreateAccount transaction
|
to: &Pubkey,
|
||||||
pub fn new_account(
|
recent_blockhash: Hash,
|
||||||
from_keypair: &Keypair,
|
lamports: u64,
|
||||||
to: &Pubkey,
|
space: u64,
|
||||||
recent_blockhash: Hash,
|
program_id: &Pubkey,
|
||||||
lamports: u64,
|
_fee: u64,
|
||||||
space: u64,
|
) -> Transaction {
|
||||||
program_id: &Pubkey,
|
let from_pubkey = from_keypair.pubkey();
|
||||||
_fee: u64,
|
let create_instruction =
|
||||||
) -> Transaction {
|
system_instruction::create_account(&from_pubkey, to, lamports, space, program_id);
|
||||||
let from_pubkey = from_keypair.pubkey();
|
let instructions = vec![create_instruction];
|
||||||
let create_instruction =
|
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
|
||||||
SystemInstruction::new_account(&from_pubkey, to, lamports, space, program_id);
|
}
|
||||||
let instructions = vec![create_instruction];
|
|
||||||
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
|
/// Create and sign a transaction to create a system account
|
||||||
}
|
pub fn create_user_account(
|
||||||
|
from_keypair: &Keypair,
|
||||||
/// Create and sign a transaction to create a system account
|
to: &Pubkey,
|
||||||
pub fn new_user_account(
|
lamports: u64,
|
||||||
from_keypair: &Keypair,
|
recent_blockhash: Hash,
|
||||||
to: &Pubkey,
|
fee: u64,
|
||||||
lamports: u64,
|
) -> Transaction {
|
||||||
recent_blockhash: Hash,
|
let program_id = system_program::id();
|
||||||
fee: u64,
|
create_account(
|
||||||
) -> Transaction {
|
from_keypair,
|
||||||
let program_id = system_program::id();
|
to,
|
||||||
Self::new_account(
|
recent_blockhash,
|
||||||
from_keypair,
|
lamports,
|
||||||
to,
|
0,
|
||||||
recent_blockhash,
|
&program_id,
|
||||||
lamports,
|
fee,
|
||||||
0,
|
)
|
||||||
&program_id,
|
}
|
||||||
fee,
|
|
||||||
)
|
/// Create and sign new system_instruction::Assign transaction
|
||||||
}
|
pub fn assign(
|
||||||
|
from_keypair: &Keypair,
|
||||||
/// Create and sign new SystemInstruction::Assign transaction
|
recent_blockhash: Hash,
|
||||||
pub fn new_assign(
|
program_id: &Pubkey,
|
||||||
from_keypair: &Keypair,
|
_fee: u64,
|
||||||
recent_blockhash: Hash,
|
) -> Transaction {
|
||||||
program_id: &Pubkey,
|
let from_pubkey = from_keypair.pubkey();
|
||||||
_fee: u64,
|
let assign_instruction = system_instruction::assign(&from_pubkey, program_id);
|
||||||
) -> Transaction {
|
let instructions = vec![assign_instruction];
|
||||||
let from_pubkey = from_keypair.pubkey();
|
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
|
||||||
let assign_instruction = SystemInstruction::new_assign(&from_pubkey, program_id);
|
}
|
||||||
let instructions = vec![assign_instruction];
|
|
||||||
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
|
/// Create and sign new system_instruction::Transfer transaction
|
||||||
}
|
pub fn transfer(
|
||||||
|
from_keypair: &Keypair,
|
||||||
/// Create and sign new SystemInstruction::Transfer transaction
|
to: &Pubkey,
|
||||||
pub fn new_transfer(
|
lamports: u64,
|
||||||
from_keypair: &Keypair,
|
recent_blockhash: Hash,
|
||||||
to: &Pubkey,
|
_fee: u64,
|
||||||
lamports: u64,
|
) -> Transaction {
|
||||||
recent_blockhash: Hash,
|
let from_pubkey = from_keypair.pubkey();
|
||||||
_fee: u64,
|
let move_instruction = system_instruction::transfer(&from_pubkey, to, lamports);
|
||||||
) -> Transaction {
|
let instructions = vec![move_instruction];
|
||||||
let from_pubkey = from_keypair.pubkey();
|
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
|
||||||
let move_instruction = SystemInstruction::new_transfer(&from_pubkey, to, lamports);
|
|
||||||
let instructions = vec![move_instruction];
|
|
||||||
Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,7 +200,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::instruction::AccountMeta;
|
use crate::instruction::AccountMeta;
|
||||||
use crate::signature::Keypair;
|
use crate::signature::Keypair;
|
||||||
use crate::system_instruction::SystemInstruction;
|
use crate::system_instruction;
|
||||||
use bincode::{deserialize, serialize, serialized_size};
|
use bincode::{deserialize, serialize, serialized_size};
|
||||||
use std::mem::size_of;
|
use std::mem::size_of;
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ mod tests {
|
||||||
let alice_keypair = Keypair::new();
|
let alice_keypair = Keypair::new();
|
||||||
let alice_pubkey = alice_keypair.pubkey();
|
let alice_pubkey = alice_keypair.pubkey();
|
||||||
let bob_pubkey = Pubkey::new_rand();
|
let bob_pubkey = Pubkey::new_rand();
|
||||||
let ix = SystemInstruction::new_transfer(&alice_pubkey, &bob_pubkey, 42);
|
let ix = system_instruction::transfer(&alice_pubkey, &bob_pubkey, 42);
|
||||||
|
|
||||||
let expected_data_size = size_of::<u32>() + size_of::<u64>();
|
let expected_data_size = size_of::<u32>() + size_of::<u64>();
|
||||||
assert_eq!(expected_data_size, 12);
|
assert_eq!(expected_data_size, 12);
|
||||||
|
|
|
@ -10,7 +10,7 @@ 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_instruction::SystemInstruction;
|
use solana_sdk::system_instruction::SystemInstruction;
|
||||||
use solana_sdk::system_transaction::SystemTransaction;
|
use solana_sdk::system_transaction;
|
||||||
use solana_vote_api::vote_instruction::VoteInstruction;
|
use solana_vote_api::vote_instruction::VoteInstruction;
|
||||||
use solana_vote_api::vote_state::VoteState;
|
use solana_vote_api::vote_state::VoteState;
|
||||||
use std::fs::remove_dir_all;
|
use std::fs::remove_dir_all;
|
||||||
|
@ -32,7 +32,7 @@ pub fn transfer(
|
||||||
to,
|
to,
|
||||||
blockhash
|
blockhash
|
||||||
);
|
);
|
||||||
let transaction = SystemTransaction::new_user_account(keypair, to, lamports, *blockhash, 0);
|
let transaction = system_transaction::create_user_account(keypair, to, lamports, *blockhash, 0);
|
||||||
thin_client.transfer_signed(&transaction)
|
thin_client.transfer_signed(&transaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,15 +76,15 @@ fn test_bad_sig() {
|
||||||
|
|
||||||
let blockhash = client.get_recent_blockhash().unwrap();
|
let blockhash = client.get_recent_blockhash().unwrap();
|
||||||
|
|
||||||
let tx = SystemTransaction::new_user_account(&alice, &bob_pubkey, 500, blockhash, 0);
|
let tx = system_transaction::create_user_account(&alice, &bob_pubkey, 500, blockhash, 0);
|
||||||
|
|
||||||
let _sig = client.transfer_signed(&tx).unwrap();
|
let _sig = client.transfer_signed(&tx).unwrap();
|
||||||
|
|
||||||
let blockhash = client.get_recent_blockhash().unwrap();
|
let blockhash = client.get_recent_blockhash().unwrap();
|
||||||
|
|
||||||
let mut tr2 = SystemTransaction::new_user_account(&alice, &bob_pubkey, 501, blockhash, 0);
|
let mut tr2 = system_transaction::create_user_account(&alice, &bob_pubkey, 501, blockhash, 0);
|
||||||
let mut instruction2 = deserialize(tr2.data(0)).unwrap();
|
let mut instruction2 = deserialize(tr2.data(0)).unwrap();
|
||||||
if let SystemInstruction::Transfer { ref mut lamports } = instruction2 {
|
if let system_instruction::Transfer { ref mut lamports } = instruction2 {
|
||||||
*lamports = 502;
|
*lamports = 502;
|
||||||
}
|
}
|
||||||
tr2.instructions[0].data = serialize(&instruction2).unwrap();
|
tr2.instructions[0].data = serialize(&instruction2).unwrap();
|
||||||
|
@ -125,7 +125,7 @@ fn test_register_vote_account() {
|
||||||
let blockhash = client.get_recent_blockhash().unwrap();
|
let blockhash = client.get_recent_blockhash().unwrap();
|
||||||
|
|
||||||
let instructions =
|
let instructions =
|
||||||
VoteInstruction::new_account(&validator_keypair.pubkey(), &vote_account_id, 1);
|
vote_instruction::create_account(&validator_keypair.pubkey(), &vote_account_id, 1);
|
||||||
let transaction =
|
let transaction =
|
||||||
Transaction::new_signed_instructions(&[&validator_keypair], instructions, blockhash);
|
Transaction::new_signed_instructions(&[&validator_keypair], instructions, blockhash);
|
||||||
let signature = client.transfer_signed(&transaction).unwrap();
|
let signature = client.transfer_signed(&transaction).unwrap();
|
||||||
|
|
|
@ -5,7 +5,7 @@ use log::*;
|
||||||
use serde_json;
|
use serde_json;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use solana_budget_api;
|
use solana_budget_api;
|
||||||
use solana_budget_api::budget_instruction::BudgetInstruction;
|
use solana_budget_api::budget_instruction;
|
||||||
use solana_client::rpc_client::{get_rpc_request_str, RpcClient};
|
use solana_client::rpc_client::{get_rpc_request_str, RpcClient};
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
use solana_drone::drone::request_airdrop_transaction;
|
use solana_drone::drone::request_airdrop_transaction;
|
||||||
|
@ -14,13 +14,13 @@ use solana_drone::drone::DRONE_PORT;
|
||||||
use solana_drone::drone_mock::request_airdrop_transaction;
|
use solana_drone::drone_mock::request_airdrop_transaction;
|
||||||
use solana_sdk::bpf_loader;
|
use solana_sdk::bpf_loader;
|
||||||
use solana_sdk::hash::Hash;
|
use solana_sdk::hash::Hash;
|
||||||
use solana_sdk::loader_instruction::LoaderInstruction;
|
use solana_sdk::loader_instruction;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::rpc_port::DEFAULT_RPC_PORT;
|
use solana_sdk::rpc_port::DEFAULT_RPC_PORT;
|
||||||
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;
|
||||||
use solana_sdk::transaction::Transaction;
|
use solana_sdk::transaction::Transaction;
|
||||||
use solana_vote_api::vote_instruction::VoteInstruction;
|
use solana_vote_api::vote_instruction;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||||
|
@ -333,13 +333,13 @@ fn process_configure_staking(
|
||||||
let recent_blockhash = rpc_client.get_recent_blockhash()?;
|
let recent_blockhash = rpc_client.get_recent_blockhash()?;
|
||||||
let mut ixs = vec![];
|
let mut ixs = vec![];
|
||||||
if let Some(delegate_id) = delegate_option {
|
if let Some(delegate_id) = delegate_option {
|
||||||
ixs.push(VoteInstruction::new_delegate_stake(
|
ixs.push(vote_instruction::delegate_stake(
|
||||||
&config.keypair.pubkey(),
|
&config.keypair.pubkey(),
|
||||||
&delegate_id,
|
&delegate_id,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if let Some(authorized_voter_id) = authorized_voter_option {
|
if let Some(authorized_voter_id) = authorized_voter_option {
|
||||||
ixs.push(VoteInstruction::new_authorize_voter(
|
ixs.push(vote_instruction::authorize_voter(
|
||||||
&config.keypair.pubkey(),
|
&config.keypair.pubkey(),
|
||||||
&authorized_voter_id,
|
&authorized_voter_id,
|
||||||
));
|
));
|
||||||
|
@ -356,7 +356,8 @@ fn process_create_staking(
|
||||||
lamports: u64,
|
lamports: u64,
|
||||||
) -> ProcessResult {
|
) -> ProcessResult {
|
||||||
let recent_blockhash = rpc_client.get_recent_blockhash()?;
|
let recent_blockhash = rpc_client.get_recent_blockhash()?;
|
||||||
let ixs = VoteInstruction::new_account(&config.keypair.pubkey(), voting_account_id, lamports);
|
let ixs =
|
||||||
|
vote_instruction::create_account(&config.keypair.pubkey(), voting_account_id, lamports);
|
||||||
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, recent_blockhash);
|
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, recent_blockhash);
|
||||||
let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &config.keypair)?;
|
let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &config.keypair)?;
|
||||||
Ok(signature_str.to_string())
|
Ok(signature_str.to_string())
|
||||||
|
@ -390,7 +391,7 @@ fn process_deploy(
|
||||||
)
|
)
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let mut tx = SystemTransaction::new_account(
|
let mut tx = system_transaction::create_account(
|
||||||
&config.keypair,
|
&config.keypair,
|
||||||
&program_id.pubkey(),
|
&program_id.pubkey(),
|
||||||
blockhash,
|
blockhash,
|
||||||
|
@ -411,7 +412,7 @@ fn process_deploy(
|
||||||
.chunks(USERDATA_CHUNK_SIZE)
|
.chunks(USERDATA_CHUNK_SIZE)
|
||||||
.zip(0..)
|
.zip(0..)
|
||||||
.map(|(chunk, i)| {
|
.map(|(chunk, i)| {
|
||||||
let instruction = LoaderInstruction::new_write(
|
let instruction = loader_instruction::write(
|
||||||
&program_id.pubkey(),
|
&program_id.pubkey(),
|
||||||
&bpf_loader::id(),
|
&bpf_loader::id(),
|
||||||
(i * USERDATA_CHUNK_SIZE) as u32,
|
(i * USERDATA_CHUNK_SIZE) as u32,
|
||||||
|
@ -423,7 +424,7 @@ fn process_deploy(
|
||||||
rpc_client.send_and_confirm_transactions(write_transactions, &program_id)?;
|
rpc_client.send_and_confirm_transactions(write_transactions, &program_id)?;
|
||||||
|
|
||||||
trace!("Finalizing program account");
|
trace!("Finalizing program account");
|
||||||
let instruction = LoaderInstruction::new_finalize(&program_id.pubkey(), &bpf_loader::id());
|
let instruction = loader_instruction::finalize(&program_id.pubkey(), &bpf_loader::id());
|
||||||
let mut tx = Transaction::new_signed_instructions(&[&program_id], vec![instruction], blockhash);
|
let mut tx = Transaction::new_signed_instructions(&[&program_id], vec![instruction], blockhash);
|
||||||
rpc_client
|
rpc_client
|
||||||
.send_and_confirm_transaction(&mut tx, &program_id)
|
.send_and_confirm_transaction(&mut tx, &program_id)
|
||||||
|
@ -450,7 +451,7 @@ fn process_pay(
|
||||||
let blockhash = rpc_client.get_recent_blockhash()?;
|
let blockhash = rpc_client.get_recent_blockhash()?;
|
||||||
|
|
||||||
if timestamp == None && *witnesses == None {
|
if timestamp == None && *witnesses == None {
|
||||||
let mut tx = SystemTransaction::new_transfer(&config.keypair, to, lamports, blockhash, 0);
|
let mut tx = system_transaction::transfer(&config.keypair, to, lamports, blockhash, 0);
|
||||||
let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &config.keypair)?;
|
let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &config.keypair)?;
|
||||||
Ok(signature_str.to_string())
|
Ok(signature_str.to_string())
|
||||||
} else if *witnesses == None {
|
} else if *witnesses == None {
|
||||||
|
@ -463,7 +464,7 @@ fn process_pay(
|
||||||
let contract_state = Keypair::new();
|
let contract_state = Keypair::new();
|
||||||
|
|
||||||
// Initializing contract
|
// Initializing contract
|
||||||
let ixs = BudgetInstruction::new_on_date(
|
let ixs = budget_instruction::on_date(
|
||||||
&config.keypair.pubkey(),
|
&config.keypair.pubkey(),
|
||||||
to,
|
to,
|
||||||
&contract_state.pubkey(),
|
&contract_state.pubkey(),
|
||||||
|
@ -494,7 +495,7 @@ fn process_pay(
|
||||||
let contract_state = Keypair::new();
|
let contract_state = Keypair::new();
|
||||||
|
|
||||||
// Initializing contract
|
// Initializing contract
|
||||||
let ixs = BudgetInstruction::new_when_signed(
|
let ixs = budget_instruction::when_signed(
|
||||||
&config.keypair.pubkey(),
|
&config.keypair.pubkey(),
|
||||||
to,
|
to,
|
||||||
&contract_state.pubkey(),
|
&contract_state.pubkey(),
|
||||||
|
@ -517,7 +518,7 @@ fn process_pay(
|
||||||
|
|
||||||
fn process_cancel(rpc_client: &RpcClient, config: &WalletConfig, pubkey: &Pubkey) -> ProcessResult {
|
fn process_cancel(rpc_client: &RpcClient, config: &WalletConfig, pubkey: &Pubkey) -> ProcessResult {
|
||||||
let blockhash = rpc_client.get_recent_blockhash()?;
|
let blockhash = rpc_client.get_recent_blockhash()?;
|
||||||
let ix = BudgetInstruction::new_apply_signature(
|
let ix = budget_instruction::apply_signature(
|
||||||
&config.keypair.pubkey(),
|
&config.keypair.pubkey(),
|
||||||
pubkey,
|
pubkey,
|
||||||
&config.keypair.pubkey(),
|
&config.keypair.pubkey(),
|
||||||
|
@ -548,7 +549,7 @@ fn process_time_elapsed(
|
||||||
|
|
||||||
let blockhash = rpc_client.get_recent_blockhash()?;
|
let blockhash = rpc_client.get_recent_blockhash()?;
|
||||||
|
|
||||||
let ix = BudgetInstruction::new_apply_timestamp(&config.keypair.pubkey(), pubkey, to, dt);
|
let ix = budget_instruction::apply_timestamp(&config.keypair.pubkey(), pubkey, to, dt);
|
||||||
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], vec![ix], blockhash);
|
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], vec![ix], blockhash);
|
||||||
let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &config.keypair)?;
|
let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &config.keypair)?;
|
||||||
|
|
||||||
|
@ -569,7 +570,7 @@ fn process_witness(
|
||||||
}
|
}
|
||||||
|
|
||||||
let blockhash = rpc_client.get_recent_blockhash()?;
|
let blockhash = rpc_client.get_recent_blockhash()?;
|
||||||
let ix = BudgetInstruction::new_apply_signature(&config.keypair.pubkey(), pubkey, to);
|
let ix = budget_instruction::apply_signature(&config.keypair.pubkey(), pubkey, to);
|
||||||
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], vec![ix], blockhash);
|
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], vec![ix], blockhash);
|
||||||
let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &config.keypair)?;
|
let signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &config.keypair)?;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue