Created
March 20, 2023 14:49
-
-
Save WietseWind/07d0ab5f500783b1c9f63165c3b2bb68 to your computer and use it in GitHub Desktop.
Async/Sync check accounts for balance & TrustLine balance
This file contains 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
import { XrplClient } from 'xrpl-client' | |
const account = 'rpKJsRsvKXt5JwV2PFRnvfkEH47MEWpVYo' | |
const client = new XrplClient() | |
let marker | |
let pages = 0 | |
let accounts = 0 | |
while ((typeof marker === 'undefined' && pages === 0) || marker) { | |
pages++ | |
const txs = await client.send({ command: 'account_tx', account, limit: 10, marker }) | |
marker = txs?.marker | |
const activatedAccounts = (txs.transactions || []) | |
.filter(transaction => transaction.tx?.Destination && transaction.tx.Destination !== account) | |
.map(transaction => Promise.all([ | |
client.send({ command: 'account_info', account: transaction.tx.Destination }), | |
client.send({ command: 'account_lines', account: transaction.tx.Destination }), | |
])) | |
for await (const [acc, acclines] of activatedAccounts) { | |
console.log([ | |
' ', | |
acc.account_data?.Account, | |
' '.repeat(39 - acc.account_data?.Account.length), | |
Number(acc.account_data?.Balance) / 1000, | |
' ', | |
acclines.lines?.[0]?.currency, | |
' ', | |
Math.round(Number(acclines.lines?.[0]?.balance) * 100) / 100, | |
].join('')) | |
accounts++ | |
} | |
} | |
client.close() | |
console.log({ | |
pages, | |
accounts, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment