Change signed_key to index into account_keys

If index is within the signed keys range.
This commit is contained in:
Stephen Akridge 2018-11-14 21:38:12 -08:00 committed by Michael Vines
parent e048116ab2
commit 7dd198a99e
1 changed files with 18 additions and 17 deletions

View File

@ -129,8 +129,12 @@ impl Transaction {
pub fn signed_key(&self, instruction_index: usize, accounts_index: usize) -> Option<&Pubkey> {
match self.key_index(instruction_index, accounts_index) {
None => None,
Some(0) => self.account_keys.get(0),
Some(_) => None,
Some(signature_index) => {
if signature_index >= self.signatures.len() {
return None;
}
self.account_keys.get(signature_index)
}
}
}
pub fn program_id(&self, instruction_index: usize) -> &Pubkey {
@ -306,22 +310,19 @@ mod tests {
assert_eq!(
serialize(&tx).unwrap(),
vec![
1, 0, 0, 0, 0, 0, 0, 0, 199, 111, 28, 46, 13, 235, 122, 203, 210, 118, 158, 0, 59,
175, 148, 175, 225, 134, 90, 155, 188, 232, 218, 54, 199, 116, 67, 99, 65, 84, 164,
94, 224, 60, 187, 249, 92, 210, 242, 99, 58, 121, 202, 5, 140, 152, 14, 166, 13,
134, 103, 127, 216, 96, 217, 139, 5, 252, 40, 146, 48, 112, 59, 7, 1, 0, 0, 0, 0,
1, 0, 0, 0, 0, 0, 0, 0, 234, 139, 34, 5, 120, 28, 107, 203, 69, 25, 236, 200, 164,
1, 12, 47, 147, 53, 41, 143, 23, 116, 230, 203, 59, 228, 153, 14, 22, 241, 103,
226, 186, 169, 181, 65, 49, 215, 44, 2, 61, 214, 113, 216, 184, 206, 147, 104, 140,
225, 138, 21, 172, 135, 211, 80, 103, 80, 216, 106, 249, 86, 194, 1, 3, 0, 0, 0, 0,
0, 0, 0, 32, 253, 186, 201, 177, 11, 117, 135, 187, 167, 181, 188, 22, 59, 206,
105, 231, 150, 215, 30, 78, 212, 76, 16, 252, 180, 72, 134, 137, 247, 161, 68, 3,
0, 0, 0, 0, 0, 0, 0, 32, 253, 186, 201, 177, 11, 117, 135, 187, 167, 181, 188, 22,
59, 206, 105, 231, 150, 215, 30, 78, 212, 76, 16, 252, 180, 72, 134, 137, 247, 161,
68, 32, 253, 186, 201, 177, 11, 117, 135, 187, 167, 181, 188, 22, 59, 206, 105,
231, 150, 215, 30, 78, 212, 76, 16, 252, 180, 72, 134, 137, 247, 161, 68, 1, 1, 1,
4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 7, 6, 5, 4, 1, 1,
1, 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, 0, 99, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 4, 5, 6,
7, 8, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 8, 7, 6, 5, 4, 2, 2, 2, 1, 0,
0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 1, 2,
3
105, 231, 150, 215, 30, 78, 212, 76, 16, 252, 180, 72, 134, 137, 247, 161, 68, 32,
253, 186, 201, 177, 11, 117, 135, 187, 167, 181, 188, 22, 59, 206, 105, 231, 150,
215, 30, 78, 212, 76, 16, 252, 180, 72, 134, 137, 247, 161, 68, 1, 1, 1, 4, 5, 6,
7, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 7, 6, 5, 4, 1, 1, 1, 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, 0, 99, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 4, 5, 6, 7, 8, 9,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 8, 7, 6, 5, 4, 2, 2, 2, 1, 0, 0, 0, 0,
0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3
],
);
}