Skip to content

Instantly share code, notes, and snippets.

@boid-com
Created January 11, 2020 09:11
Show Gist options
  • Save boid-com/a1993b16d099f1355bb943582fe29476 to your computer and use it in GitHub Desktop.
Save boid-com/a1993b16d099f1355bb943582fe29476 to your computer and use it in GitHub Desktop.
const {api,rpc} = require('./eosjs')()
const print = (data) => console.log(data.transaction_id)
const err = (error) => console.error(error.toString())
const random = (min, max) => Math.floor(Math.random() * (Math.floor(max) - Math.ceil(min) + 1)) + Math.ceil(min)
async function getPendingClaims (account) {
try {
let res = await rpc.get_table_rows({"json":true,"code":"daccustodia1","scope":"daccustodia1","table":"pendingpay","table_key":"","lower_bound":account,"upper_bound":account,"index_position":2,"key_type":"name","limit":-1,"reverse":false,"show_payer":false})
return res.rows
} catch (error) {
console.error(error)
return []
return { error: error.toString() }
}
}
async function claimPayout(payid) {
const result = await api.transact(
{
actions: [
{
account: 'daccustodia1',
name: 'claimpay',
authorization: [{actor:'johnatboid11',permission:'vigclaim'}],
data: {payid}
}
]
},{ blocksBehind: 6, expireSeconds: 30 }
)
return result
}
async function init(account){
const claims = (await getPendingClaims(account)).map(el => el.key)
console.log(claims)
for (claim of claims) {
await claimPayout(claim).then(print).catch(err)
}
}
init('johnatboid11').catch(console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment