Last active
November 24, 2025 13:36
-
-
Save shortthefomo/93db22ade141c3ceaf4faae7bf88e534 to your computer and use it in GitHub Desktop.
Derive Balance Change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @tx: transaction result from the XRPL | |
| * @raddress: the raddress you want to get the balance changes for | |
| */ | |
| deriveBalanceChange(tx, raddress) { | |
| let change = {} | |
| if (tx.meta === undefined && tx.metaData === undefined) { return change } | |
| for (let affected of (tx.meta || tx.metaData).AffectedNodes) { | |
| let node = affected.ModifiedNode || affected.DeletedNode | |
| if (!node) { continue } | |
| if (node.LedgerEntryType === 'AccountRoot') { | |
| if (node.FinalFields?.Account === raddress) { | |
| let prev = node.PreviousFields.Balance | |
| let final = node.FinalFields.Balance | |
| change.XRP = new decimal(prev).sub(new decimal(final)) | |
| } | |
| } | |
| if (node.LedgerEntryType === 'RippleState') { | |
| if (node.FinalFields?.LowLimit?.issuer === raddress) { | |
| change[node.FinalFields.LowLimit.currency] = new decimal(node.PreviousFields.Balance.value).sub(new decimal(node.FinalFields.Balance.value)) | |
| } | |
| } | |
| } | |
| return change == {} ? undefined : change | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment