Skip to content

Instantly share code, notes, and snippets.

@randomnerd
Last active November 3, 2020 11:45
Show Gist options
  • Save randomnerd/e52f3d72f625873c631baa7cc8f651fb to your computer and use it in GitHub Desktop.
Save randomnerd/e52f3d72f625873c631baa7cc8f651fb to your computer and use it in GitHub Desktop.
eos.get_full_table.js
async function getFullTable(params, rpc) {
if (!params.limit) params.limit = 50
const rows = []
let more = true
let lastKey
let primaryKey
while (more) {
if (rows.length && primaryKey) lastKey = rows[rows.length - 1][primaryKey]
const result = await rpc.get_table_rows({
...params,
json: true,
lower_bound: lastKey
})
more = result.more
rows.push(...(lastKey ? result.rows.slice(1) : result.rows))
if (result.rows.length) primaryKey = Object.keys(result.rows[0])[0]
}
return rows
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment