Remove fee-payer guesswork from Message and Transaction (#10776)
* Make Message::new_with_payer the default constructor * Remove Transaction::new_[un]signed_instructions These guess the fee-payer instead of stating it explicitly
This commit is contained in:
@ -308,7 +308,6 @@ mod bpf {
|
||||
result.unwrap_err().unwrap(),
|
||||
TransactionError::InstructionError(0, InstructionError::MaxSeedLengthExceeded)
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -364,10 +363,12 @@ mod bpf {
|
||||
let derived_key2 =
|
||||
Pubkey::create_program_address(&[b"Lil'", b"Bits"], &invoked_program_id).unwrap();
|
||||
let derived_key3 =
|
||||
Pubkey::create_program_address(&[derived_key2.as_ref()], &invoked_program_id).unwrap();
|
||||
Pubkey::create_program_address(&[derived_key2.as_ref()], &invoked_program_id)
|
||||
.unwrap();
|
||||
|
||||
let mint_pubkey = mint_keypair.pubkey();
|
||||
let account_metas = vec![
|
||||
AccountMeta::new(mint_keypair.pubkey(), true),
|
||||
AccountMeta::new(mint_pubkey, true),
|
||||
AccountMeta::new(argument_keypair.pubkey(), true),
|
||||
AccountMeta::new_readonly(invoked_program_id, false),
|
||||
AccountMeta::new(invoked_argument_keypair.pubkey(), true),
|
||||
@ -384,7 +385,7 @@ mod bpf {
|
||||
|
||||
let instruction =
|
||||
Instruction::new(invoke_program_id, &TEST_SUCCESS, account_metas.clone());
|
||||
let message = Message::new(&[instruction]);
|
||||
let message = Message::new(&[instruction], Some(&mint_pubkey));
|
||||
assert!(bank_client
|
||||
.send_message(
|
||||
&[
|
||||
@ -404,7 +405,7 @@ mod bpf {
|
||||
&TEST_PRIVILEGE_ESCALATION_SIGNER,
|
||||
account_metas.clone(),
|
||||
);
|
||||
let message = Message::new(&[instruction]);
|
||||
let message = Message::new(&[instruction], Some(&mint_pubkey));
|
||||
assert_eq!(
|
||||
bank_client
|
||||
.send_message(
|
||||
@ -426,7 +427,7 @@ mod bpf {
|
||||
&TEST_PRIVILEGE_ESCALATION_WRITABLE,
|
||||
account_metas.clone(),
|
||||
);
|
||||
let message = Message::new(&[instruction]);
|
||||
let message = Message::new(&[instruction], Some(&mint_pubkey));
|
||||
assert_eq!(
|
||||
bank_client
|
||||
.send_message(
|
||||
|
@ -774,7 +774,7 @@ fn call<'a>(
|
||||
ro_regions,
|
||||
)?;
|
||||
verify_instruction(syscall, &instruction, &signers)?;
|
||||
let message = Message::new_with_payer(&[instruction], None);
|
||||
let message = Message::new(&[instruction], None);
|
||||
let callee_program_id_index = message.instructions[0].program_id_index as usize;
|
||||
let callee_program_id = message.account_keys[callee_program_id_index];
|
||||
let (accounts, refs) = syscall.translate_accounts(
|
||||
|
@ -256,7 +256,7 @@ mod tests {
|
||||
budget_instruction::payment(&alice_pubkey, &bob_pubkey, &budget_pubkey, 1);
|
||||
instructions[1].accounts = vec![]; // <!-- Attack! Prevent accounts from being passed into processor.
|
||||
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||
assert_eq!(
|
||||
bank_client
|
||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||
@ -276,7 +276,7 @@ mod tests {
|
||||
let budget_pubkey = budget_keypair.pubkey();
|
||||
let instructions =
|
||||
budget_instruction::payment(&alice_pubkey, &bob_pubkey, &budget_pubkey, 100);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||
bank_client
|
||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||
.unwrap();
|
||||
@ -302,7 +302,7 @@ mod tests {
|
||||
None,
|
||||
1,
|
||||
);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||
bank_client
|
||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||
.unwrap();
|
||||
@ -315,7 +315,7 @@ mod tests {
|
||||
.unwrap();
|
||||
let instruction =
|
||||
budget_instruction::apply_signature(&mallory_pubkey, &budget_pubkey, &bob_pubkey);
|
||||
let mut message = Message::new(&[instruction]);
|
||||
let mut message = Message::new(&[instruction], Some(&mallory_pubkey));
|
||||
|
||||
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
||||
message.account_keys.insert(3, alice_pubkey);
|
||||
@ -352,7 +352,7 @@ mod tests {
|
||||
None,
|
||||
1,
|
||||
);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||
bank_client
|
||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||
.unwrap();
|
||||
@ -365,7 +365,7 @@ mod tests {
|
||||
.unwrap();
|
||||
let instruction =
|
||||
budget_instruction::apply_timestamp(&mallory_pubkey, &budget_pubkey, &bob_pubkey, dt);
|
||||
let mut message = Message::new(&[instruction]);
|
||||
let mut message = Message::new(&[instruction], Some(&mallory_pubkey));
|
||||
|
||||
// Attack! Part 2: Point the instruction to the expected, but unsigned, key.
|
||||
message.account_keys.insert(3, alice_pubkey);
|
||||
@ -402,7 +402,7 @@ mod tests {
|
||||
None,
|
||||
1,
|
||||
);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||
bank_client
|
||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||
.unwrap();
|
||||
@ -472,7 +472,7 @@ mod tests {
|
||||
Some(alice_pubkey),
|
||||
1,
|
||||
);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||
bank_client
|
||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||
.unwrap();
|
||||
@ -550,7 +550,7 @@ mod tests {
|
||||
game_hash,
|
||||
41,
|
||||
);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&alice_pubkey));
|
||||
bank_client
|
||||
.send_message(&[&alice_keypair, &budget_keypair], message)
|
||||
.unwrap();
|
||||
@ -570,7 +570,7 @@ mod tests {
|
||||
|
||||
// Anyone can sign the message, but presumably it's Bob, since he's the
|
||||
// one claiming the payout.
|
||||
let message = Message::new_with_payer(&[instruction], Some(&bob_pubkey));
|
||||
let message = Message::new(&[instruction], Some(&bob_pubkey));
|
||||
bank_client.send_message(&[&bob_keypair], message).unwrap();
|
||||
|
||||
assert_eq!(bank_client.get_balance(&alice_pubkey).unwrap(), 0);
|
||||
|
@ -604,7 +604,10 @@ mod test {
|
||||
);
|
||||
|
||||
client
|
||||
.send_message(&[owner, &new], Message::new(&[instruction]))
|
||||
.send_message(
|
||||
&[owner, &new],
|
||||
Message::new(&[instruction], Some(&owner.pubkey())),
|
||||
)
|
||||
.unwrap_or_else(|_| panic!("{}:{}", line!(), file!()));
|
||||
new.pubkey()
|
||||
}
|
||||
|
@ -30,11 +30,14 @@ pub fn create_genesis<T: Client>(from: &Keypair, client: &T, amount: u64) -> Key
|
||||
);
|
||||
|
||||
client
|
||||
.send_message(&[&from, &genesis], Message::new(&[instruction]))
|
||||
.send_message(
|
||||
&[&from, &genesis],
|
||||
Message::new(&[instruction], Some(&from.pubkey())),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let instruction = librapay_instruction::genesis(&genesis.pubkey(), amount);
|
||||
let message = Message::new_with_payer(&[instruction], Some(&from.pubkey()));
|
||||
let message = Message::new(&[instruction], Some(&from.pubkey()));
|
||||
client.send_message(&[from, &genesis], message).unwrap();
|
||||
|
||||
genesis
|
||||
|
@ -8,6 +8,7 @@ use solana_sdk::{
|
||||
client::Client,
|
||||
commitment_config::CommitmentConfig,
|
||||
hash::Hash,
|
||||
message::Message,
|
||||
pubkey::Pubkey,
|
||||
signature::{Keypair, Signer},
|
||||
system_instruction,
|
||||
@ -87,7 +88,8 @@ pub fn create_accounts(
|
||||
|
||||
let mut from_signers = vec![from_keypair];
|
||||
from_signers.extend_from_slice(to_keypair);
|
||||
Transaction::new_signed_instructions(&from_signers, &instructions, recent_blockhash)
|
||||
let message = Message::new(&instructions, Some(&from_keypair.pubkey()));
|
||||
Transaction::new(&from_signers, message, recent_blockhash)
|
||||
}
|
||||
|
||||
pub fn create_account(
|
||||
|
@ -93,7 +93,7 @@ mod tests {
|
||||
owner_pubkey,
|
||||
lamports,
|
||||
);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&payer_keypair.pubkey()));
|
||||
bank_client.send_message(&[payer_keypair, account_keypair], message)
|
||||
}
|
||||
|
||||
@ -109,7 +109,7 @@ mod tests {
|
||||
&old_owner_keypair.pubkey(),
|
||||
new_owner_pubkey,
|
||||
);
|
||||
let message = Message::new_with_payer(&[instruction], Some(&payer_keypair.pubkey()));
|
||||
let message = Message::new(&[instruction], Some(&payer_keypair.pubkey()));
|
||||
bank_client.send_message(&[payer_keypair, old_owner_keypair], message)
|
||||
}
|
||||
|
||||
|
@ -183,7 +183,7 @@ mod tests {
|
||||
date_instruction::create_account(&payer_keypair.pubkey(), &date_pubkey, 1);
|
||||
instructions.push(date_instruction::store(&date_pubkey, date));
|
||||
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&payer_keypair.pubkey()));
|
||||
bank_client.send_message(&[payer_keypair, date_keypair], message)
|
||||
}
|
||||
|
||||
@ -195,7 +195,7 @@ mod tests {
|
||||
) -> Result<Signature> {
|
||||
let date_pubkey = date_keypair.pubkey();
|
||||
let instruction = date_instruction::store(&date_pubkey, date);
|
||||
let message = Message::new_with_payer(&[instruction], Some(&payer_keypair.pubkey()));
|
||||
let message = Message::new(&[instruction], Some(&payer_keypair.pubkey()));
|
||||
bank_client.send_message(&[payer_keypair, date_keypair], message)
|
||||
}
|
||||
|
||||
@ -218,7 +218,7 @@ mod tests {
|
||||
&date_pubkey,
|
||||
lamports,
|
||||
);
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&payer_keypair.pubkey()));
|
||||
bank_client.send_message(&[payer_keypair, contract_keypair], message)
|
||||
}
|
||||
|
||||
@ -253,7 +253,7 @@ mod tests {
|
||||
) -> Result<Signature> {
|
||||
let instruction =
|
||||
vest_instruction::redeem_tokens(&contract_pubkey, &date_pubkey, &payee_pubkey);
|
||||
let message = Message::new_with_payer(&[instruction], Some(&payer_keypair.pubkey()));
|
||||
let message = Message::new(&[instruction], Some(&payer_keypair.pubkey()));
|
||||
bank_client.send_message(&[payer_keypair], message)
|
||||
}
|
||||
|
||||
@ -349,7 +349,7 @@ mod tests {
|
||||
);
|
||||
instructions[1].accounts = vec![]; // <!-- Attack! Prevent accounts from being passed into processor.
|
||||
|
||||
let message = Message::new(&instructions);
|
||||
let message = Message::new(&instructions, Some(&alice_keypair.pubkey()));
|
||||
assert_eq!(
|
||||
bank_client
|
||||
.send_message(&[&alice_keypair, &contract_keypair], message)
|
||||
|
Reference in New Issue
Block a user