Make it unappealing to build and sign transactions at the same time

Use a client to sign transactions. It'll need that keypair anyway
to resign new blockhashes on retries.
This commit is contained in:
Greg Fitzgerald
2019-03-14 16:10:53 -06:00
parent f8bf9ca218
commit 4d53be8350
6 changed files with 86 additions and 70 deletions

View File

@@ -28,7 +28,7 @@ impl BudgetTransaction {
) -> Transaction {
let from = from_keypair.pubkey();
let space = serialized_size(&BudgetState::new(expr.clone())).unwrap();
TransactionBuilder::new(fee)
let mut tx = TransactionBuilder::new(fee)
.push(SystemInstruction::new_program_account(
&from,
contract,
@@ -37,7 +37,10 @@ impl BudgetTransaction {
&id(),
))
.push(BudgetInstruction::new_initialize_account(contract, expr))
.sign(&[from_keypair], recent_blockhash)
.compile();
tx.sign(&[from_keypair], recent_blockhash);
tx
}
/// Create and sign a new Transaction. Used for unit-testing.
@@ -69,11 +72,13 @@ impl BudgetTransaction {
recent_blockhash: Hash,
) -> Transaction {
let from = from_keypair.pubkey();
TransactionBuilder::default()
let mut tx = TransactionBuilder::default()
.push(BudgetInstruction::new_apply_timestamp(
&from, contract, to, dt,
))
.sign(&[from_keypair], recent_blockhash)
.compile();
tx.sign(&[from_keypair], recent_blockhash);
tx
}
/// Create and sign a new Witness Signature. Used for unit-testing.
@@ -84,9 +89,11 @@ impl BudgetTransaction {
recent_blockhash: Hash,
) -> Transaction {
let from = from_keypair.pubkey();
TransactionBuilder::default()
let mut tx = TransactionBuilder::default()
.push(BudgetInstruction::new_apply_signature(&from, contract, to))
.sign(&[from_keypair], recent_blockhash)
.compile();
tx.sign(&[from_keypair], recent_blockhash);
tx
}
/// Create and sign a postdated Transaction. Used for unit-testing.

View File

@@ -40,11 +40,13 @@ impl RewardsTransaction {
fee: u64,
) -> Transaction {
let vote_id = vote_keypair.pubkey();
TransactionBuilder::new(fee)
let mut tx = TransactionBuilder::new(fee)
.push(RewardsInstruction::new_redeem_vote_credits(
&vote_id, rewards_id,
))
.push(VoteInstruction::new_clear_credits(&vote_id))
.sign(&[vote_keypair], blockhash)
.compile();
tx.sign(&[vote_keypair], blockhash);
tx
}
}

View File

@@ -22,9 +22,11 @@ impl VoteTransaction {
fee: u64,
) -> Transaction {
let vote = Vote { slot };
TransactionBuilder::new(fee)
let mut tx = TransactionBuilder::new(fee)
.push(VoteInstruction::new_vote(staking_account, vote))
.sign(&[authorized_voter_keypair], recent_blockhash)
.compile();
tx.sign(&[authorized_voter_keypair], recent_blockhash);
tx
}
/// Fund or create the staking account with lamports
@@ -37,7 +39,7 @@ impl VoteTransaction {
) -> Transaction {
let from_id = from_keypair.pubkey();
let space = VoteState::max_size() as u64;
TransactionBuilder::new(fee)
let mut tx = TransactionBuilder::new(fee)
.push(SystemInstruction::new_program_account(
&from_id,
staker_id,
@@ -46,7 +48,9 @@ impl VoteTransaction {
&id(),
))
.push(VoteInstruction::new_initialize_account(staker_id))
.sign(&[from_keypair], recent_blockhash)
.compile();
tx.sign(&[from_keypair], recent_blockhash);
tx
}
/// Fund or create the staking account with lamports
@@ -61,7 +65,7 @@ impl VoteTransaction {
let from_id = from_keypair.pubkey();
let voter_id = voter_keypair.pubkey();
let space = VoteState::max_size() as u64;
TransactionBuilder::new(fee)
let mut tx = TransactionBuilder::new(fee)
.push(SystemInstruction::new_program_account(
&from_id,
&voter_id,
@@ -71,7 +75,9 @@ impl VoteTransaction {
))
.push(VoteInstruction::new_initialize_account(&voter_id))
.push(VoteInstruction::new_delegate_stake(&voter_id, &delegate_id))
.sign(&[from_keypair, voter_keypair], recent_blockhash)
.compile();
tx.sign(&[from_keypair, voter_keypair], recent_blockhash);
tx
}
/// Choose a voter id to accept signed votes from
@@ -81,12 +87,14 @@ impl VoteTransaction {
authorized_voter_id: &Pubkey,
fee: u64,
) -> Transaction {
TransactionBuilder::new(fee)
let mut tx = TransactionBuilder::new(fee)
.push(VoteInstruction::new_authorize_voter(
&vote_keypair.pubkey(),
authorized_voter_id,
))
.sign(&[vote_keypair], recent_blockhash)
.compile();
tx.sign(&[vote_keypair], recent_blockhash);
tx
}
/// Choose a node id to `delegate` or `assign` this vote account to
@@ -96,12 +104,14 @@ impl VoteTransaction {
node_id: &Pubkey,
fee: u64,
) -> Transaction {
TransactionBuilder::new(fee)
let mut tx = TransactionBuilder::new(fee)
.push(VoteInstruction::new_delegate_stake(
&vote_keypair.pubkey(),
node_id,
))
.sign(&[vote_keypair], recent_blockhash)
.compile();
tx.sign(&[vote_keypair], recent_blockhash);
tx
}
fn get_vote(tx: &Transaction, ix_index: usize) -> Option<(Pubkey, Vote, Hash)> {