From ca2ac1e5ea9a404941b970a09db585cd2ac7f005 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Tue, 26 Mar 2019 16:26:30 -0600 Subject: [PATCH] Remove a mostly unused Transaction constructor --- runtime/src/bank.rs | 13 ++++++------- sdk/src/transaction.rs | 39 ++++++++++----------------------------- 2 files changed, 16 insertions(+), 36 deletions(-) diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index e26a606c02..87d8180110 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -930,7 +930,6 @@ mod tests { use solana_sdk::instruction::InstructionError; use solana_sdk::signature::{Keypair, KeypairUtil}; use solana_sdk::system_instruction::SystemInstruction; - use solana_sdk::system_program; use solana_sdk::system_transaction::SystemTransaction; #[test] @@ -1578,13 +1577,13 @@ mod tests { let bank = Arc::new(Bank::new(&genesis_block)); let key = Keypair::new(); - let move_lamports = SystemInstruction::Move { lamports: 1 }; + let mut move_instruction = + SystemInstruction::new_move(&mint_keypair.pubkey(), &key.pubkey(), 1); + move_instruction.accounts[0].is_signer = false; - let mut tx = Transaction::new_with_blockhash_and_fee( - &mint_keypair.pubkey(), - &[key.pubkey()], - &system_program::id(), - &move_lamports, + let mut tx = Transaction::new_signed_instructions( + &Vec::<&Keypair>::new(), + vec![move_instruction], bank.last_blockhash(), 2, ); diff --git a/sdk/src/transaction.rs b/sdk/src/transaction.rs index ebe2e56c84..151d540f0b 100644 --- a/sdk/src/transaction.rs +++ b/sdk/src/transaction.rs @@ -72,7 +72,7 @@ pub struct Transaction { } impl Transaction { - fn new_with_message(message: Message) -> Self { + fn new_unsigned_message(message: Message) -> Self { Self { signatures: Vec::with_capacity(message.num_signatures as usize), account_keys: message.account_keys, @@ -85,7 +85,7 @@ impl Transaction { pub fn new(instructions: Vec) -> Self { let message = Message::new(instructions); - Self::new_with_message(message) + Self::new_unsigned_message(message) } pub fn new_signed_instructions( @@ -100,25 +100,6 @@ impl Transaction { tx } - pub fn new_with_blockhash_and_fee( - from_pubkey: &Pubkey, - transaction_keys: &[Pubkey], - program_id: &Pubkey, - data: &T, - recent_blockhash: Hash, - fee: u64, - ) -> Self { - let mut account_metas = vec![AccountMeta::new(*from_pubkey, true)]; - for pubkey in transaction_keys { - account_metas.push(AccountMeta::new(*pubkey, false)); - } - let instruction = Instruction::new(*program_id, data, account_metas); - let mut transaction = Self::new(vec![instruction]); - transaction.fee = fee; - transaction.recent_blockhash = recent_blockhash; - transaction - } - pub fn new_signed( from_keypair: &T, transaction_keys: &[Pubkey], @@ -127,14 +108,14 @@ impl Transaction { recent_blockhash: Hash, fee: u64, ) -> Self { - let mut transaction = Self::new_with_blockhash_and_fee( - &from_keypair.pubkey(), - transaction_keys, - program_id, - data, - Hash::default(), - fee, - ); + let mut account_metas = vec![AccountMeta::new(from_keypair.pubkey(), true)]; + for pubkey in transaction_keys { + account_metas.push(AccountMeta::new(*pubkey, false)); + } + let instruction = Instruction::new(*program_id, data, account_metas); + let mut transaction = Self::new(vec![instruction]); + transaction.fee = fee; + transaction.recent_blockhash = recent_blockhash; transaction.sign(&[from_keypair], recent_blockhash); transaction }