Label tuple with AccountMeta

This commit is contained in:
Greg Fitzgerald
2019-03-19 13:03:20 -06:00
parent 7246d72f03
commit a4652a9aaf
10 changed files with 83 additions and 68 deletions

View File

@@ -100,7 +100,11 @@ impl<P, Q> GenericInstruction<P, Q> {
}
}
pub type Instruction = GenericInstruction<Pubkey, (Pubkey, bool)>;
/// An account's pubkey and a Boolean that is true if an Instruciton
/// requires a Transaction signature corresponding to this key.
pub struct AccountMeta(pub Pubkey, pub bool);
pub type Instruction = GenericInstruction<Pubkey, AccountMeta>;
pub type CompiledInstruction = GenericInstruction<u8, u8>;
impl CompiledInstruction {
@@ -209,9 +213,9 @@ impl Transaction {
recent_blockhash: Hash,
fee: u64,
) -> Self {
let mut account_keys = vec![(*from_pubkey, true)];
let mut account_keys = vec![AccountMeta(*from_pubkey, true)];
for pubkey in transaction_keys {
account_keys.push((*pubkey, false));
account_keys.push(AccountMeta(*pubkey, false));
}
let instruction = Instruction::new(*program_id, data, account_keys);
let mut transaction = Self::new(vec![instruction]);
@@ -705,8 +709,8 @@ mod tests {
let program_id = Pubkey::default();
let keypair0 = Keypair::new();
let id0 = keypair0.pubkey();
Transaction::new(vec![Instruction::new(program_id, &0, vec![(id0, true)])])
.sign(&Vec::<&Keypair>::new(), Hash::default());
let ix = Instruction::new(program_id, &0, vec![AccountMeta(id0, true)]);
Transaction::new(vec![ix]).sign(&Vec::<&Keypair>::new(), Hash::default());
}
#[test]
@@ -715,12 +719,8 @@ mod tests {
let program_id = Pubkey::default();
let keypair0 = Keypair::new();
let wrong_id = Pubkey::default();
Transaction::new(vec![Instruction::new(
program_id,
&0,
vec![(wrong_id, true)],
)])
.sign(&[&keypair0], Hash::default());
let ix = Instruction::new(program_id, &0, vec![AccountMeta(wrong_id, true)]);
Transaction::new(vec![ix]).sign(&[&keypair0], Hash::default());
}
#[test]
@@ -728,7 +728,8 @@ mod tests {
let program_id = Pubkey::default();
let keypair0 = Keypair::new();
let id0 = keypair0.pubkey();
let mut tx = Transaction::new(vec![Instruction::new(program_id, &0, vec![(id0, true)])]);
let ix = Instruction::new(program_id, &0, vec![AccountMeta(id0, true)]);
let mut tx = Transaction::new(vec![ix]);
tx.sign(&[&keypair0], Hash::default());
assert_eq!(tx.instructions[0], CompiledInstruction::new(0, &0, vec![0]));
}