Skip to content

Commit 3c185c7

Browse files
pplanelPedro Gabrielwjthieme
authored
fix: modify parsing logic in get_token_accounts_for_owner (#729)
* fix: modify parsing logic in get_token_accounts_for_owner Modify the parsing logic to check if data.program is "spl-token" and use spl_token::ID, rather than attempting to parse it as a Pubkey. * chore: run changeset * fix: patch changeset * Update four-shrimps-refuse.md --------- Co-authored-by: Pedro Gabriel <[email protected]> Co-authored-by: Will <[email protected]>
1 parent 667b437 commit 3c185c7

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

.changeset/four-shrimps-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@orca-so/whirlpools-rust": patch
3+
---
4+
5+
Fix a bug parsing rpc-response in get_token_accounts_for_owner

rust-sdk/whirlpool/src/account.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ pub(crate) async fn get_token_accounts_for_owner(
4646
let mut token_accounts: Vec<ParsedTokenAccount> = Vec::new();
4747
for account in accounts {
4848
if let UiAccountData::Json(data) = account.account.data {
49+
let token_program = match data.program.as_str() {
50+
"spl-token" => &spl_token::ID.to_string(),
51+
"spl-token-2022" => &spl_token_2022::ID.to_string(),
52+
pubkey => pubkey,
53+
};
4954
let token: Parsed = from_value(data.parsed)?;
5055
token_accounts.push(ParsedTokenAccount {
5156
pubkey: Pubkey::from_str(&account.pubkey)?,
52-
token_program: Pubkey::from_str(&data.program)?,
57+
token_program: Pubkey::from_str(token_program)?,
5358
mint: Pubkey::from_str(&token.info.mint)?,
5459
amount: token.info.token_amount.amount.parse::<u64>()?,
5560
});

0 commit comments

Comments
 (0)