Skip to content

Instantly share code, notes, and snippets.

@WietseWind
Created August 1, 2023 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WietseWind/c2732240ef993519249bdb4aac9224a3 to your computer and use it in GitHub Desktop.
Save WietseWind/c2732240ef993519249bdb4aac9224a3 to your computer and use it in GitHub Desktop.
Batch Escrow Finish on XRPTipBot account
import { derive, utils, signAndSubmit } from "xrpl-accountlib"
import { XrplClient } from "xrpl-client"
const account = derive.familySeed("... FAMILY SEED OF ACCOUNT TO SIGN FINISH TX WITH ...")
const tipbotAccount = 'rPEPPER7kfTD9w2To4CQk6UCfuHM9c6GDY'
const xrplTime = Math.round(new Date() / 1000) - 946684800
const client = new XrplClient()
const networkInfo = await utils.txNetworkAndAccountValues(client, account)
console.log('Signing with...', networkInfo.txValues.Account)
let marker = ''
const escrows = []
while (typeof marker === 'string') {
const objects = await client.send({
command: 'account_objects',
account: tipbotAccount,
type: 'escrow',
marker: marker === '' ? undefined : marker,
})
escrows.push(...objects.account_objects)
if (objects.marker) console.log(objects.marker)
marker = objects.marker !== marker ? objects.marker : undefined
}
const matureEscrows = escrows.filter(escrow => escrow.FinishAfter < xrplTime)
console.log('matureEscrows', matureEscrows.length)
let finished = 0
if (matureEscrows.length > 0) {
for await (const matureEscrow of matureEscrows) {
const escrowCreate = await client.send({ command: 'tx', transaction: matureEscrow.PreviousTxnID })
const submitted = await signAndSubmit({
TransactionType: 'EscrowFinish',
Owner: tipbotAccount,
OfferSequence: escrowCreate.Sequence,
...networkInfo.txValues,
Sequence: networkInfo.txValues.Sequence + finished,
NetworkID: undefined,
}, client, account)
finished++
console.log(submitted.tx_id, submitted.response.engine_result_message)
}
}
client.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment