const pgp = require('pg-promise')({ capSQL: true, }); import { sleep } from '@blockworks-foundation/mango-client'; export async function getTransactions( signaturesToProcess, connection, requestWaitTime ) { console.time('transactions request') let promises: Promise[] = []; let transactions: any[] = []; let counter = 1; for (let signature of signaturesToProcess) { // Want to store the raw json returned from the rpc - so have to bypass the regular client methods here (which transform the json) let args = [signature, { encoding: 'jsonParsed', commitment: 'finalized' }]; let promise = connection ._rpcRequest('getConfirmedTransaction', args) .then((confirmedTransaction) => transactions.push([signature, confirmedTransaction]), ); if (counter % 1000 === 0) { console.log('requested ', counter, ' of ', signaturesToProcess.length); } counter++; promises.push(promise); // Limit request frequency to avoid request failures due to rate limiting await sleep(requestWaitTime); } await (Promise as any).allSettled(promises); console.timeEnd('transactions request') return transactions; } export async function getUnprocessedSignatures( pool, programPk, schema, workerPartitionStart, workerPartitionEnd, limit, ) { const client = await pool.connect(); let signatures; try { // TODO: add back in order by id asc - but why does it make it so much slower? const res = await client.query( 'select signature from ' + schema + ".transactions where process_state = 'unprocessed' and program_pk = $1 and worker_partition between $2 and $3 limit " + limit, [programPk, workerPartitionStart, workerPartitionEnd], ); signatures = res.rows.map((e) => e['signature']); } finally { client.release(); } return signatures; }