Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscripting a transaction's pre_token_balances and post_token_balances returns the same object? #365

Open
Bewinxed opened this issue Jun 14, 2023 · 3 comments

Comments

@Bewinxed
Copy link

Bewinxed commented Jun 14, 2023

So let's say i fetch a transaction:

        tx_sig='4JsupFeVjPjLQfYLGGkDds6PZbfqhehJXYu5XryNN26hwChX9oPisZra61vvMzAK2xhQHa84r44aWaenD8hbjpgg',
        encoding="jsonParsed",
        commitment=None,
        max_supported_transaction_version=None,
    )

Then I print the transaction meta and I get:

pre_token_balances: Some(
                        [
                            UiTransactionTokenBalance {
                                account_index: 1,
                                mint: "cUBeL4fhn1yznohws5Gquc3CnomDJwKL7Bz24RSCEVu",
                                ui_token_amount: UiTokenAmount {
                                    ui_amount: Some(
                                        1.0,
                                    ),
                                    decimals: 0,
                                    amount: "1",
                                    ui_amount_string: "1",
                                },
                                owner: Some(
                                    "Bwinxuqwf5uNcqCAFG8Wqt7cGcirdPkthn4MbNXhJY8f",
                                ),
                                program_id: Skip,
                            },
                        ],
                    ),
                    post_token_balances: Some(
                        [
                            UiTransactionTokenBalance {
                                account_index: 1,
                                mint: "cUBeL4fhn1yznohws5Gquc3CnomDJwKL7Bz24RSCEVu",
                                ui_token_amount: UiTokenAmount {
                                    ui_amount: Some(
                                        1.0,
                                    ),
                                    decimals: 0,
                                    amount: "1",
                                    ui_amount_string: "1",
                                },
                                owner: Some(
                                    "GUfCR9mK6azb9vcpsxgXyj7XRPAKJd4KMHTTVvtncGgp",
                                ),
                                program_id: Skip,
                            },
                        ],
                    ),

then I do this:

pre_balances = response.transaction.meta.pre_token_balances
post_balances = response.transaction.meta.post_token_balances
print(pre_balances)
print(post_balances)

They both return the pre balances value

                        [
                            UiTransactionTokenBalance {
                                account_index: 1,
                                mint: "cUBeL4fhn1yznohws5Gquc3CnomDJwKL7Bz24RSCEVu",
                                ui_token_amount: UiTokenAmount {
                                    ui_amount: Some(
                                        1.0,
                                    ),
                                    decimals: 0,
                                    amount: "1",
                                    ui_amount_string: "1",
                                },
                                owner: Some(
                                    "GUfCR9mK6azb9vcpsxgXyj7XRPAKJd4KMHTTVvtncGgp",
                                ),
                                program_id: Skip,
                            },
                        ],
                    ),

I had to turn meta into a dict using loads(response.transaction.meta.to_json()) and only then could I access the proper token balances.
Even if I print the objects directly they print the same value, and even if I do
response.transaction.meta.post_token_balances == response.transaction.meta.pre_token_balances it returns True

Am I tripping?

@michaelhly
Copy link
Owner

I believe this is a Solana JSON RPC API issue. We don't have control over what the Solana Node returns back. Might want to ask someone at @solana-labs

@Bewinxed
Copy link
Author

Bewinxed commented Jun 15, 2023 via email

@kevinheavey
Copy link
Collaborator

Are you using the latest solana-py? This should be fixed by kevinheavey/solders#59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants