RPC: Fix ATA create instruction parsing (#28314)
This commit is contained in:
parent
d500391006
commit
cc390f176c
|
@ -27,25 +27,13 @@ pub fn parse_associated_token(
|
|||
));
|
||||
}
|
||||
}
|
||||
if instruction.data.is_empty() {
|
||||
check_num_associated_token_accounts(&instruction.accounts, 7)?;
|
||||
Ok(ParsedInstructionEnum {
|
||||
instruction_type: "create".to_string(),
|
||||
info: json!({
|
||||
"source": account_keys[instruction.accounts[0] as usize].to_string(),
|
||||
"account": account_keys[instruction.accounts[1] as usize].to_string(),
|
||||
"wallet": account_keys[instruction.accounts[2] as usize].to_string(),
|
||||
"mint": account_keys[instruction.accounts[3] as usize].to_string(),
|
||||
"systemProgram": account_keys[instruction.accounts[4] as usize].to_string(),
|
||||
"tokenProgram": account_keys[instruction.accounts[5] as usize].to_string(),
|
||||
"rentSysvar": account_keys[instruction.accounts[6] as usize].to_string(),
|
||||
}),
|
||||
})
|
||||
let ata_instruction = if instruction.data.is_empty() {
|
||||
AssociatedTokenAccountInstruction::Create
|
||||
} else {
|
||||
let ata_instruction = AssociatedTokenAccountInstruction::try_from_slice(&instruction.data)
|
||||
.map_err(|_| {
|
||||
ParseInstructionError::InstructionNotParsable(ParsableProgram::SplToken)
|
||||
})?;
|
||||
AssociatedTokenAccountInstruction::try_from_slice(&instruction.data)
|
||||
.map_err(|_| ParseInstructionError::InstructionNotParsable(ParsableProgram::SplToken))?
|
||||
};
|
||||
|
||||
match ata_instruction {
|
||||
AssociatedTokenAccountInstruction::Create => {
|
||||
check_num_associated_token_accounts(&instruction.accounts, 6)?;
|
||||
|
@ -92,7 +80,6 @@ pub fn parse_associated_token(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_num_associated_token_accounts(
|
||||
accounts: &[u8],
|
||||
|
@ -158,13 +145,7 @@ mod test {
|
|||
);
|
||||
let message = Message::new(&[create_ix], None);
|
||||
let mut compiled_instruction = convert_compiled_instruction(&message.instructions[0]);
|
||||
assert_eq!(
|
||||
parse_associated_token(
|
||||
&compiled_instruction,
|
||||
&AccountKeys::new(&convert_account_keys(&message), None)
|
||||
)
|
||||
.unwrap(),
|
||||
ParsedInstructionEnum {
|
||||
let expected_parsed_ix = ParsedInstructionEnum {
|
||||
instruction_type: "create".to_string(),
|
||||
info: json!({
|
||||
"source": funder.to_string(),
|
||||
|
@ -173,10 +154,34 @@ mod test {
|
|||
"mint": mint.to_string(),
|
||||
"systemProgram": solana_sdk::system_program::id().to_string(),
|
||||
"tokenProgram": spl_token::id().to_string(),
|
||||
"rentSysvar": sysvar::rent::id().to_string(),
|
||||
})
|
||||
}
|
||||
}),
|
||||
};
|
||||
assert_eq!(
|
||||
parse_associated_token(
|
||||
&compiled_instruction,
|
||||
&AccountKeys::new(&convert_account_keys(&message), None)
|
||||
)
|
||||
.unwrap(),
|
||||
expected_parsed_ix,
|
||||
);
|
||||
|
||||
// after popping rent account, parsing should still succeed
|
||||
let rent_account_index = compiled_instruction
|
||||
.accounts
|
||||
.iter()
|
||||
.position(|index| message.account_keys[*index as usize] == sysvar::rent::id())
|
||||
.unwrap();
|
||||
compiled_instruction.accounts.remove(rent_account_index);
|
||||
assert_eq!(
|
||||
parse_associated_token(
|
||||
&compiled_instruction,
|
||||
&AccountKeys::new(&convert_account_keys(&message), None)
|
||||
)
|
||||
.unwrap(),
|
||||
expected_parsed_ix,
|
||||
);
|
||||
|
||||
// after popping another account, parsing should fail
|
||||
compiled_instruction.accounts.pop();
|
||||
assert!(parse_associated_token(
|
||||
&compiled_instruction,
|
||||
|
|
Loading…
Reference in New Issue