xrpl-py
xrpl-py copied to clipboard
Transaction.from_xrpl should work even if there are non-canonical fields
When you send a request, you often get transactions back with non-canonical fields like date
or hash
. Transaction.from_xrpl
should be able to still construct a Transaction object from those fields.
One simple way to do this is to filter out lowercase fields, then use .from_xrpl as is.
Ex. This code snippet for parsing the response of get_account_transactions
from xrpl.clients import WebsocketClient
from xrpl.account import get_account_transactions
from xrpl.models.transactions.transaction import Transaction
client = WebsocketClient("wss://s.devnet.rippletest.net:51233")
client.open()
faucet_account = "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe"
account_tx = get_account_transactions(faucet_account, client)
tx_1 = account_tx[0]['tx']
# Remove fields which are added as part of the Request, and are not part of the actual Transaction object
tx_1_no_added_fields = dict((k, v) for k,v in tx_1.items() if not(k[0].islower()))
print(Transaction.from_xrpl(tx_1_no_added_fields))
client.close()
This issue was found in response to this comment in the XRP Ledger Developers Discord: https://discord.com/channels/886050993802985492/886053080913821717/933452502077177886