const Fetch = require('node-fetch')
const Client = require('rippled-ws-client')
const Sign = require('rippled-ws-client-sign')
const Seed = process.argv[2] || ''
new Client('wss://xrpl.ws').then(Connection => {
Fetch('https://ledger.exposed/api/escrowlist').then(r => r.json()).then(Escrows => {
const ToFinish = Escrows.filter(Escrow => {
return Escrow.FinishAfter <= Math.round((new Date()) / 1000) - 946684800
&& Escrow.Condition === undefined
}).slice(0, 1)
ToFinish.forEach(Escrow => {
Connection.send({
command: 'account_objects',
account: Escrow.Account,
limit: 400
}).then(AccountObjects => {
const Escrows = AccountObjects.account_objects.filter(Obj => Obj.LedgerEntryType === 'Escrow')
Escrows.forEach(Escrow => {
Connection.send({
command: 'tx',
transaction: Escrow.PreviousTxnID
}).then(CreateTx => {
const FinishJson = {
Account: 'rPEPPER7kfTD9w2To4CQk6UCfuHM9c6GDY',
TransactionType: 'EscrowFinish',
Owner: Escrow.Account,
OfferSequence: CreateTx.Sequence
}
new Sign(FinishJson, Seed, Connection)
.then(TransactionSuccess => {
console.log('TransactionSuccess', TransactionSuccess)
}).catch(SignError => {
console.log('SignError', SignError.details)
})
})
})
})
})
})
})