From 35298e01a8fd9ee41360b61f75afea37df0abe85 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Wed, 3 Apr 2019 09:45:57 -0600 Subject: [PATCH] Remove Instruction wrapper structs and name functions after enum fields --- bench-tps/src/bench.rs | 15 +- client/src/rpc_client.rs | 10 +- core/benches/banking_stage.rs | 10 +- core/benches/ledger.rs | 4 +- core/src/banking_stage.rs | 23 +- core/src/blockstream.rs | 6 +- core/src/blockstream_service.rs | 11 +- core/src/blocktree_processor.rs | 51 +++-- core/src/chacha.rs | 4 +- core/src/cluster_tests.rs | 8 +- core/src/entry.rs | 26 +-- core/src/fullnode.rs | 10 +- core/src/local_cluster.rs | 15 +- core/src/packet.rs | 4 +- core/src/replay_stage.rs | 6 +- core/src/replicator.rs | 8 +- core/src/rpc.rs | 21 +- core/src/rpc_pubsub.rs | 24 +- core/src/rpc_subscriptions.rs | 8 +- core/src/storage_stage.rs | 10 +- core/src/test_tx.rs | 12 +- core/src/voting_keypair.rs | 17 +- core/tests/rpc.rs | 4 +- core/tests/tvu.rs | 4 +- drone/src/drone.rs | 7 +- drone/src/drone_mock.rs | 4 +- drone/tests/local-drone.rs | 5 +- install/src/command.rs | 6 +- programs/budget_api/src/budget_instruction.rs | 159 +++++++------- programs/budget_api/src/budget_processor.rs | 36 ++- programs/config_api/src/config_instruction.rs | 58 +++-- programs/config_api/src/config_processor.rs | 25 +-- programs/config_api/src/lib.rs | 4 +- .../exchange_api/src/exchange_instruction.rs | 167 +++++++------- .../exchange_api/src/exchange_processor.rs | 19 +- .../exchange_api/src/exchange_transaction.rs | 205 ++++++++---------- programs/stake_api/src/stake_instruction.rs | 68 +++--- .../storage_api/src/storage_instruction.rs | 92 ++++---- programs/storage_api/src/storage_processor.rs | 36 ++- programs/vote_api/src/vote_instruction.rs | 80 ++++--- programs/vote_api/src/vote_processor.rs | 16 +- runtime/benches/bank.rs | 6 +- runtime/src/bank.rs | 108 +++------ runtime/src/bank_client.rs | 6 +- runtime/src/loader_utils.rs | 10 +- runtime/src/system_instruction_processor.rs | 1 - sdk/src/fee_calculator.rs | 8 +- sdk/src/loader_instruction.rs | 31 +-- sdk/src/system_instruction.rs | 110 +++++----- sdk/src/system_transaction.rs | 130 ++++++----- sdk/src/transaction.rs | 4 +- tests/thin_client.rs | 12 +- wallet/src/wallet.rs | 33 +-- 53 files changed, 835 insertions(+), 922 deletions(-) diff --git a/bench-tps/src/bench.rs b/bench-tps/src/bench.rs index 87beff8c4..40b2200a1 100644 --- a/bench-tps/src/bench.rs +++ b/bench-tps/src/bench.rs @@ -13,8 +13,8 @@ use solana_metrics::influxdb; use solana_sdk::hash::Hash; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::{Keypair, KeypairUtil}; -use solana_sdk::system_instruction::SystemInstruction; -use solana_sdk::system_transaction::SystemTransaction; +use solana_sdk::system_instruction; +use solana_sdk::system_transaction; use solana_sdk::timing::timestamp; use solana_sdk::timing::{duration_as_ms, duration_as_s}; use solana_sdk::transaction::Transaction; @@ -321,7 +321,7 @@ fn send_barrier_transaction( *blockhash = barrier_client.get_recent_blockhash().unwrap(); 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 .transfer_signed(&transaction) .expect("Unable to send barrier transaction"); @@ -399,7 +399,7 @@ fn generate_txs( .par_iter() .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(), ) }) @@ -551,9 +551,10 @@ fn fund_keys(client: &ThinClient, source: &Keypair, dests: &[Keypair], lamports: .map(|(k, m)| { ( k.clone(), - Transaction::new_unsigned_instructions( - SystemInstruction::new_transfer_many(&k.pubkey(), &m), - ), + Transaction::new_unsigned_instructions(system_instruction::transfer_many( + &k.pubkey(), + &m, + )), ) }) .collect(); diff --git a/client/src/rpc_client.rs b/client/src/rpc_client.rs index 970dab959..fbe67ac6f 100644 --- a/client/src/rpc_client.rs +++ b/client/src/rpc_client.rs @@ -556,7 +556,7 @@ mod tests { use serde_json::Number; use solana_logger; use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_transaction::SystemTransaction; + use solana_sdk::system_transaction; use std::sync::mpsc::channel; use std::thread; @@ -662,7 +662,7 @@ mod tests { let key = Keypair::new(); let to = Pubkey::new_rand(); 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); assert_eq!(signature.unwrap(), SIGNATURE.to_string()); @@ -713,7 +713,7 @@ mod tests { let key = Keypair::new(); let to = Pubkey::new_rand(); 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); result.unwrap(); @@ -737,8 +737,8 @@ mod tests { .into_vec() .unwrap(); let blockhash = Hash::new(&vec); - let prev_tx = SystemTransaction::new_user_account(&key, &to, 50, blockhash, 0); - let mut 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 = system_transaction::create_user_account(&key, &to, 50, blockhash, 0); rpc_client.resign_transaction(&mut tx, &key).unwrap(); diff --git a/core/benches/banking_stage.rs b/core/benches/banking_stage.rs index c70da3af6..f8a873a98 100644 --- a/core/benches/banking_stage.rs +++ b/core/benches/banking_stage.rs @@ -18,7 +18,7 @@ use solana_sdk::genesis_block::GenesisBlock; use solana_sdk::hash::hash; use solana_sdk::pubkey::Pubkey; 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 std::iter; 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 bank = Arc::new(Bank::new(&genesis_block)); - let dummy = SystemTransaction::new_transfer( + let dummy = system_transaction::transfer( &mint_keypair, &mint_keypair.pubkey(), 1, @@ -78,7 +78,7 @@ fn bench_banking_stage_multi_accounts(bencher: &mut Bencher) { .collect(); // fund all the accounts transactions.iter().for_each(|tx| { - let fund = SystemTransaction::new_transfer( + let fund = system_transaction::transfer( &mint_keypair, &tx.message.account_keys[0], 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 bank = Arc::new(Bank::new(&genesis_block)); - let dummy = SystemTransaction::new_transfer( + let dummy = system_transaction::transfer( &mint_keypair, &mint_keypair.pubkey(), 1, @@ -194,7 +194,7 @@ fn bench_banking_stage_multi_programs(bencher: &mut Bencher) { }) .collect(); transactions.iter().for_each(|tx| { - let fund = SystemTransaction::new_transfer( + let fund = system_transaction::transfer( &mint_keypair, &tx.message.account_keys[0], mint_total / txes as u64, diff --git a/core/benches/ledger.rs b/core/benches/ledger.rs index 22894c337..8814edee6 100644 --- a/core/benches/ledger.rs +++ b/core/benches/ledger.rs @@ -5,7 +5,7 @@ extern crate test; use solana::entry::{next_entries, reconstruct_entries_from_blobs, EntrySlice}; use solana_sdk::hash::{hash, Hash}; use solana_sdk::signature::{Keypair, KeypairUtil}; -use solana_sdk::system_transaction::SystemTransaction; +use solana_sdk::system_transaction; use test::Bencher; #[bench] @@ -13,7 +13,7 @@ fn bench_block_to_blobs_to_block(bencher: &mut Bencher) { let zero = Hash::default(); let one = hash(&zero.as_ref()); 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 entries = next_entries(&zero, 1, transactions); diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index b22826875..1a741362e 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -507,7 +507,7 @@ mod tests { use solana_sdk::genesis_block::GenesisBlock; use solana_sdk::instruction::InstructionError; use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_transaction::SystemTransaction; + use solana_sdk::system_transaction; use std::sync::mpsc::channel; use std::thread::sleep; @@ -593,7 +593,7 @@ mod tests { // fund another account so we can send 2 good transactions in a single batch. let keypair = Keypair::new(); - let fund_tx = SystemTransaction::new_user_account( + let fund_tx = system_transaction::create_user_account( &mint_keypair, &keypair.pubkey(), 2, @@ -604,16 +604,17 @@ mod tests { // good tx 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 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 let keypair = Keypair::new(); 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 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. let alice = Keypair::new(); - let tx = SystemTransaction::new_user_account( + let tx = system_transaction::create_user_account( &mint_keypair, &alice.pubkey(), 2, @@ -690,7 +691,7 @@ mod tests { .unwrap(); // Process a second batch that spends one of those lamports. - let tx = SystemTransaction::new_user_account( + let tx = system_transaction::create_user_account( &alice, &mint_keypair.pubkey(), 1, @@ -783,8 +784,8 @@ mod tests { let pubkey = Pubkey::new_rand(); let transactions = vec![ - SystemTransaction::new_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), + system_transaction::transfer(&mint_keypair, &pubkey, 1, genesis_block.hash(), 0), ]; let mut results = vec![Ok(()), Ok(())]; @@ -820,7 +821,7 @@ mod tests { let bank = Arc::new(Bank::new(&genesis_block)); let pubkey = Pubkey::new_rand(); - let transactions = vec![SystemTransaction::new_transfer( + let transactions = vec![system_transaction::transfer( &mint_keypair, &pubkey, 1, @@ -873,7 +874,7 @@ mod tests { assert_eq!(done, true); - let transactions = vec![SystemTransaction::new_transfer( + let transactions = vec![system_transaction::transfer( &mint_keypair, &pubkey, 2, diff --git a/core/src/blockstream.rs b/core/src/blockstream.rs index b656419ac..acfdad090 100644 --- a/core/src/blockstream.rs +++ b/core/src/blockstream.rs @@ -172,7 +172,7 @@ mod test { use serde_json::Value; use solana_sdk::hash::Hash; use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_transaction::SystemTransaction; + use solana_sdk::system_transaction; use std::collections::HashSet; #[test] @@ -184,9 +184,9 @@ mod test { let keypair0 = Keypair::new(); let keypair1 = Keypair::new(); let tx0 = - SystemTransaction::new_transfer(&keypair0, &keypair1.pubkey(), 1, Hash::default(), 0); + system_transaction::transfer(&keypair0, &keypair1.pubkey(), 1, Hash::default(), 0); 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_tx1 = serialize(&tx1).unwrap(); let entry = Entry::new(&Hash::default(), 1, vec![tx0, tx1]); diff --git a/core/src/blockstream_service.rs b/core/src/blockstream_service.rs index b5866280d..e673df668 100644 --- a/core/src/blockstream_service.rs +++ b/core/src/blockstream_service.rs @@ -115,7 +115,7 @@ mod test { use solana_sdk::genesis_block::GenesisBlock; use solana_sdk::hash::Hash; use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_transaction::SystemTransaction; + use solana_sdk::system_transaction; use std::sync::mpsc::channel; #[test] @@ -141,8 +141,13 @@ mod test { let keypair = Keypair::new(); let mut blockhash = entries[3].hash; - let tx = - SystemTransaction::new_user_account(&keypair, &keypair.pubkey(), 1, Hash::default(), 0); + let tx = system_transaction::create_user_account( + &keypair, + &keypair.pubkey(), + 1, + Hash::default(), + 0, + ); let entry = Entry::new(&mut blockhash, 1, vec![tx]); blockhash = entry.hash; entries.push(entry); diff --git a/core/src/blocktree_processor.rs b/core/src/blocktree_processor.rs index 098cd9556..80641489b 100644 --- a/core/src/blocktree_processor.rs +++ b/core/src/blocktree_processor.rs @@ -233,7 +233,7 @@ mod tests { use solana_sdk::hash::Hash; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_transaction::SystemTransaction; + use solana_sdk::system_transaction; use solana_sdk::transaction::TransactionError; fn fill_blocktree_slot_with_ticks( @@ -421,7 +421,7 @@ mod tests { let bank = Bank::new(&genesis_block); let keypair = Keypair::new(); 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, &keypair.pubkey(), 1, @@ -453,7 +453,7 @@ mod tests { for _ in 0..3 { // Transfer one token from the mint to a random account let keypair = Keypair::new(); - let tx = SystemTransaction::new_user_account( + let tx = system_transaction::create_user_account( &mint_keypair, &keypair.pubkey(), 1, @@ -467,8 +467,13 @@ mod tests { // Add a second Transaction that will produce a // InstructionError<0, ResultWithNegativeLamports> error when processed let keypair2 = Keypair::new(); - let tx = - SystemTransaction::new_user_account(&keypair, &keypair2.pubkey(), 42, blockhash, 0); + let tx = system_transaction::create_user_account( + &keypair, + &keypair2.pubkey(), + 42, + blockhash, + 0, + ); let entry = Entry::new(&last_entry_hash, 1, vec![tx]); last_entry_hash = entry.hash; entries.push(entry); @@ -545,7 +550,7 @@ mod tests { let blockhash = bank.last_blockhash(); // 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, &keypair1.pubkey(), 2, @@ -553,7 +558,7 @@ mod tests { 0, ); let entry_1 = next_entry(&blockhash, 1, vec![tx]); - let tx = SystemTransaction::new_user_account( + let tx = system_transaction::create_user_account( &mint_keypair, &keypair2.pubkey(), 2, @@ -583,7 +588,7 @@ mod tests { let entry_1_to_mint = next_entry( &bank.last_blockhash(), 1, - vec![SystemTransaction::new_user_account( + vec![system_transaction::create_user_account( &keypair1, &mint_keypair.pubkey(), 1, @@ -596,14 +601,14 @@ mod tests { &entry_1_to_mint.hash, 1, vec![ - SystemTransaction::new_user_account( + system_transaction::create_user_account( &keypair2, &keypair3.pubkey(), 2, bank.last_blockhash(), 0, ), // should be fine - SystemTransaction::new_user_account( + system_transaction::create_user_account( &keypair1, &mint_keypair.pubkey(), 2, @@ -642,14 +647,14 @@ mod tests { &bank.last_blockhash(), 1, vec![ - SystemTransaction::new_user_account( + system_transaction::create_user_account( &keypair1, &mint_keypair.pubkey(), 1, bank.last_blockhash(), 0, ), - SystemTransaction::new_transfer( + system_transaction::transfer( &keypair4, &keypair4.pubkey(), 1, @@ -663,14 +668,14 @@ mod tests { &entry_1_to_mint.hash, 1, vec![ - SystemTransaction::new_user_account( + system_transaction::create_user_account( &keypair2, &keypair3.pubkey(), 2, bank.last_blockhash(), 0, ), // should be fine - SystemTransaction::new_user_account( + system_transaction::create_user_account( &keypair1, &mint_keypair.pubkey(), 2, @@ -715,7 +720,7 @@ mod tests { let keypair4 = Keypair::new(); //load accounts - let tx = SystemTransaction::new_user_account( + let tx = system_transaction::create_user_account( &mint_keypair, &keypair1.pubkey(), 1, @@ -723,7 +728,7 @@ mod tests { 0, ); assert_eq!(bank.process_transaction(&tx), Ok(())); - let tx = SystemTransaction::new_user_account( + let tx = system_transaction::create_user_account( &mint_keypair, &keypair2.pubkey(), 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 let blockhash = bank.last_blockhash(); - let tx = SystemTransaction::new_user_account( + let tx = system_transaction::create_user_account( &keypair1, &keypair3.pubkey(), 1, @@ -742,7 +747,7 @@ mod tests { 0, ); let entry_1 = next_entry(&blockhash, 1, vec![tx]); - let tx = SystemTransaction::new_user_account( + let tx = system_transaction::create_user_account( &keypair2, &keypair4.pubkey(), 1, @@ -766,7 +771,7 @@ mod tests { let keypair4 = Keypair::new(); //load accounts - let tx = SystemTransaction::new_user_account( + let tx = system_transaction::create_user_account( &mint_keypair, &keypair1.pubkey(), 1, @@ -774,7 +779,7 @@ mod tests { 0, ); assert_eq!(bank.process_transaction(&tx), Ok(())); - let tx = SystemTransaction::new_user_account( + let tx = system_transaction::create_user_account( &mint_keypair, &keypair2.pubkey(), 1, @@ -790,10 +795,10 @@ mod tests { // ensure bank can process 2 entries that do not have a common account and tick is registered 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 tick = next_entry(&entry_1.hash, 1, vec![]); - let tx = SystemTransaction::new_user_account( + let tx = system_transaction::create_user_account( &keypair1, &keypair4.pubkey(), 1, @@ -809,7 +814,7 @@ mod tests { assert_eq!(bank.get_balance(&keypair4.pubkey()), 1); // 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, &keypair3.pubkey(), 1, diff --git a/core/src/chacha.rs b/core/src/chacha.rs index 524e13c23..8ea5c8bf8 100644 --- a/core/src/chacha.rs +++ b/core/src/chacha.rs @@ -97,7 +97,7 @@ mod tests { use ring::signature::Ed25519KeyPair; use solana_sdk::hash::{hash, Hash, Hasher}; use solana_sdk::signature::KeypairUtil; - use solana_sdk::system_transaction::SystemTransaction; + use solana_sdk::system_transaction; use std::fs::remove_file; use std::fs::File; use std::io::Read; @@ -124,7 +124,7 @@ mod tests { Entry::new_mut( &mut id, &mut num_hashes, - vec![SystemTransaction::new_user_account( + vec![system_transaction::create_user_account( &keypair, &keypair.pubkey(), 1, diff --git a/core/src/cluster_tests.rs b/core/src/cluster_tests.rs index 9bdf01ae1..6b4bed68d 100644 --- a/core/src/cluster_tests.rs +++ b/core/src/cluster_tests.rs @@ -12,7 +12,7 @@ use crate::poh_service::PohServiceConfig; use solana_client::thin_client::create_client; use solana_sdk::hash::Hash; use solana_sdk::signature::{Keypair, KeypairUtil, Signature}; -use solana_sdk::system_transaction::SystemTransaction; +use solana_sdk::system_transaction; use solana_sdk::timing::{ 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()) .expect("balance in source"); assert!(bal > 0); - let mut transaction = SystemTransaction::new_transfer( + let mut transaction = system_transaction::transfer( &funding_keypair, &random_keypair.pubkey(), 1, @@ -63,7 +63,7 @@ pub fn send_many_transactions(node: &ContactInfo, funding_keypair: &Keypair, num .poll_get_balance(&funding_keypair.pubkey()) .expect("balance in source"); assert!(bal > 0); - let mut transaction = SystemTransaction::new_transfer( + let mut transaction = system_transaction::transfer( &funding_keypair, &random_keypair.pubkey(), 1, @@ -183,7 +183,7 @@ pub fn kill_entry_and_spend_and_verify_rest( } let random_keypair = Keypair::new(); - let mut transaction = SystemTransaction::new_transfer( + let mut transaction = system_transaction::transfer( &funding_keypair, &random_keypair.pubkey(), 1, diff --git a/core/src/entry.rs b/core/src/entry.rs index a471843cb..9eb3afaa9 100644 --- a/core/src/entry.rs +++ b/core/src/entry.rs @@ -8,7 +8,7 @@ use crate::result::Result; use bincode::{deserialize, serialized_size}; use chrono::prelude::Utc; 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::signature::{Keypair, KeypairUtil}; use solana_sdk::transaction::Transaction; @@ -380,7 +380,7 @@ pub fn make_tiny_test_entries_from_hash(start: &Hash, num: usize) -> Vec let mut num_hashes = 0; (0..num) .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); Entry::new_mut(&mut hash, &mut num_hashes, vec![tx]) }) @@ -399,7 +399,7 @@ pub fn make_large_test_entries(num_entries: usize) -> Vec { let keypair = Keypair::new(); 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 serialized_size = serialized_size(&tx).unwrap(); @@ -450,31 +450,31 @@ mod tests { use crate::packet::{to_blobs, BLOB_DATA_SIZE, PACKET_DATA_SIZE}; use solana_sdk::hash::hash; use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_transaction::SystemTransaction; - use solana_vote_api::vote_instruction::{Vote, VoteInstruction}; + use solana_sdk::system_transaction; + use solana_vote_api::vote_instruction::{self, Vote}; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; fn create_sample_payment(keypair: &Keypair, hash: Hash) -> Transaction { 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) } fn create_sample_timestamp(keypair: &Keypair, hash: Hash) -> Transaction { 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) } fn create_sample_signature(keypair: &Keypair, hash: Hash) -> Transaction { 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) } fn create_sample_vote(keypair: &Keypair, hash: Hash) -> Transaction { 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) } @@ -494,8 +494,8 @@ mod tests { // First, verify entries let keypair = Keypair::new(); - let tx0 = SystemTransaction::new_user_account(&keypair, &keypair.pubkey(), 0, zero, 0); - let tx1 = SystemTransaction::new_user_account(&keypair, &keypair.pubkey(), 1, zero, 0); + let tx0 = system_transaction::create_user_account(&keypair, &keypair.pubkey(), 0, 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()]); assert!(e0.verify(&zero)); @@ -545,7 +545,7 @@ mod tests { fn test_next_entry_panic() { let zero = Hash::default(); 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]); } @@ -553,7 +553,7 @@ mod tests { fn test_serialized_size() { let zero = Hash::default(); 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()]); assert_eq!( Entry::serialized_size(&[tx]), diff --git a/core/src/fullnode.rs b/core/src/fullnode.rs index c1661178e..102279678 100644 --- a/core/src/fullnode.rs +++ b/core/src/fullnode.rs @@ -25,10 +25,10 @@ use solana_sdk::genesis_block::GenesisBlock; use solana_sdk::hash::Hash; use solana_sdk::pubkey::Pubkey; 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::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::sync::atomic::{AtomicBool, Ordering}; use std::sync::mpsc::{channel, Receiver}; @@ -318,7 +318,7 @@ pub fn make_active_set_entries( num_ending_ticks: u64, ) -> (Vec, Keypair) { // 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, &active_keypair.pubkey(), stake, @@ -332,7 +332,7 @@ pub fn make_active_set_entries( let voting_keypair = Keypair::new(); 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(), &vote_account_id, 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]); // 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 = Transaction::new_signed_instructions(&[&voting_keypair], vec![vote_ix], *blockhash); let vote_entry = next_entry_mut(&mut last_entry_hash, 1, vec![vote_tx]); diff --git a/core/src/local_cluster.rs b/core/src/local_cluster.rs index 10eadac2b..0760e4aae 100644 --- a/core/src/local_cluster.rs +++ b/core/src/local_cluster.rs @@ -11,11 +11,11 @@ use solana_client::thin_client::ThinClient; use solana_sdk::genesis_block::GenesisBlock; use solana_sdk::pubkey::Pubkey; 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_TICKS_PER_SLOT; 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 std::collections::HashMap; use std::fs::remove_dir_all; @@ -296,7 +296,7 @@ impl LocalCluster { ) -> u64 { trace!("getting leader blockhash"); let blockhash = client.get_recent_blockhash().unwrap(); - let mut tx = SystemTransaction::new_user_account( + let mut tx = system_transaction::create_user_account( &source_keypair, dest_pubkey, lamports, @@ -328,8 +328,11 @@ impl LocalCluster { // Create the vote account if necessary if client.poll_get_balance(&vote_account_pubkey).unwrap_or(0) == 0 { // 1) Create vote account - let instructions = - VoteInstruction::new_account(&from_account.pubkey(), &vote_account_pubkey, amount); + let instructions = vote_instruction::create_account( + &from_account.pubkey(), + &vote_account_pubkey, + amount, + ); let mut transaction = Transaction::new_signed_instructions( &[from_account.as_ref()], instructions, @@ -345,7 +348,7 @@ impl LocalCluster { // 2) Set delegate for new vote account 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( &[vote_account], diff --git a/core/src/packet.rs b/core/src/packet.rs index b92cf1136..2ec3bb630 100644 --- a/core/src/packet.rs +++ b/core/src/packet.rs @@ -573,7 +573,7 @@ mod tests { use rand::Rng; use solana_sdk::hash::Hash; use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_transaction::SystemTransaction; + use solana_sdk::system_transaction; use std::io; use std::io::Write; use std::net::{Ipv4Addr, SocketAddr, UdpSocket}; @@ -612,7 +612,7 @@ mod tests { fn test_to_packets() { let keypair = Keypair::new(); 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]); assert_eq!(rv.len(), 1); assert_eq!(rv[0].read().unwrap().packets.len(), 1); diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index 3e94ce4bb..b03965eab 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -21,7 +21,7 @@ use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::KeypairUtil; use solana_sdk::timing::{self, duration_as_ms}; 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::mpsc::{channel, Receiver, RecvTimeoutError, Sender}; use std::sync::{Arc, Mutex, RwLock}; @@ -296,7 +296,7 @@ impl ReplayStage { T: 'static + KeypairUtil + Send + Sync, { 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( &[voting_keypair.as_ref()], vec![vote_ix], @@ -635,7 +635,7 @@ mod test { 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( &[voting_keypair.as_ref()], vec![vote_ix], diff --git a/core/src/replicator.rs b/core/src/replicator.rs index 467f834fa..493873563 100644 --- a/core/src/replicator.rs +++ b/core/src/replicator.rs @@ -22,9 +22,9 @@ use solana_client::thin_client::{create_client, ThinClient}; use solana_drone::drone::{request_airdrop_transaction, DRONE_PORT}; use solana_sdk::hash::{Hash, Hasher}; 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_storage_api::storage_instruction::StorageInstruction; +use solana_storage_api::storage_instruction; use std::fs::File; use std::io; use std::io::BufReader; @@ -434,7 +434,7 @@ impl Replicator { { let blockhash = client.get_recent_blockhash().expect("blockhash"); //TODO the account space needs to be well defined somewhere - let tx = SystemTransaction::new_account( + let tx = system_transaction::create_account( keypair, &storage_keypair.pubkey(), blockhash, @@ -455,7 +455,7 @@ impl Replicator { ); 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.hash, self.slot, diff --git a/core/src/rpc.rs b/core/src/rpc.rs index c2cc70bff..ca1bed17c 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -454,7 +454,7 @@ mod tests { use solana_sdk::genesis_block::GenesisBlock; use solana_sdk::hash::{hash, Hash}; use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_transaction::SystemTransaction; + use solana_sdk::system_transaction; use std::thread; fn start_rpc_handler_with_tx(pubkey: &Pubkey) -> (MetaIoHandler, Meta, Hash, Keypair) { @@ -463,7 +463,7 @@ mod tests { let exit = Arc::new(AtomicBool::new(false)); 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"); let request_processor = Arc::new(RwLock::new(JsonRpcRequestProcessor::new( @@ -503,7 +503,7 @@ mod tests { ); thread::spawn(move || { 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"); }) .join() @@ -575,7 +575,7 @@ mod tests { fn test_rpc_confirm_tx() { let bob_pubkey = Pubkey::new_rand(); 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!( r#"{{"jsonrpc":"2.0","id":1,"method":"confirmTransaction","params":["{}"]}}"#, @@ -594,7 +594,7 @@ mod tests { fn test_rpc_get_signature_status() { let bob_pubkey = Pubkey::new_rand(); 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!( r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#, @@ -609,7 +609,7 @@ mod tests { assert_eq!(expected, result); // 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!( r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#, tx.signatures[0] @@ -716,13 +716,8 @@ mod tests { #[test] fn test_rpc_verify_signature() { - let tx = SystemTransaction::new_transfer( - &Keypair::new(), - &Pubkey::new_rand(), - 20, - hash(&[0]), - 0, - ); + let tx = + system_transaction::transfer(&Keypair::new(), &Pubkey::new_rand(), 20, hash(&[0]), 0); assert_eq!( verify_signature(&tx.signatures[0].to_string()).unwrap(), tx.signatures[0] diff --git a/core/src/rpc_pubsub.rs b/core/src/rpc_pubsub.rs index a6513afcf..84ba7a9c4 100644 --- a/core/src/rpc_pubsub.rs +++ b/core/src/rpc_pubsub.rs @@ -227,12 +227,12 @@ mod tests { use jsonrpc_core::Response; use jsonrpc_pubsub::{PubSubHandler, Session}; 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_sdk::genesis_block::GenesisBlock; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_transaction::SystemTransaction; + use solana_sdk::system_transaction; use solana_sdk::transaction::Transaction; use std::thread::sleep; use std::time::Duration; @@ -270,7 +270,7 @@ mod tests { let rpc = RpcSolPubSubImpl::default(); // 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 (subscriber, _id_receiver, mut receiver) = @@ -302,7 +302,7 @@ mod tests { let rpc = RpcSolPubSubImpl::default(); 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!( r#"{{"jsonrpc":"2.0","id":1,"method":"signatureSubscribe","params":["{}"]}}"#, tx.signatures[0].to_string() @@ -354,11 +354,16 @@ mod tests { let (subscriber, _id_receiver, mut receiver) = Subscriber::new_test("accountNotification"); rpc.account_subscribe(session, subscriber, contract_state.pubkey().to_string()); - let tx = - SystemTransaction::new_user_account(&alice, &contract_funds.pubkey(), 51, blockhash, 0); + let tx = system_transaction::create_user_account( + &alice, + &contract_funds.pubkey(), + 51, + blockhash, + 0, + ); 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(), &bob_pubkey, &contract_state.pubkey(), @@ -391,10 +396,11 @@ mod tests { 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(); sleep(Duration::from_millis(200)); - let ix = BudgetInstruction::new_apply_signature( + let ix = budget_instruction::apply_signature( &witness.pubkey(), &contract_state.pubkey(), &bob_pubkey, diff --git a/core/src/rpc_subscriptions.rs b/core/src/rpc_subscriptions.rs index f7be2eef2..b680c345e 100644 --- a/core/src/rpc_subscriptions.rs +++ b/core/src/rpc_subscriptions.rs @@ -202,7 +202,7 @@ mod tests { use solana_budget_api; use solana_sdk::genesis_block::GenesisBlock; use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_transaction::SystemTransaction; + use solana_sdk::system_transaction; use tokio::prelude::{Async, Stream}; #[test] @@ -211,7 +211,7 @@ mod tests { let bank = Bank::new(&genesis_block); let alice = Keypair::new(); let blockhash = bank.last_blockhash(); - let tx = SystemTransaction::new_account( + let tx = system_transaction::create_account( &mint_keypair, &alice.pubkey(), blockhash, @@ -257,7 +257,7 @@ mod tests { let bank = Bank::new(&genesis_block); let alice = Keypair::new(); let blockhash = bank.last_blockhash(); - let tx = SystemTransaction::new_account( + let tx = system_transaction::create_account( &mint_keypair, &alice.pubkey(), blockhash, @@ -302,7 +302,7 @@ mod tests { let bank = Bank::new(&genesis_block); let alice = Keypair::new(); 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]; bank.process_transaction(&tx).unwrap(); diff --git a/core/src/storage_stage.rs b/core/src/storage_stage.rs index bb75dbc04..104cb0fb9 100644 --- a/core/src/storage_stage.rs +++ b/core/src/storage_stage.rs @@ -16,9 +16,9 @@ use solana_client::thin_client::{create_client_with_timeout, ThinClient}; use solana_sdk::hash::Hash; use solana_sdk::pubkey::Pubkey; 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_storage_api::storage_instruction::StorageInstruction; +use solana_storage_api::storage_instruction::{self, StorageInstruction}; use std::collections::HashSet; use std::io; use std::mem::size_of; @@ -279,7 +279,7 @@ impl StorageStage { if let Some(account) = account_to_create { if client.get_account_data(&account).is_err() { // TODO the account space needs to be well defined somewhere - let tx = SystemTransaction::new_account( + let tx = system_transaction::create_account( keypair, &storage_keypair.pubkey(), blockhash, @@ -318,7 +318,7 @@ impl StorageStage { let mut seed = [0u8; 32]; let signature = keypair.sign(&entry_id.as_ref()); - let ix = StorageInstruction::new_advertise_recent_blockhash( + let ix = storage_instruction::advertise_recent_blockhash( &keypair.pubkey(), entry_id, entry_height, @@ -643,7 +643,7 @@ mod tests { } let keypair = Keypair::new(); - let mining_proof_ix = StorageInstruction::new_mining_proof( + let mining_proof_ix = storage_instruction::mining_proof( &keypair.pubkey(), Hash::default(), 0, diff --git a/core/src/test_tx.rs b/core/src/test_tx.rs index e4d434532..840676e9a 100644 --- a/core/src/test_tx.rs +++ b/core/src/test_tx.rs @@ -3,14 +3,14 @@ use solana_sdk::instruction::CompiledInstruction; use solana_sdk::signature::{Keypair, KeypairUtil}; use solana_sdk::system_instruction::SystemInstruction; use solana_sdk::system_program; -use solana_sdk::system_transaction::SystemTransaction; +use solana_sdk::system_transaction; use solana_sdk::transaction::Transaction; pub fn test_tx() -> Transaction { let keypair1 = Keypair::new(); let pubkey1 = keypair1.pubkey(); 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 { @@ -20,11 +20,15 @@ pub fn test_multisig_tx() -> Transaction { let lamports = 5; 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 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( &keypairs, diff --git a/core/src/voting_keypair.rs b/core/src/voting_keypair.rs index ac26b74a2..447877309 100644 --- a/core/src/voting_keypair.rs +++ b/core/src/voting_keypair.rs @@ -110,7 +110,7 @@ pub mod tests { use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::{Keypair, KeypairUtil}; use solana_sdk::transaction::Transaction; - use solana_vote_api::vote_instruction::{Vote, VoteInstruction}; + use solana_vote_api::vote_instruction::{self, Vote}; fn process_instructions(bank: &Bank, keypairs: &[&T], ixs: Vec) { let blockhash = bank.last_blockhash(); @@ -124,7 +124,7 @@ pub mod tests { bank: &Bank, 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); } @@ -137,16 +137,13 @@ pub mod tests { ) { let voting_pubkey = voting_keypair.pubkey(); let mut ixs = - VoteInstruction::new_account(&from_keypair.pubkey(), &voting_pubkey, lamports); - ixs.push(VoteInstruction::new_delegate_stake( - &voting_pubkey, - delegate, - )); + vote_instruction::create_account(&from_keypair.pubkey(), &voting_pubkey, lamports); + ixs.push(vote_instruction::delegate_stake(&voting_pubkey, delegate)); process_instructions(bank, &[from_keypair, voting_keypair], ixs); } pub fn push_vote(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]); } @@ -159,8 +156,8 @@ pub mod tests { ) { let voting_pubkey = voting_keypair.pubkey(); let mut ixs = - VoteInstruction::new_account(&from_keypair.pubkey(), &voting_pubkey, lamports); - ixs.push(VoteInstruction::new_vote(&voting_pubkey, Vote::new(slot))); + vote_instruction::create_account(&from_keypair.pubkey(), &voting_pubkey, lamports); + ixs.push(vote_instruction::vote(&voting_pubkey, Vote::new(slot))); process_instructions(bank, &[from_keypair, voting_keypair], ixs); } } diff --git a/core/tests/rpc.rs b/core/tests/rpc.rs index 0602dfada..c9161c979 100644 --- a/core/tests/rpc.rs +++ b/core/tests/rpc.rs @@ -7,7 +7,7 @@ use solana::fullnode::new_fullnode_for_tests; use solana_client::rpc_client::get_rpc_request_str; use solana_sdk::hash::Hash; use solana_sdk::pubkey::Pubkey; -use solana_sdk::system_transaction::SystemTransaction; +use solana_sdk::system_transaction; use std::fs::remove_dir_all; use std::thread::sleep; use std::time::Duration; @@ -41,7 +41,7 @@ fn test_rpc_send_tx() { let blockhash = Hash::new(&blockhash_vec); 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 client = reqwest::Client::new(); diff --git a/core/tests/tvu.rs b/core/tests/tvu.rs index ddb2a6ff7..f72f4f4c1 100644 --- a/core/tests/tvu.rs +++ b/core/tests/tvu.rs @@ -18,7 +18,7 @@ use solana::streamer; use solana::tvu::{Sockets, Tvu}; use solana_sdk::genesis_block::GenesisBlock; 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::net::UdpSocket; use std::sync::atomic::{AtomicBool, Ordering}; @@ -140,7 +140,7 @@ fn test_replay() { let entry0 = next_entry_mut(&mut cur_hash, i, 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, &bob_keypair.pubkey(), transfer_amount, diff --git a/drone/src/drone.rs b/drone/src/drone.rs index 8a3e1aeab..8efdd6d74 100644 --- a/drone/src/drone.rs +++ b/drone/src/drone.rs @@ -16,7 +16,7 @@ use solana_sdk::message::Message; use solana_sdk::packet::PACKET_DATA_SIZE; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::{Keypair, KeypairUtil}; -use solana_sdk::system_instruction::SystemInstruction; +use solana_sdk::system_instruction; use solana_sdk::transaction::Transaction; use std::io; use std::io::{Error, ErrorKind}; @@ -127,7 +127,7 @@ impl Drone { 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(), &to, lamports, @@ -285,6 +285,7 @@ pub fn run_local_drone(mint_keypair: Keypair, sender: Sender) { mod tests { use super::*; use bytes::BufMut; + use solana_sdk::system_instruction::SystemInstruction; use std::time::Duration; #[test] @@ -394,7 +395,7 @@ mod tests { let keypair = Keypair::new(); 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 expected_tx = Transaction::new(&[&keypair], message, blockhash); let expected_bytes = serialize(&expected_tx).unwrap(); diff --git a/drone/src/drone_mock.rs b/drone/src/drone_mock.rs index 708a682c4..9bf085162 100644 --- a/drone/src/drone_mock.rs +++ b/drone/src/drone_mock.rs @@ -1,7 +1,7 @@ use solana_sdk::hash::Hash; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::{Keypair, KeypairUtil}; -use solana_sdk::system_transaction::SystemTransaction; +use solana_sdk::system_transaction; use solana_sdk::transaction::Transaction; use std::io::{Error, ErrorKind}; use std::net::SocketAddr; @@ -18,6 +18,6 @@ pub fn request_airdrop_transaction( let key = Keypair::new(); let to = Pubkey::new_rand(); 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) } diff --git a/drone/tests/local-drone.rs b/drone/tests/local-drone.rs index 13cc6c70c..d2d11c925 100644 --- a/drone/tests/local-drone.rs +++ b/drone/tests/local-drone.rs @@ -3,7 +3,7 @@ use solana_sdk::hash::Hash; use solana_sdk::message::Message; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::{Keypair, KeypairUtil}; -use solana_sdk::system_instruction::SystemInstruction; +use solana_sdk::system_instruction; use solana_sdk::transaction::Transaction; use std::sync::mpsc::channel; @@ -13,7 +13,8 @@ fn test_local_drone() { let to = Pubkey::new_rand(); let lamports = 50; 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 expected_tx = Transaction::new(&[&keypair], message, blockhash); diff --git a/install/src/command.rs b/install/src/command.rs index 7c40d1fc6..45da10222 100644 --- a/install/src/command.rs +++ b/install/src/command.rs @@ -5,7 +5,7 @@ use console::{style, Emoji}; use indicatif::{ProgressBar, ProgressStyle}; use ring::digest::{Context, Digest, SHA256}; 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::signature::{read_keypair, Keypair, KeypairUtil, Signable}; use solana_sdk::transaction::Transaction; @@ -198,7 +198,7 @@ fn new_update_manifest( { let recect_blockhash = rpc_client.get_recent_blockhash()?; - let new_account = ConfigInstruction::new_account::( + let new_account = config_instruction::create_account::( &from_keypair.pubkey(), &update_manifest_keypair.pubkey(), 1, // lamports @@ -220,7 +220,7 @@ fn store_update_manifest( ) -> Result<(), Box> { let recect_blockhash = rpc_client.get_recent_blockhash()?; - let new_store = ConfigInstruction::new_store::( + let new_store = config_instruction::store::( &from_keypair.pubkey(), &update_manifest_keypair.pubkey(), update_manifest, diff --git a/programs/budget_api/src/budget_instruction.rs b/programs/budget_api/src/budget_instruction.rs index ec717f956..4441d9b85 100644 --- a/programs/budget_api/src/budget_instruction.rs +++ b/programs/budget_api/src/budget_instruction.rs @@ -6,7 +6,7 @@ use chrono::prelude::{DateTime, Utc}; use serde_derive::{Deserialize, Serialize}; use solana_sdk::instruction::{AccountMeta, Instruction}; use solana_sdk::pubkey::Pubkey; -use solana_sdk::system_instruction::SystemInstruction; +use solana_sdk::system_instruction; /// A smart contract. #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] @@ -30,93 +30,90 @@ pub enum BudgetInstruction { ApplySignature, } -impl BudgetInstruction { - fn new_initialize_account(contract: &Pubkey, expr: BudgetExpr) -> Instruction { - let mut keys = vec![]; - if let BudgetExpr::Pay(payment) = &expr { - keys.push(AccountMeta::new(payment.to, false)); - } - keys.push(AccountMeta::new(*contract, false)); - Instruction::new(id(), &BudgetInstruction::InitializeAccount(expr), keys) +fn initialize_account(contract: &Pubkey, expr: BudgetExpr) -> Instruction { + let mut keys = vec![]; + if let BudgetExpr::Pay(payment) = &expr { + keys.push(AccountMeta::new(payment.to, false)); } + keys.push(AccountMeta::new(*contract, false)); + Instruction::new(id(), &BudgetInstruction::InitializeAccount(expr), keys) +} - pub fn new_account( - from: &Pubkey, - contract: &Pubkey, - lamports: u64, - expr: BudgetExpr, - ) -> Vec { - if !expr.verify(lamports) { - 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), - ] +pub fn create_account( + from: &Pubkey, + contract: &Pubkey, + lamports: u64, + expr: BudgetExpr, +) -> Vec { + if !expr.verify(lamports) { + panic!("invalid budget expression"); } + 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. - pub fn new_payment(from: &Pubkey, to: &Pubkey, lamports: u64) -> Vec { - let contract = Pubkey::new_rand(); - let expr = BudgetExpr::new_payment(lamports, to); - Self::new_account(from, &contract, lamports, expr) - } +/// Create a new payment script. +pub fn payment(from: &Pubkey, to: &Pubkey, lamports: u64) -> Vec { + let contract = Pubkey::new_rand(); + let expr = BudgetExpr::new_payment(lamports, to); + create_account(from, &contract, lamports, expr) +} - /// Create a future payment script. - pub fn new_on_date( - from: &Pubkey, - to: &Pubkey, - contract: &Pubkey, - dt: DateTime, - dt_pubkey: &Pubkey, - cancelable: Option, - lamports: u64, - ) -> Vec { - let expr = - BudgetExpr::new_cancelable_future_payment(dt, dt_pubkey, lamports, to, cancelable); - Self::new_account(from, contract, lamports, expr) - } +/// Create a future payment script. +pub fn on_date( + from: &Pubkey, + to: &Pubkey, + contract: &Pubkey, + dt: DateTime, + dt_pubkey: &Pubkey, + cancelable: Option, + lamports: u64, +) -> Vec { + let expr = BudgetExpr::new_cancelable_future_payment(dt, dt_pubkey, lamports, to, cancelable); + create_account(from, contract, lamports, expr) +} - /// Create a multisig payment script. - pub fn new_when_signed( - from: &Pubkey, - to: &Pubkey, - contract: &Pubkey, - witness: &Pubkey, - cancelable: Option, - lamports: u64, - ) -> Vec { - let expr = BudgetExpr::new_cancelable_authorized_payment(witness, lamports, to, cancelable); - Self::new_account(from, contract, lamports, expr) - } +/// Create a multisig payment script. +pub fn when_signed( + from: &Pubkey, + to: &Pubkey, + contract: &Pubkey, + witness: &Pubkey, + cancelable: Option, + lamports: u64, +) -> Vec { + let expr = BudgetExpr::new_cancelable_authorized_payment(witness, lamports, to, cancelable); + create_account(from, contract, lamports, expr) +} - pub fn new_apply_timestamp( - from: &Pubkey, - contract: &Pubkey, - to: &Pubkey, - dt: DateTime, - ) -> Instruction { - let mut account_metas = vec![ - AccountMeta::new(*from, true), - AccountMeta::new(*contract, false), - ]; - if from != to { - account_metas.push(AccountMeta::new(*to, false)); - } - Instruction::new(id(), &BudgetInstruction::ApplyTimestamp(dt), account_metas) +pub fn apply_timestamp( + from: &Pubkey, + contract: &Pubkey, + to: &Pubkey, + dt: DateTime, +) -> Instruction { + let mut account_metas = vec![ + AccountMeta::new(*from, true), + AccountMeta::new(*contract, false), + ]; + if from != to { + account_metas.push(AccountMeta::new(*to, false)); } + Instruction::new(id(), &BudgetInstruction::ApplyTimestamp(dt), account_metas) +} - pub fn new_apply_signature(from: &Pubkey, contract: &Pubkey, to: &Pubkey) -> Instruction { - let mut account_metas = vec![ - AccountMeta::new(*from, true), - AccountMeta::new(*contract, false), - ]; - if from != to { - account_metas.push(AccountMeta::new(*to, false)); - } - Instruction::new(id(), &BudgetInstruction::ApplySignature, account_metas) +pub fn apply_signature(from: &Pubkey, contract: &Pubkey, to: &Pubkey) -> Instruction { + let mut account_metas = vec![ + AccountMeta::new(*from, true), + AccountMeta::new(*contract, false), + ]; + if from != to { + account_metas.push(AccountMeta::new(*to, false)); } + Instruction::new(id(), &BudgetInstruction::ApplySignature, account_metas) } #[cfg(test)] @@ -128,7 +125,7 @@ mod tests { fn test_budget_instruction_verify() { let alice_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] @@ -138,7 +135,7 @@ mod tests { let bob_pubkey = Pubkey::new_rand(); let budget_pubkey = Pubkey::new_rand(); 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] @@ -148,6 +145,6 @@ mod tests { let bob_pubkey = Pubkey::new_rand(); let budget_pubkey = Pubkey::new_rand(); 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); } } diff --git a/programs/budget_api/src/budget_processor.rs b/programs/budget_api/src/budget_processor.rs index ce2051596..58c76aad4 100644 --- a/programs/budget_api/src/budget_processor.rs +++ b/programs/budget_api/src/budget_processor.rs @@ -143,7 +143,7 @@ pub fn process_instruction( #[cfg(test)] mod tests { use super::*; - use crate::budget_instruction::BudgetInstruction; + use crate::budget_instruction; use crate::id; use solana_runtime::bank::Bank; use solana_runtime::bank_client::BankClient; @@ -166,7 +166,7 @@ mod tests { let bank_client = BankClient::new(&bank); let alice_pubkey = alice_keypair.pubkey(); 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); bank_client .process_message(&[&alice_keypair], message) @@ -184,7 +184,7 @@ mod tests { let budget_pubkey = Pubkey::new_rand(); let bob_pubkey = Pubkey::new_rand(); let witness = Pubkey::new_rand(); - let instructions = BudgetInstruction::new_when_signed( + let instructions = budget_instruction::when_signed( &alice_pubkey, &bob_pubkey, &budget_pubkey, @@ -204,7 +204,7 @@ mod tests { .transfer(1, &alice_keypair, &mallory_pubkey) .unwrap(); 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]); // 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 bob_pubkey = Pubkey::new_rand(); let dt = Utc::now(); - let instructions = BudgetInstruction::new_on_date( + let instructions = budget_instruction::on_date( &alice_pubkey, &bob_pubkey, &budget_pubkey, @@ -251,12 +251,8 @@ mod tests { bank_client .transfer(1, &alice_keypair, &mallory_pubkey) .unwrap(); - let instruction = BudgetInstruction::new_apply_timestamp( - &mallory_pubkey, - &budget_pubkey, - &bob_pubkey, - dt, - ); + let instruction = + budget_instruction::apply_timestamp(&mallory_pubkey, &budget_pubkey, &bob_pubkey, dt); let mut message = Message::new(vec![instruction]); // 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 mallory_pubkey = Pubkey::new_rand(); let dt = Utc::now(); - let instructions = BudgetInstruction::new_on_date( + let instructions = budget_instruction::on_date( &alice_pubkey, &bob_pubkey, &budget_pubkey, @@ -303,12 +299,8 @@ mod tests { assert!(budget_state.is_pending()); // Attack! Try to payout to mallory_pubkey - let instruction = BudgetInstruction::new_apply_timestamp( - &alice_pubkey, - &budget_pubkey, - &mallory_pubkey, - dt, - ); + let instruction = + budget_instruction::apply_timestamp(&alice_pubkey, &budget_pubkey, &mallory_pubkey, dt); assert_eq!( bank_client .process_instruction(&alice_keypair, instruction) @@ -329,7 +321,7 @@ mod tests { // Now, acknowledge the time in the condition occurred and // that pubkey's funds are now available. 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 .process_instruction(&alice_keypair, instruction) .unwrap(); @@ -348,7 +340,7 @@ mod tests { let bob_pubkey = Pubkey::new_rand(); let dt = Utc::now(); - let instructions = BudgetInstruction::new_on_date( + let instructions = budget_instruction::on_date( &alice_pubkey, &bob_pubkey, &budget_pubkey, @@ -377,7 +369,7 @@ mod tests { assert_eq!(bank.get_balance(&alice_pubkey), 1); let instruction = - BudgetInstruction::new_apply_signature(&mallory_pubkey, &budget_pubkey, &bob_pubkey); + budget_instruction::apply_signature(&mallory_pubkey, &budget_pubkey, &bob_pubkey); bank_client .process_instruction(&mallory_keypair, instruction) .unwrap(); @@ -388,7 +380,7 @@ mod tests { // Now, cancel the transaction. mint gets her funds back let instruction = - BudgetInstruction::new_apply_signature(&alice_pubkey, &budget_pubkey, &alice_pubkey); + budget_instruction::apply_signature(&alice_pubkey, &budget_pubkey, &alice_pubkey); bank_client .process_instruction(&alice_keypair, instruction) .unwrap(); diff --git a/programs/config_api/src/config_instruction.rs b/programs/config_api/src/config_instruction.rs index 021d19dd3..1206c9922 100644 --- a/programs/config_api/src/config_instruction.rs +++ b/programs/config_api/src/config_instruction.rs @@ -2,36 +2,32 @@ use crate::id; use crate::ConfigState; use solana_sdk::instruction::{AccountMeta, Instruction}; use solana_sdk::pubkey::Pubkey; -use solana_sdk::system_instruction::SystemInstruction; +use solana_sdk::system_instruction; -pub struct ConfigInstruction {} - -impl ConfigInstruction { - /// Create a new, empty configuration account - pub fn new_account( - from_account_pubkey: &Pubkey, - config_account_pubkey: &Pubkey, - lamports: u64, - ) -> Instruction { - SystemInstruction::new_account( - from_account_pubkey, - config_account_pubkey, - lamports, - T::max_space(), - &id(), - ) - } - - /// Store new data in a configuration account - pub fn new_store( - from_account_pubkey: &Pubkey, - config_account_pubkey: &Pubkey, - data: &T, - ) -> Instruction { - let account_metas = vec![ - AccountMeta::new(*from_account_pubkey, true), - AccountMeta::new(*config_account_pubkey, true), - ]; - Instruction::new(id(), data, account_metas) - } +/// Create a new, empty configuration account +pub fn create_account( + from_account_pubkey: &Pubkey, + config_account_pubkey: &Pubkey, + lamports: u64, +) -> Instruction { + system_instruction::create_account( + from_account_pubkey, + config_account_pubkey, + lamports, + T::max_space(), + &id(), + ) +} + +/// Store new data in a configuration account +pub fn store( + from_account_pubkey: &Pubkey, + config_account_pubkey: &Pubkey, + data: &T, +) -> Instruction { + let account_metas = vec![ + AccountMeta::new(*from_account_pubkey, true), + AccountMeta::new(*config_account_pubkey, true), + ]; + Instruction::new(id(), data, account_metas) } diff --git a/programs/config_api/src/config_processor.rs b/programs/config_api/src/config_processor.rs index cd1b9cd0e..58265846e 100644 --- a/programs/config_api/src/config_processor.rs +++ b/programs/config_api/src/config_processor.rs @@ -28,7 +28,7 @@ pub fn process_instruction( #[cfg(test)] mod tests { use super::*; - use crate::{id, ConfigInstruction, ConfigState}; + use crate::{config_instruction, id, ConfigState}; use bincode::{deserialize, serialized_size}; use serde_derive::{Deserialize, Serialize}; use solana_runtime::bank::Bank; @@ -36,7 +36,7 @@ mod tests { use solana_sdk::genesis_block::GenesisBlock; use solana_sdk::message::Message; use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_instruction::SystemInstruction; + use solana_sdk::system_instruction; #[derive(Serialize, Deserialize, Default, Debug, PartialEq)] struct MyConfig { @@ -78,7 +78,7 @@ mod tests { bank_client .process_instruction( &mint_keypair, - ConfigInstruction::new_account::( + config_instruction::create_account::( &mint_keypair.pubkey(), &config_pubkey, 1, @@ -111,7 +111,7 @@ mod tests { let my_config = MyConfig::new(42); 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]); bank_client .process_message(&[&from_keypair, &config_keypair], message) @@ -133,11 +133,8 @@ mod tests { let my_config = MyConfig::new(42); // Replace instruction data with a vector that's too large - let mut instruction = ConfigInstruction::new_store( - &from_keypair.pubkey(), - &config_keypair.pubkey(), - &my_config, - ); + let mut instruction = + config_instruction::store(&from_keypair.pubkey(), &config_keypair.pubkey(), &my_config); instruction.data = vec![0; 123]; let message = Message::new(vec![instruction]); @@ -155,14 +152,10 @@ mod tests { bank.transfer(42, &mint_keypair, &system_pubkey).unwrap(); let (bank_client, from_keypair, config_keypair) = create_config_client(&bank, mint_keypair); - let move_instruction = - SystemInstruction::new_transfer(&system_pubkey, &Pubkey::default(), 42); + let move_instruction = system_instruction::transfer(&system_pubkey, &Pubkey::default(), 42); let my_config = MyConfig::new(42); - let mut store_instruction = ConfigInstruction::new_store( - &from_keypair.pubkey(), - &config_keypair.pubkey(), - &my_config, - ); + let mut store_instruction = + config_instruction::store(&from_keypair.pubkey(), &config_keypair.pubkey(), &my_config); store_instruction.accounts[0].is_signer = false; store_instruction.accounts[1].is_signer = false; diff --git a/programs/config_api/src/lib.rs b/programs/config_api/src/lib.rs index 127c31484..6050810ab 100644 --- a/programs/config_api/src/lib.rs +++ b/programs/config_api/src/lib.rs @@ -1,11 +1,9 @@ use serde::Serialize; use solana_sdk::pubkey::Pubkey; -mod config_instruction; +pub mod config_instruction; pub mod config_processor; -pub use config_instruction::ConfigInstruction; - 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, 0, diff --git a/programs/exchange_api/src/exchange_instruction.rs b/programs/exchange_api/src/exchange_instruction.rs index 4d9efd30a..1741ee01e 100644 --- a/programs/exchange_api/src/exchange_instruction.rs +++ b/programs/exchange_api/src/exchange_instruction.rs @@ -59,89 +59,88 @@ pub enum ExchangeInstruction { /// key 6 - Token account in which to deposit the brokers profit from the swap. 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( - owner: &Pubkey, - to: &Pubkey, - from: &Pubkey, - token: Token, - tokens: u64, - ) -> Instruction { - let account_metas = vec![ - AccountMeta::new(*owner, true), - AccountMeta::new(*to, false), - AccountMeta::new(*from, false), - ]; - Instruction::new( - id(), - &ExchangeInstruction::TransferRequest(token, tokens), - account_metas, - ) - } - - pub fn new_trade_request( - owner: &Pubkey, - trade: &Pubkey, - direction: Direction, - pair: TokenPair, - tokens: u64, - price: u64, - src_account: &Pubkey, - dst_account: &Pubkey, - ) -> Instruction { - let account_metas = vec![ - AccountMeta::new(*owner, true), - AccountMeta::new(*trade, false), - AccountMeta::new(*src_account, false), - ]; - Instruction::new( - id(), - &ExchangeInstruction::TradeRequest(TradeRequestInfo { - direction, - pair, - tokens, - price, - dst_account: *dst_account, - }), - account_metas, - ) - } - - pub fn new_trade_cancellation(owner: &Pubkey, trade: &Pubkey, account: &Pubkey) -> Instruction { - let account_metas = vec![ - AccountMeta::new(*owner, true), - AccountMeta::new(*trade, false), - AccountMeta::new(*account, false), - ]; - Instruction::new(id(), &ExchangeInstruction::TradeCancellation, account_metas) - } - - pub fn new_swap_request( - owner: &Pubkey, - swap: &Pubkey, - to_trade: &Pubkey, - from_trade: &Pubkey, - to_trade_account: &Pubkey, - from_trade_account: &Pubkey, - profit_account: &Pubkey, - ) -> Instruction { - let account_metas = vec![ - 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) - } +pub fn 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 transfer_request( + owner: &Pubkey, + to: &Pubkey, + from: &Pubkey, + token: Token, + tokens: u64, +) -> Instruction { + let account_metas = vec![ + AccountMeta::new(*owner, true), + AccountMeta::new(*to, false), + AccountMeta::new(*from, false), + ]; + Instruction::new( + id(), + &ExchangeInstruction::TransferRequest(token, tokens), + account_metas, + ) +} + +pub fn trade_request( + owner: &Pubkey, + trade: &Pubkey, + direction: Direction, + pair: TokenPair, + tokens: u64, + price: u64, + src_account: &Pubkey, + dst_account: &Pubkey, +) -> Instruction { + let account_metas = vec![ + AccountMeta::new(*owner, true), + AccountMeta::new(*trade, false), + AccountMeta::new(*src_account, false), + ]; + Instruction::new( + id(), + &ExchangeInstruction::TradeRequest(TradeRequestInfo { + direction, + pair, + tokens, + price, + dst_account: *dst_account, + }), + account_metas, + ) +} + +pub fn trade_cancellation(owner: &Pubkey, trade: &Pubkey, account: &Pubkey) -> Instruction { + let account_metas = vec![ + AccountMeta::new(*owner, true), + AccountMeta::new(*trade, false), + AccountMeta::new(*account, false), + ]; + Instruction::new(id(), &ExchangeInstruction::TradeCancellation, account_metas) +} + +pub fn swap_request( + owner: &Pubkey, + swap: &Pubkey, + to_trade: &Pubkey, + from_trade: &Pubkey, + to_trade_account: &Pubkey, + from_trade_account: &Pubkey, + profit_account: &Pubkey, +) -> Instruction { + let account_metas = vec![ + 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) } diff --git a/programs/exchange_api/src/exchange_processor.rs b/programs/exchange_api/src/exchange_processor.rs index 91c2a11a7..8309e8eda 100644 --- a/programs/exchange_api/src/exchange_processor.rs +++ b/programs/exchange_api/src/exchange_processor.rs @@ -412,11 +412,12 @@ pub fn process_instruction( #[cfg(test)] mod test { use super::*; + use crate::exchange_instruction; use solana_runtime::bank::Bank; use solana_runtime::bank_client::BankClient; use solana_sdk::genesis_block::GenesisBlock; use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_instruction::SystemInstruction; + use solana_sdk::system_instruction; use std::mem; fn try_calc( @@ -527,7 +528,7 @@ mod test { fn create_account(client: &BankClient, owner: &Keypair) -> Pubkey { let new = Pubkey::new_rand(); - let instruction = SystemInstruction::new_account( + let instruction = system_instruction::create_account( &owner.pubkey(), &new, 1, @@ -542,7 +543,7 @@ mod test { fn create_token_account(client: &BankClient, owner: &Keypair) -> Pubkey { let new = Pubkey::new_rand(); - let instruction = SystemInstruction::new_account( + let instruction = system_instruction::create_account( &owner.pubkey(), &new, 1, @@ -552,7 +553,7 @@ mod test { client .process_instruction(owner, instruction) .expect(&format!("{}:{}", line!(), file!())); - let instruction = ExchangeInstruction::new_account_request(&owner.pubkey(), &new); + let instruction = exchange_instruction::account_request(&owner.pubkey(), &new); client .process_instruction(owner, instruction) .expect(&format!("{}:{}", line!(), file!())); @@ -561,7 +562,7 @@ mod test { fn transfer(client: &BankClient, owner: &Keypair, to: &Pubkey, token: Token, tokens: u64) { let instruction = - ExchangeInstruction::new_transfer_request(&owner.pubkey(), to, &id(), token, tokens); + exchange_instruction::transfer_request(&owner.pubkey(), to, &id(), token, tokens); client .process_instruction(owner, instruction) .expect(&format!("{}:{}", line!(), file!())); @@ -582,7 +583,7 @@ mod test { let dst = create_token_account(&client, &owner); transfer(&client, &owner, &src, from_token, src_tokens); - let instruction = ExchangeInstruction::new_trade_request( + let instruction = exchange_instruction::trade_request( &owner.pubkey(), &trade, direction, @@ -633,7 +634,7 @@ mod test { let (client, owner) = create_client(&bank, mint_keypair); 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 .process_instruction(&owner, instruction) .expect_err(&format!("{}:{}", line!(), file!())); @@ -648,7 +649,7 @@ mod test { let new = create_token_account(&client, &owner); 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 .process_instruction(&owner, instruction) .expect(&format!("{}:{}", line!(), file!())); @@ -743,7 +744,7 @@ mod test { 3000, ); - let instruction = ExchangeInstruction::new_swap_request( + let instruction = exchange_instruction::swap_request( &owner.pubkey(), &swap, &to_trade, diff --git a/programs/exchange_api/src/exchange_transaction.rs b/programs/exchange_api/src/exchange_transaction.rs index 78fdd7410..ccfda2e8e 100644 --- a/programs/exchange_api/src/exchange_transaction.rs +++ b/programs/exchange_api/src/exchange_transaction.rs @@ -1,120 +1,103 @@ -use crate::exchange_instruction::*; +use crate::exchange_instruction; use crate::exchange_state::*; use crate::id; use solana_sdk::hash::Hash; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::{Keypair, KeypairUtil}; -use solana_sdk::system_instruction::SystemInstruction; +use solana_sdk::system_instruction; use solana_sdk::transaction::Transaction; use std::mem; -pub struct ExchangeTransaction {} - -impl ExchangeTransaction { - pub fn new_account_request( - owner: &Keypair, - new: &Pubkey, - recent_blockhash: Hash, - _fee: u64, - ) -> Transaction { - let owner_id = &owner.pubkey(); - let space = mem::size_of::() as u64; - 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( - &[owner], - vec![create_ix, request_ix], - recent_blockhash, - ) - } - - pub fn new_transfer_request( - owner: &Keypair, - to: &Pubkey, - from: &Pubkey, - token: Token, - tokens: u64, - recent_blockhash: Hash, - _fee: u64, - ) -> Transaction { - let owner_id = &owner.pubkey(); - let request_ix = - ExchangeInstruction::new_transfer_request(owner_id, to, from, token, tokens); - Transaction::new_signed_instructions(&[owner], vec![request_ix], recent_blockhash) - } - - #[allow(clippy::too_many_arguments)] - pub fn new_trade_request( - owner: &Keypair, - trade: &Pubkey, - direction: Direction, - pair: TokenPair, - tokens: u64, - price: u64, - src_account: &Pubkey, - dst_account: &Pubkey, - recent_blockhash: Hash, - _fee: u64, - ) -> Transaction { - let owner_id = &owner.pubkey(); - let space = mem::size_of::() as u64; - let create_ix = SystemInstruction::new_account(owner_id, trade, 1, space, &id()); - let request_ix = ExchangeInstruction::new_trade_request( - owner_id, - trade, - direction, - pair, - tokens, - price, - src_account, - dst_account, - ); - Transaction::new_signed_instructions( - &[owner], - vec![create_ix, request_ix], - recent_blockhash, - ) - } - - pub fn new_trade_cancellation( - owner: &Keypair, - trade: &Pubkey, - account: &Pubkey, - recent_blockhash: Hash, - _fee: u64, - ) -> Transaction { - let owner_id = &owner.pubkey(); - let request_ix = ExchangeInstruction::new_trade_cancellation(owner_id, trade, account); - Transaction::new_signed_instructions(&[owner], vec![request_ix], recent_blockhash) - } - - pub fn new_swap_request( - owner: &Keypair, - swap: &Pubkey, - to_trade: &Pubkey, - from_trade: &Pubkey, - to_trade_account: &Pubkey, - from_trade_account: &Pubkey, - profit_account: &Pubkey, - recent_blockhash: Hash, - _fee: u64, - ) -> Transaction { - let owner_id = &owner.pubkey(); - let space = mem::size_of::() 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, - ) - } +pub fn account_request( + owner: &Keypair, + new: &Pubkey, + recent_blockhash: Hash, + _fee: u64, +) -> Transaction { + let owner_id = &owner.pubkey(); + let space = mem::size_of::() as u64; + let create_ix = system_instruction::create_account(owner_id, new, 1, space, &id()); + let request_ix = exchange_instruction::account_request(owner_id, new); + Transaction::new_signed_instructions(&[owner], vec![create_ix, request_ix], recent_blockhash) +} + +pub fn transfer_request( + owner: &Keypair, + to: &Pubkey, + from: &Pubkey, + token: Token, + tokens: u64, + recent_blockhash: Hash, + _fee: u64, +) -> Transaction { + let owner_id = &owner.pubkey(); + let request_ix = exchange_instruction::transfer_request(owner_id, to, from, token, tokens); + Transaction::new_signed_instructions(&[owner], vec![request_ix], recent_blockhash) +} + +#[allow(clippy::too_many_arguments)] +pub fn trade_request( + owner: &Keypair, + trade: &Pubkey, + direction: Direction, + pair: TokenPair, + tokens: u64, + price: u64, + src_account: &Pubkey, + dst_account: &Pubkey, + recent_blockhash: Hash, + _fee: u64, +) -> Transaction { + let owner_id = &owner.pubkey(); + let space = mem::size_of::() as u64; + let create_ix = system_instruction::create_account(owner_id, trade, 1, space, &id()); + let request_ix = exchange_instruction::trade_request( + owner_id, + trade, + direction, + pair, + tokens, + price, + src_account, + dst_account, + ); + Transaction::new_signed_instructions(&[owner], vec![create_ix, request_ix], recent_blockhash) +} + +pub fn trade_cancellation( + owner: &Keypair, + trade: &Pubkey, + account: &Pubkey, + recent_blockhash: Hash, + _fee: u64, +) -> Transaction { + let owner_id = &owner.pubkey(); + let request_ix = exchange_instruction::trade_cancellation(owner_id, trade, account); + Transaction::new_signed_instructions(&[owner], vec![request_ix], recent_blockhash) +} + +pub fn swap_request( + owner: &Keypair, + swap: &Pubkey, + to_trade: &Pubkey, + from_trade: &Pubkey, + to_trade_account: &Pubkey, + from_trade_account: &Pubkey, + profit_account: &Pubkey, + recent_blockhash: Hash, + _fee: u64, +) -> Transaction { + let owner_id = &owner.pubkey(); + let space = mem::size_of::() as u64; + let create_ix = system_instruction::create_account(owner_id, swap, 1, space, &id()); + let request_ix = exchange_instruction::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) } diff --git a/programs/stake_api/src/stake_instruction.rs b/programs/stake_api/src/stake_instruction.rs index 7815a109d..ef39912ed 100644 --- a/programs/stake_api/src/stake_instruction.rs +++ b/programs/stake_api/src/stake_instruction.rs @@ -6,7 +6,7 @@ use serde_derive::{Deserialize, Serialize}; use solana_sdk::account::KeyedAccount; use solana_sdk::instruction::{AccountMeta, Instruction, InstructionError}; use solana_sdk::pubkey::Pubkey; -use solana_sdk::system_instruction::SystemInstruction; +use solana_sdk::system_instruction; #[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)] pub enum StakeInstruction { @@ -22,44 +22,38 @@ pub enum StakeInstruction { RedeemVoteCredits, } -impl StakeInstruction { - pub fn new_account(from_id: &Pubkey, staker_id: &Pubkey, lamports: u64) -> Vec { - vec![SystemInstruction::new_account( - from_id, - staker_id, - lamports, - std::mem::size_of::() as u64, - &id(), - )] - } +pub fn create_account(from_id: &Pubkey, staker_id: &Pubkey, lamports: u64) -> Vec { + vec![system_instruction::create_account( + from_id, + staker_id, + lamports, + std::mem::size_of::() as u64, + &id(), + )] +} - pub fn new_redeem_vote_credits( - from_id: &Pubkey, - mining_pool_id: &Pubkey, - stake_id: &Pubkey, - vote_id: &Pubkey, - ) -> Instruction { - let account_metas = vec![ - AccountMeta::new(*from_id, true), - AccountMeta::new(*mining_pool_id, false), - AccountMeta::new(*stake_id, false), - AccountMeta::new(*vote_id, false), - ]; - Instruction::new(id(), &StakeInstruction::RedeemVoteCredits, account_metas) - } +pub fn redeem_vote_credits( + from_id: &Pubkey, + mining_pool_id: &Pubkey, + stake_id: &Pubkey, + vote_id: &Pubkey, +) -> Instruction { + let account_metas = vec![ + AccountMeta::new(*from_id, true), + AccountMeta::new(*mining_pool_id, false), + AccountMeta::new(*stake_id, false), + AccountMeta::new(*vote_id, false), + ]; + Instruction::new(id(), &StakeInstruction::RedeemVoteCredits, account_metas) +} - pub fn new_delegate_stake( - from_id: &Pubkey, - stake_id: &Pubkey, - vote_id: &Pubkey, - ) -> Instruction { - let account_metas = vec![ - AccountMeta::new(*from_id, true), - AccountMeta::new(*stake_id, true), - AccountMeta::new(*vote_id, false), - ]; - Instruction::new(id(), &StakeInstruction::DelegateStake, account_metas) - } +pub fn delegate_stake(from_id: &Pubkey, stake_id: &Pubkey, vote_id: &Pubkey) -> Instruction { + let account_metas = vec![ + AccountMeta::new(*from_id, true), + AccountMeta::new(*stake_id, true), + AccountMeta::new(*vote_id, false), + ]; + Instruction::new(id(), &StakeInstruction::DelegateStake, account_metas) } pub fn process_instruction( diff --git a/programs/storage_api/src/storage_instruction.rs b/programs/storage_api/src/storage_instruction.rs index d116237c5..69a9f691a 100644 --- a/programs/storage_api/src/storage_instruction.rs +++ b/programs/storage_api/src/storage_instruction.rs @@ -26,51 +26,49 @@ pub enum StorageInstruction { }, } -impl StorageInstruction { - pub fn new_mining_proof( - from_pubkey: &Pubkey, - sha_state: Hash, - entry_height: u64, - signature: Signature, - ) -> Instruction { - let storage_instruction = StorageInstruction::SubmitMiningProof { - sha_state, - entry_height, - signature, - }; - let account_metas = vec![AccountMeta::new(*from_pubkey, true)]; - Instruction::new(id(), &storage_instruction, account_metas) - } - - pub fn new_advertise_recent_blockhash( - from_pubkey: &Pubkey, - storage_hash: Hash, - entry_height: u64, - ) -> Instruction { - let storage_instruction = StorageInstruction::AdvertiseStorageRecentBlockhash { - hash: storage_hash, - entry_height, - }; - let account_metas = vec![AccountMeta::new(*from_pubkey, true)]; - Instruction::new(id(), &storage_instruction, account_metas) - } - - pub fn new_proof_validation( - from_pubkey: &Pubkey, - entry_height: u64, - proof_mask: Vec, - ) -> Instruction { - let storage_instruction = StorageInstruction::ProofValidation { - entry_height, - proof_mask, - }; - let account_metas = vec![AccountMeta::new(*from_pubkey, true)]; - Instruction::new(id(), &storage_instruction, account_metas) - } - - pub fn new_reward_claim(from_pubkey: &Pubkey, entry_height: u64) -> Instruction { - let storage_instruction = StorageInstruction::ClaimStorageReward { entry_height }; - let account_metas = vec![AccountMeta::new(*from_pubkey, true)]; - Instruction::new(id(), &storage_instruction, account_metas) - } +pub fn mining_proof( + from_pubkey: &Pubkey, + sha_state: Hash, + entry_height: u64, + signature: Signature, +) -> Instruction { + let storage_instruction = StorageInstruction::SubmitMiningProof { + sha_state, + entry_height, + signature, + }; + let account_metas = vec![AccountMeta::new(*from_pubkey, true)]; + Instruction::new(id(), &storage_instruction, account_metas) +} + +pub fn advertise_recent_blockhash( + from_pubkey: &Pubkey, + storage_hash: Hash, + entry_height: u64, +) -> Instruction { + let storage_instruction = StorageInstruction::AdvertiseStorageRecentBlockhash { + hash: storage_hash, + entry_height, + }; + let account_metas = vec![AccountMeta::new(*from_pubkey, true)]; + Instruction::new(id(), &storage_instruction, account_metas) +} + +pub fn proof_validation( + from_pubkey: &Pubkey, + entry_height: u64, + proof_mask: Vec, +) -> Instruction { + let storage_instruction = StorageInstruction::ProofValidation { + entry_height, + proof_mask, + }; + let account_metas = vec![AccountMeta::new(*from_pubkey, true)]; + Instruction::new(id(), &storage_instruction, account_metas) +} + +pub fn reward_claim(from_pubkey: &Pubkey, entry_height: u64) -> Instruction { + let storage_instruction = StorageInstruction::ClaimStorageReward { entry_height }; + let account_metas = vec![AccountMeta::new(*from_pubkey, true)]; + Instruction::new(id(), &storage_instruction, account_metas) } diff --git a/programs/storage_api/src/storage_processor.rs b/programs/storage_api/src/storage_processor.rs index 76b59f80e..4ac8ec596 100644 --- a/programs/storage_api/src/storage_processor.rs +++ b/programs/storage_api/src/storage_processor.rs @@ -171,6 +171,7 @@ mod tests { use super::*; use crate::id; use crate::storage_contract::ProofStatus; + use crate::storage_instruction; use crate::ENTRIES_PER_SEGMENT; use bincode::deserialize; use solana_runtime::bank::Bank; @@ -181,7 +182,7 @@ mod tests { use solana_sdk::instruction::Instruction; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::{Keypair, KeypairUtil, Signature}; - use solana_sdk::system_instruction::SystemInstruction; + use solana_sdk::system_instruction; fn test_instruction( ix: &Instruction, @@ -216,7 +217,7 @@ mod tests { let mut user_account = Account::default(); 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, Hash::default(), ENTRIES_PER_SEGMENT, @@ -234,7 +235,7 @@ mod tests { let mut accounts = [Account::default()]; 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()); let mut accounts = [Account::default(), Account::default(), Account::default()]; @@ -250,7 +251,7 @@ mod tests { accounts[1].data.resize(16 * 1024, 0); 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 assert!(test_instruction(&ix, &mut accounts).is_err()); @@ -263,7 +264,7 @@ mod tests { let mut accounts = [Account::default(), Account::default()]; accounts[0].data.resize(16 * 1024, 0); - let ix = StorageInstruction::new_advertise_recent_blockhash( + let ix = storage_instruction::advertise_recent_blockhash( &pubkey, Hash::default(), ENTRIES_PER_SEGMENT, @@ -272,7 +273,7 @@ mod tests { test_instruction(&ix, &mut accounts).unwrap(); 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(); } @@ -286,7 +287,7 @@ mod tests { let entry_height = 0; - let ix = StorageInstruction::new_advertise_recent_blockhash( + let ix = storage_instruction::advertise_recent_blockhash( &pubkey, Hash::default(), ENTRIES_PER_SEGMENT, @@ -294,7 +295,7 @@ mod tests { test_instruction(&ix, &mut accounts).unwrap(); - let ix = StorageInstruction::new_mining_proof( + let ix = storage_instruction::mining_proof( &pubkey, Hash::default(), entry_height, @@ -302,28 +303,25 @@ mod tests { ); test_instruction(&ix, &mut accounts).unwrap(); - let ix = StorageInstruction::new_advertise_recent_blockhash( + let ix = storage_instruction::advertise_recent_blockhash( &pubkey, Hash::default(), ENTRIES_PER_SEGMENT * 2, ); test_instruction(&ix, &mut accounts).unwrap(); - let ix = StorageInstruction::new_proof_validation( - &pubkey, - entry_height, - vec![ProofStatus::Valid], - ); + let ix = + storage_instruction::proof_validation(&pubkey, entry_height, vec![ProofStatus::Valid]); test_instruction(&ix, &mut accounts).unwrap(); - let ix = StorageInstruction::new_advertise_recent_blockhash( + let ix = storage_instruction::advertise_recent_blockhash( &pubkey, Hash::default(), ENTRIES_PER_SEGMENT * 3, ); 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(); assert!(accounts[0].lamports == TOTAL_VALIDATOR_REWARDS); @@ -386,11 +384,11 @@ mod tests { .transfer(10, &alice_keypair, &jack_pubkey) .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(); - let ix = StorageInstruction::new_advertise_recent_blockhash( + let ix = storage_instruction::advertise_recent_blockhash( &bob_pubkey, storage_blockhash, ENTRIES_PER_SEGMENT, @@ -399,7 +397,7 @@ mod tests { bank_client.process_instruction(&bob_keypair, ix).unwrap(); let entry_height = 0; - let ix = StorageInstruction::new_mining_proof( + let ix = storage_instruction::mining_proof( &bob_pubkey, Hash::default(), entry_height, diff --git a/programs/vote_api/src/vote_instruction.rs b/programs/vote_api/src/vote_instruction.rs index 1b645af8e..bd180555c 100644 --- a/programs/vote_api/src/vote_instruction.rs +++ b/programs/vote_api/src/vote_instruction.rs @@ -3,7 +3,7 @@ use crate::vote_state::VoteState; use serde_derive::{Deserialize, Serialize}; use solana_sdk::instruction::{AccountMeta, Instruction}; use solana_sdk::pubkey::Pubkey; -use solana_sdk::system_instruction::SystemInstruction; +use solana_sdk::system_instruction; #[derive(Serialize, Default, Deserialize, Debug, PartialEq, Eq, Clone)] pub struct Vote { @@ -37,44 +37,42 @@ pub enum VoteInstruction { ClearCredits, } -impl VoteInstruction { - fn new_initialize_account(vote_id: &Pubkey) -> Instruction { - let account_metas = vec![AccountMeta::new(*vote_id, false)]; - Instruction::new(id(), &VoteInstruction::InitializeAccount, account_metas) - } - - pub fn new_account(from_id: &Pubkey, staker_id: &Pubkey, lamports: u64) -> Vec { - let space = VoteState::max_size() as u64; - let create_ix = SystemInstruction::new_account(&from_id, staker_id, lamports, space, &id()); - let init_ix = VoteInstruction::new_initialize_account(staker_id); - vec![create_ix, init_ix] - } - - pub fn new_clear_credits(vote_id: &Pubkey) -> Instruction { - let account_metas = vec![AccountMeta::new(*vote_id, true)]; - Instruction::new(id(), &VoteInstruction::ClearCredits, account_metas) - } - - pub fn new_delegate_stake(vote_id: &Pubkey, delegate_id: &Pubkey) -> Instruction { - let account_metas = vec![AccountMeta::new(*vote_id, true)]; - Instruction::new( - id(), - &VoteInstruction::DelegateStake(*delegate_id), - account_metas, - ) - } - - pub fn new_authorize_voter(vote_id: &Pubkey, authorized_voter_id: &Pubkey) -> Instruction { - let account_metas = vec![AccountMeta::new(*vote_id, true)]; - Instruction::new( - id(), - &VoteInstruction::AuthorizeVoter(*authorized_voter_id), - account_metas, - ) - } - - pub fn new_vote(vote_id: &Pubkey, vote: Vote) -> Instruction { - let account_metas = vec![AccountMeta::new(*vote_id, true)]; - Instruction::new(id(), &VoteInstruction::Vote(vote), account_metas) - } +fn initialize_account(vote_id: &Pubkey) -> Instruction { + let account_metas = vec![AccountMeta::new(*vote_id, false)]; + Instruction::new(id(), &VoteInstruction::InitializeAccount, account_metas) +} + +pub fn create_account(from_id: &Pubkey, staker_id: &Pubkey, lamports: u64) -> Vec { + let space = VoteState::max_size() as u64; + let create_ix = system_instruction::create_account(&from_id, staker_id, lamports, space, &id()); + let init_ix = initialize_account(staker_id); + vec![create_ix, init_ix] +} + +pub fn clear_credits(vote_id: &Pubkey) -> Instruction { + let account_metas = vec![AccountMeta::new(*vote_id, true)]; + Instruction::new(id(), &VoteInstruction::ClearCredits, account_metas) +} + +pub fn delegate_stake(vote_id: &Pubkey, delegate_id: &Pubkey) -> Instruction { + let account_metas = vec![AccountMeta::new(*vote_id, true)]; + Instruction::new( + id(), + &VoteInstruction::DelegateStake(*delegate_id), + account_metas, + ) +} + +pub fn authorize_voter(vote_id: &Pubkey, authorized_voter_id: &Pubkey) -> Instruction { + let account_metas = vec![AccountMeta::new(*vote_id, true)]; + Instruction::new( + id(), + &VoteInstruction::AuthorizeVoter(*authorized_voter_id), + account_metas, + ) +} + +pub fn vote(vote_id: &Pubkey, vote: Vote) -> Instruction { + let account_metas = vec![AccountMeta::new(*vote_id, true)]; + Instruction::new(id(), &VoteInstruction::Vote(vote), account_metas) } diff --git a/programs/vote_api/src/vote_processor.rs b/programs/vote_api/src/vote_processor.rs index 22ab2d80d..bd8935ef2 100644 --- a/programs/vote_api/src/vote_processor.rs +++ b/programs/vote_api/src/vote_processor.rs @@ -45,7 +45,7 @@ pub fn process_instruction( mod tests { use super::*; use crate::id; - use crate::vote_instruction::{Vote, VoteInstruction}; + use crate::vote_instruction::{self, Vote}; use crate::vote_state::VoteState; use solana_runtime::bank::{Bank, Result}; use solana_runtime::bank_client::BankClient; @@ -54,7 +54,7 @@ mod tests { use solana_sdk::message::Message; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_instruction::SystemInstruction; + use solana_sdk::system_instruction; use solana_sdk::transaction::TransactionError; fn create_bank(lamports: u64) -> (Bank, Keypair) { @@ -70,7 +70,7 @@ mod tests { vote_id: &Pubkey, lamports: u64, ) -> 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); bank_client.process_message(&[from_keypair], message) } @@ -83,8 +83,8 @@ mod tests { lamports: u64, ) -> Result<()> { let vote_id = vote_keypair.pubkey(); - let mut ixs = VoteInstruction::new_account(&from_keypair.pubkey(), &vote_id, lamports); - let delegate_ix = VoteInstruction::new_delegate_stake(&vote_id, delegate_id); + let mut ixs = vote_instruction::create_account(&from_keypair.pubkey(), &vote_id, lamports); + let delegate_ix = vote_instruction::delegate_stake(&vote_id, delegate_id); ixs.push(delegate_ix); let message = Message::new(ixs); bank_client.process_message(&[&from_keypair, vote_keypair], message) @@ -95,7 +95,7 @@ mod tests { vote_keypair: &Keypair, tick_height: u64, ) -> 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) } @@ -142,13 +142,13 @@ mod tests { create_vote_account(&bank_client, &mallory_keypair, &vote_id, 100).unwrap(); 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. // Sneak in an instruction so that the transaction is signed but // the 0th account in the second instruction is not! The program // 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 result = bank_client.process_message(&[&mallory_keypair], message); diff --git a/runtime/benches/bank.rs b/runtime/benches/bank.rs index fb9befe8a..a8e705ff5 100644 --- a/runtime/benches/bank.rs +++ b/runtime/benches/bank.rs @@ -6,7 +6,7 @@ use solana_runtime::bank::*; use solana_sdk::genesis_block::GenesisBlock; use solana_sdk::hash::hash; 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 test::Bencher; @@ -21,7 +21,7 @@ fn bench_process_transaction(bencher: &mut Bencher) { .map(|_| { // Seed the 'from' account. let rando0 = Keypair::new(); - let tx = SystemTransaction::new_transfer( + let tx = system_transaction::transfer( &mint_keypair, &rando0.pubkey(), 10_000, @@ -32,7 +32,7 @@ fn bench_process_transaction(bencher: &mut Bencher) { // Seed the 'to' account and a cell for its signature. let rando1 = Keypair::new(); - let tx = SystemTransaction::new_transfer( + let tx = system_transaction::transfer( &rando0, &rando1.pubkey(), 1, diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index ef167b8b0..45c5ad1d7 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -20,7 +20,7 @@ use solana_sdk::hash::{extend_and_hash, Hash}; use solana_sdk::native_loader; use solana_sdk::pubkey::Pubkey; 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::transaction::{Transaction, TransactionError}; 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. pub fn transfer(&self, n: u64, keypair: &Keypair, to: &Pubkey) -> Result { 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]; self.process_transaction(&tx).map(|_| signature) } @@ -973,8 +973,8 @@ mod tests { use solana_sdk::hash; use solana_sdk::instruction::InstructionError; use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_instruction::SystemInstruction; - use solana_sdk::system_transaction::SystemTransaction; + use solana_sdk::system_instruction; + use solana_sdk::system_transaction; #[test] fn test_bank_new() { @@ -1027,8 +1027,8 @@ mod tests { let bank = Bank::new(&genesis_block); assert_eq!(bank.last_blockhash(), genesis_block.hash()); - let t1 = SystemTransaction::new_transfer(&mint_keypair, &key1, 1, genesis_block.hash(), 0); - let t2 = SystemTransaction::new_transfer(&mint_keypair, &key2, 1, genesis_block.hash(), 0); + let t1 = system_transaction::transfer(&mint_keypair, &key1, 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()]); assert_eq!(res.len(), 2); assert_eq!(res[0], Ok(())); @@ -1051,7 +1051,7 @@ mod tests { let key2 = Pubkey::new_rand(); let bank = Bank::new(&genesis_block); 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( &[&mint_keypair], instructions, @@ -1076,7 +1076,7 @@ mod tests { let key2 = Pubkey::new_rand(); let bank = Bank::new(&genesis_block); 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( &[&mint_keypair], instructions, @@ -1098,7 +1098,7 @@ mod tests { let dest = Keypair::new(); // source with 0 program context - let tx = SystemTransaction::new_user_account( + let tx = system_transaction::create_user_account( &mint_keypair, &dest.pubkey(), 2, @@ -1217,13 +1217,8 @@ mod tests { let key1 = Keypair::new(); let key2 = Keypair::new(); - let tx = SystemTransaction::new_transfer( - &mint_keypair, - &key1.pubkey(), - 2, - genesis_block.hash(), - 0, - ); + let tx = + system_transaction::transfer(&mint_keypair, &key1.pubkey(), 2, genesis_block.hash(), 0); let initial_balance = bank.get_balance(&leader); assert_eq!(bank.process_transaction(&tx), Ok(())); 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); 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.get_balance(&leader), initial_balance + 4); assert_eq!(bank.get_balance(&key1.pubkey()), 0); @@ -1246,20 +1241,10 @@ mod tests { let mut bank = Bank::new(&genesis_block); let key = Keypair::new(); - let tx1 = SystemTransaction::new_transfer( - &mint_keypair, - &key.pubkey(), - 2, - genesis_block.hash(), - 0, - ); - let tx2 = SystemTransaction::new_transfer( - &mint_keypair, - &key.pubkey(), - 5, - genesis_block.hash(), - 0, - ); + let tx1 = + system_transaction::transfer(&mint_keypair, &key.pubkey(), 2, genesis_block.hash(), 0); + let tx2 = + system_transaction::transfer(&mint_keypair, &key.pubkey(), 5, genesis_block.hash(), 0); let results = vec![ Ok(()), @@ -1282,14 +1267,14 @@ mod tests { let (genesis_block, mint_keypair) = GenesisBlock::new(2); let bank = Bank::new(&genesis_block); let keypair = Keypair::new(); - let tx0 = SystemTransaction::new_user_account( + let tx0 = system_transaction::create_user_account( &mint_keypair, &keypair.pubkey(), 2, genesis_block.hash(), 0, ); - let tx1 = SystemTransaction::new_user_account( + let tx1 = system_transaction::create_user_account( &keypair, &mint_keypair.pubkey(), 1, @@ -1322,7 +1307,7 @@ mod tests { let alice = Keypair::new(); let bob = Keypair::new(); - let tx1 = SystemTransaction::new_user_account( + let tx1 = system_transaction::create_user_account( &mint_keypair, &alice.pubkey(), 1, @@ -1362,7 +1347,7 @@ mod tests { let keypair = Keypair::new(); let bank = Bank::new(&genesis_block); - let tx = SystemTransaction::new_transfer( + let tx = system_transaction::transfer( &mint_keypair, &keypair.pubkey(), 1, @@ -1393,7 +1378,7 @@ mod tests { bank.transfer(1, &mint_keypair, &key1.pubkey()).unwrap(); 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()]); assert_eq!(res.len(), 1); assert_eq!(bank.get_balance(&key1.pubkey()), 1); @@ -1427,13 +1412,8 @@ mod tests { let key1 = Keypair::new(); let parent = Arc::new(Bank::new(&genesis_block)); - let tx = SystemTransaction::new_transfer( - &mint_keypair, - &key1.pubkey(), - 1, - genesis_block.hash(), - 0, - ); + let tx = + system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0); assert_eq!(parent.process_transaction(&tx), Ok(())); let bank = new_from_parent(&parent); assert_eq!( @@ -1450,16 +1430,11 @@ mod tests { let key2 = Keypair::new(); let parent = Arc::new(Bank::new(&genesis_block)); - let tx = SystemTransaction::new_transfer( - &mint_keypair, - &key1.pubkey(), - 1, - genesis_block.hash(), - 0, - ); + let tx = + system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0); assert_eq!(parent.process_transaction(&tx), Ok(())); 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!(parent.get_signature_status(&tx.signatures[0]), None); } @@ -1516,13 +1491,8 @@ mod tests { let key2 = Keypair::new(); let parent = Arc::new(Bank::new(&genesis_block)); - let tx_move_mint_to_1 = SystemTransaction::new_transfer( - &mint_keypair, - &key1.pubkey(), - 1, - genesis_block.hash(), - 0, - ); + let tx_move_mint_to_1 = + system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0); trace!("parent process tx "); assert_eq!(parent.process_transaction(&tx_move_mint_to_1), Ok(())); trace!("done parent process tx "); @@ -1542,7 +1512,7 @@ mod tests { assert_eq!(bank.transaction_count(), parent.transaction_count()); 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.transaction_count(), 2); assert_eq!(parent.transaction_count(), 1); @@ -1660,7 +1630,7 @@ mod tests { let key = Keypair::new(); 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; let tx = Transaction::new_signed_instructions( @@ -1741,13 +1711,8 @@ mod tests { let (genesis_block, mint_keypair) = GenesisBlock::new(500); let bank = Arc::new(Bank::new(&genesis_block)); let key1 = Keypair::new(); - let tx_move_mint_to_1 = SystemTransaction::new_transfer( - &mint_keypair, - &key1.pubkey(), - 1, - genesis_block.hash(), - 0, - ); + let tx_move_mint_to_1 = + system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0); assert_eq!(bank.process_transaction(&tx_move_mint_to_1), Ok(())); assert_eq!(bank.is_delta.load(Ordering::Relaxed), true); } @@ -1760,13 +1725,8 @@ mod tests { assert_eq!(bank.is_votable(), false); // Set is_delta to true - let tx_move_mint_to_1 = SystemTransaction::new_transfer( - &mint_keypair, - &key1.pubkey(), - 1, - genesis_block.hash(), - 0, - ); + let tx_move_mint_to_1 = + system_transaction::transfer(&mint_keypair, &key1.pubkey(), 1, genesis_block.hash(), 0); assert_eq!(bank.process_transaction(&tx_move_mint_to_1), Ok(())); assert_eq!(bank.is_votable(), false); diff --git a/runtime/src/bank_client.rs b/runtime/src/bank_client.rs index 3390849da..2dc62caa6 100644 --- a/runtime/src/bank_client.rs +++ b/runtime/src/bank_client.rs @@ -3,7 +3,7 @@ use solana_sdk::instruction::Instruction; use solana_sdk::message::Message; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::{Keypair, KeypairUtil}; -use solana_sdk::system_instruction::SystemInstruction; +use solana_sdk::system_instruction; use solana_sdk::transaction::{Transaction, TransactionError}; pub struct BankClient<'a> { @@ -42,7 +42,7 @@ impl<'a> BankClient<'a> { keypair: &Keypair, pubkey: &Pubkey, ) -> 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) } } @@ -65,7 +65,7 @@ mod tests { // Create 2-2 Multisig Transfer instruction. 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 .accounts .push(AccountMeta::new(jane_pubkey, true)); diff --git a/runtime/src/loader_utils.rs b/runtime/src/loader_utils.rs index f200ed0e7..5b10e969a 100644 --- a/runtime/src/loader_utils.rs +++ b/runtime/src/loader_utils.rs @@ -1,10 +1,10 @@ use crate::bank_client::BankClient; use serde::Serialize; 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::signature::{Keypair, KeypairUtil}; -use solana_sdk::system_instruction::SystemInstruction; +use solana_sdk::system_instruction; pub fn load_program( bank_client: &BankClient, @@ -15,7 +15,7 @@ pub fn load_program( let program_keypair = Keypair::new(); let program_pubkey = program_keypair.pubkey(); - let instruction = SystemInstruction::new_account( + let instruction = system_instruction::create_account( &from_keypair.pubkey(), &program_pubkey, 1, @@ -30,14 +30,14 @@ pub fn load_program( let mut offset = 0; for chunk in program.chunks(chunk_size) { 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 .process_instruction(&program_keypair, instruction) .unwrap(); 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 .process_instruction(&program_keypair, instruction) .unwrap(); diff --git a/runtime/src/system_instruction_processor.rs b/runtime/src/system_instruction_processor.rs index 1aca17de9..78a345b17 100644 --- a/runtime/src/system_instruction_processor.rs +++ b/runtime/src/system_instruction_processor.rs @@ -110,7 +110,6 @@ mod tests { use solana_sdk::genesis_block::GenesisBlock; use solana_sdk::instruction::{AccountMeta, Instruction, InstructionError}; use solana_sdk::signature::{Keypair, KeypairUtil}; - use solana_sdk::system_instruction::SystemInstruction; use solana_sdk::system_program; use solana_sdk::transaction::TransactionError; diff --git a/sdk/src/fee_calculator.rs b/sdk/src/fee_calculator.rs index 3f3b10611..a60deafcf 100644 --- a/sdk/src/fee_calculator.rs +++ b/sdk/src/fee_calculator.rs @@ -21,7 +21,7 @@ impl FeeCalculator { mod tests { use super::*; use crate::pubkey::Pubkey; - use crate::system_instruction::SystemInstruction; + use crate::system_instruction; #[test] fn test_fee_calculator_calculate_fee() { @@ -35,13 +35,13 @@ mod tests { // One signature, a fee. let pubkey0 = Pubkey::new(&[0; 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]); assert_eq!(FeeCalculator::new(2).calculate_fee(&message), 2); // Two signatures, double the fee. - let ix0 = SystemInstruction::new_transfer(&pubkey0, &pubkey1, 1); - let ix1 = SystemInstruction::new_transfer(&pubkey1, &pubkey0, 1); + let ix0 = system_instruction::transfer(&pubkey0, &pubkey1, 1); + let ix1 = system_instruction::transfer(&pubkey1, &pubkey0, 1); let message = Message::new(vec![ix0, ix1]); assert_eq!(FeeCalculator::new(2).calculate_fee(&message), 4); } diff --git a/sdk/src/loader_instruction.rs b/sdk/src/loader_instruction.rs index f020474a5..831ee51ba 100644 --- a/sdk/src/loader_instruction.rs +++ b/sdk/src/loader_instruction.rs @@ -20,23 +20,16 @@ pub enum LoaderInstruction { Finalize, } -impl LoaderInstruction { - pub fn new_write( - account_id: &Pubkey, - program_id: &Pubkey, - offset: u32, - bytes: Vec, - ) -> Instruction { - let account_metas = vec![AccountMeta::new(*account_id, true)]; - Instruction::new( - *program_id, - &LoaderInstruction::Write { offset, bytes }, - 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) - } +pub fn write(account_id: &Pubkey, program_id: &Pubkey, offset: u32, bytes: Vec) -> Instruction { + let account_metas = vec![AccountMeta::new(*account_id, true)]; + Instruction::new( + *program_id, + &LoaderInstruction::Write { offset, bytes }, + account_metas, + ) +} + +pub fn 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) } diff --git a/sdk/src/system_instruction.rs b/sdk/src/system_instruction.rs index 807d741dc..d9ef0ba5b 100644 --- a/sdk/src/system_instruction.rs +++ b/sdk/src/system_instruction.rs @@ -31,65 +31,63 @@ pub enum SystemInstruction { Transfer { lamports: u64 }, } -impl SystemInstruction { - pub fn new_account( - from_id: &Pubkey, - to_id: &Pubkey, - lamports: u64, - space: u64, - program_id: &Pubkey, - ) -> Instruction { - let account_metas = vec![ - AccountMeta::new(*from_id, true), - AccountMeta::new(*to_id, false), - ]; - Instruction::new( - system_program::id(), - &SystemInstruction::CreateAccount { - lamports, - space, - program_id: *program_id, - }, - account_metas, - ) - } +pub fn create_account( + from_id: &Pubkey, + to_id: &Pubkey, + lamports: u64, + space: u64, + program_id: &Pubkey, +) -> Instruction { + let account_metas = vec![ + AccountMeta::new(*from_id, true), + AccountMeta::new(*to_id, false), + ]; + Instruction::new( + system_program::id(), + &SystemInstruction::CreateAccount { + lamports, + space, + program_id: *program_id, + }, + account_metas, + ) +} - /// Create and sign a transaction to create a system account - pub fn new_user_account(from_id: &Pubkey, to_id: &Pubkey, lamports: u64) -> Instruction { - let program_id = system_program::id(); - Self::new_account(from_id, to_id, lamports, 0, &program_id) - } +/// Create and sign a transaction to create a system account +pub fn create_user_account(from_id: &Pubkey, to_id: &Pubkey, lamports: u64) -> Instruction { + let program_id = system_program::id(); + create_account(from_id, to_id, lamports, 0, &program_id) +} - pub fn new_assign(from_id: &Pubkey, program_id: &Pubkey) -> Instruction { - let account_metas = vec![AccountMeta::new(*from_id, true)]; - Instruction::new( - system_program::id(), - &SystemInstruction::Assign { - program_id: *program_id, - }, - account_metas, - ) - } +pub fn assign(from_id: &Pubkey, program_id: &Pubkey) -> Instruction { + let account_metas = vec![AccountMeta::new(*from_id, true)]; + Instruction::new( + system_program::id(), + &SystemInstruction::Assign { + program_id: *program_id, + }, + account_metas, + ) +} - pub fn new_transfer(from_id: &Pubkey, to_id: &Pubkey, lamports: u64) -> Instruction { - let account_metas = vec![ - AccountMeta::new(*from_id, true), - AccountMeta::new(*to_id, false), - ]; - Instruction::new( - system_program::id(), - &SystemInstruction::Transfer { lamports }, - account_metas, - ) - } +pub fn transfer(from_id: &Pubkey, to_id: &Pubkey, lamports: u64) -> Instruction { + let account_metas = vec![ + AccountMeta::new(*from_id, true), + AccountMeta::new(*to_id, false), + ]; + Instruction::new( + system_program::id(), + &SystemInstruction::Transfer { lamports }, + account_metas, + ) +} - /// Create and sign new SystemInstruction::Transfer transaction to many destinations - pub fn new_transfer_many(from_id: &Pubkey, to_lamports: &[(Pubkey, u64)]) -> Vec { - to_lamports - .iter() - .map(|(to_id, lamports)| SystemInstruction::new_transfer(from_id, to_id, *lamports)) - .collect() - } +/// Create and sign new SystemInstruction::Transfer transaction to many destinations +pub fn transfer_many(from_id: &Pubkey, to_lamports: &[(Pubkey, u64)]) -> Vec { + to_lamports + .iter() + .map(|(to_id, lamports)| transfer(from_id, to_id, *lamports)) + .collect() } #[cfg(test)] @@ -107,7 +105,7 @@ mod tests { let carol_pubkey = Pubkey::new_rand(); 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!(get_keys(&instructions[0]), vec![alice_pubkey, bob_pubkey]); assert_eq!(get_keys(&instructions[1]), vec![alice_pubkey, carol_pubkey]); diff --git a/sdk/src/system_transaction.rs b/sdk/src/system_transaction.rs index 892900da6..66c75f549 100644 --- a/sdk/src/system_transaction.rs +++ b/sdk/src/system_transaction.rs @@ -3,74 +3,70 @@ use crate::hash::Hash; use crate::pubkey::Pubkey; use crate::signature::{Keypair, KeypairUtil}; -use crate::system_instruction::SystemInstruction; +use crate::system_instruction; use crate::system_program; use crate::transaction::Transaction; -pub struct SystemTransaction {} - -impl SystemTransaction { - /// Create and sign new SystemInstruction::CreateAccount transaction - pub fn new_account( - from_keypair: &Keypair, - to: &Pubkey, - recent_blockhash: Hash, - lamports: u64, - space: u64, - program_id: &Pubkey, - _fee: u64, - ) -> Transaction { - let from_pubkey = from_keypair.pubkey(); - let create_instruction = - 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 new_user_account( - from_keypair: &Keypair, - to: &Pubkey, - lamports: u64, - recent_blockhash: Hash, - fee: u64, - ) -> Transaction { - let program_id = system_program::id(); - Self::new_account( - from_keypair, - to, - recent_blockhash, - lamports, - 0, - &program_id, - fee, - ) - } - - /// Create and sign new SystemInstruction::Assign transaction - pub fn new_assign( - from_keypair: &Keypair, - recent_blockhash: Hash, - program_id: &Pubkey, - _fee: u64, - ) -> Transaction { - let from_pubkey = from_keypair.pubkey(); - 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 SystemInstruction::Transfer transaction - pub fn new_transfer( - from_keypair: &Keypair, - to: &Pubkey, - lamports: u64, - recent_blockhash: Hash, - _fee: u64, - ) -> Transaction { - let from_pubkey = from_keypair.pubkey(); - let move_instruction = SystemInstruction::new_transfer(&from_pubkey, to, lamports); - let instructions = vec![move_instruction]; - Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash) - } +/// Create and sign new SystemInstruction::CreateAccount transaction +pub fn create_account( + from_keypair: &Keypair, + to: &Pubkey, + recent_blockhash: Hash, + lamports: u64, + space: u64, + program_id: &Pubkey, + _fee: u64, +) -> Transaction { + let from_pubkey = from_keypair.pubkey(); + let create_instruction = + system_instruction::create_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, + to: &Pubkey, + lamports: u64, + recent_blockhash: Hash, + fee: u64, +) -> Transaction { + let program_id = system_program::id(); + create_account( + from_keypair, + to, + recent_blockhash, + lamports, + 0, + &program_id, + fee, + ) +} + +/// Create and sign new system_instruction::Assign transaction +pub fn assign( + from_keypair: &Keypair, + recent_blockhash: Hash, + program_id: &Pubkey, + _fee: u64, +) -> Transaction { + let from_pubkey = from_keypair.pubkey(); + let assign_instruction = system_instruction::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, + to: &Pubkey, + lamports: u64, + recent_blockhash: Hash, + _fee: u64, +) -> Transaction { + let from_pubkey = from_keypair.pubkey(); + let move_instruction = system_instruction::transfer(&from_pubkey, to, lamports); + let instructions = vec![move_instruction]; + Transaction::new_signed_instructions(&[from_keypair], instructions, recent_blockhash) } diff --git a/sdk/src/transaction.rs b/sdk/src/transaction.rs index f9c3e3325..a65f517ed 100644 --- a/sdk/src/transaction.rs +++ b/sdk/src/transaction.rs @@ -200,7 +200,7 @@ mod tests { use super::*; use crate::instruction::AccountMeta; use crate::signature::Keypair; - use crate::system_instruction::SystemInstruction; + use crate::system_instruction; use bincode::{deserialize, serialize, serialized_size}; use std::mem::size_of; @@ -321,7 +321,7 @@ mod tests { let alice_keypair = Keypair::new(); let alice_pubkey = alice_keypair.pubkey(); 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::() + size_of::(); assert_eq!(expected_data_size, 12); diff --git a/tests/thin_client.rs b/tests/thin_client.rs index 37372c510..7091028ed 100644 --- a/tests/thin_client.rs +++ b/tests/thin_client.rs @@ -10,7 +10,7 @@ use solana_sdk::hash::Hash; use solana_sdk::pubkey::Pubkey; use solana_sdk::signature::{Keypair, KeypairUtil, Signature}; 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_state::VoteState; use std::fs::remove_dir_all; @@ -32,7 +32,7 @@ pub fn transfer( to, 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) } @@ -76,15 +76,15 @@ fn test_bad_sig() { 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 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(); - if let SystemInstruction::Transfer { ref mut lamports } = instruction2 { + if let system_instruction::Transfer { ref mut lamports } = instruction2 { *lamports = 502; } tr2.instructions[0].data = serialize(&instruction2).unwrap(); @@ -125,7 +125,7 @@ fn test_register_vote_account() { let blockhash = client.get_recent_blockhash().unwrap(); 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 = Transaction::new_signed_instructions(&[&validator_keypair], instructions, blockhash); let signature = client.transfer_signed(&transaction).unwrap(); diff --git a/wallet/src/wallet.rs b/wallet/src/wallet.rs index 45076da64..3a436f152 100644 --- a/wallet/src/wallet.rs +++ b/wallet/src/wallet.rs @@ -5,7 +5,7 @@ use log::*; use serde_json; use serde_json::json; 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}; #[cfg(not(test))] 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_sdk::bpf_loader; use solana_sdk::hash::Hash; -use solana_sdk::loader_instruction::LoaderInstruction; +use solana_sdk::loader_instruction; use solana_sdk::pubkey::Pubkey; use solana_sdk::rpc_port::DEFAULT_RPC_PORT; 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_vote_api::vote_instruction::VoteInstruction; +use solana_vote_api::vote_instruction; use std::fs::File; use std::io::Read; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; @@ -333,13 +333,13 @@ fn process_configure_staking( let recent_blockhash = rpc_client.get_recent_blockhash()?; let mut ixs = vec![]; if let Some(delegate_id) = delegate_option { - ixs.push(VoteInstruction::new_delegate_stake( + ixs.push(vote_instruction::delegate_stake( &config.keypair.pubkey(), &delegate_id, )); } if let Some(authorized_voter_id) = authorized_voter_option { - ixs.push(VoteInstruction::new_authorize_voter( + ixs.push(vote_instruction::authorize_voter( &config.keypair.pubkey(), &authorized_voter_id, )); @@ -356,7 +356,8 @@ fn process_create_staking( lamports: u64, ) -> ProcessResult { 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 signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &config.keypair)?; 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, &program_id.pubkey(), blockhash, @@ -411,7 +412,7 @@ fn process_deploy( .chunks(USERDATA_CHUNK_SIZE) .zip(0..) .map(|(chunk, i)| { - let instruction = LoaderInstruction::new_write( + let instruction = loader_instruction::write( &program_id.pubkey(), &bpf_loader::id(), (i * USERDATA_CHUNK_SIZE) as u32, @@ -423,7 +424,7 @@ fn process_deploy( rpc_client.send_and_confirm_transactions(write_transactions, &program_id)?; 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); rpc_client .send_and_confirm_transaction(&mut tx, &program_id) @@ -450,7 +451,7 @@ fn process_pay( let blockhash = rpc_client.get_recent_blockhash()?; 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)?; Ok(signature_str.to_string()) } else if *witnesses == None { @@ -463,7 +464,7 @@ fn process_pay( let contract_state = Keypair::new(); // Initializing contract - let ixs = BudgetInstruction::new_on_date( + let ixs = budget_instruction::on_date( &config.keypair.pubkey(), to, &contract_state.pubkey(), @@ -494,7 +495,7 @@ fn process_pay( let contract_state = Keypair::new(); // Initializing contract - let ixs = BudgetInstruction::new_when_signed( + let ixs = budget_instruction::when_signed( &config.keypair.pubkey(), to, &contract_state.pubkey(), @@ -517,7 +518,7 @@ fn process_pay( fn process_cancel(rpc_client: &RpcClient, config: &WalletConfig, pubkey: &Pubkey) -> ProcessResult { let blockhash = rpc_client.get_recent_blockhash()?; - let ix = BudgetInstruction::new_apply_signature( + let ix = budget_instruction::apply_signature( &config.keypair.pubkey(), pubkey, &config.keypair.pubkey(), @@ -548,7 +549,7 @@ fn process_time_elapsed( 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 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 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 signature_str = rpc_client.send_and_confirm_transaction(&mut tx, &config.keypair)?;