2021-12-07 00:19:50 -08:00
|
|
|
const pgp = require('pg-promise')({
|
|
|
|
capSQL: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
import { sleep } from '@blockworks-foundation/mango-client';
|
|
|
|
|
2021-12-16 16:37:08 -08:00
|
|
|
export async function getTransactions(
|
|
|
|
signaturesToProcess,
|
2021-12-07 00:19:50 -08:00
|
|
|
connection,
|
2021-12-16 16:37:08 -08:00
|
|
|
requestWaitTime
|
2021-12-07 00:19:50 -08:00
|
|
|
) {
|
|
|
|
|
|
|
|
let promises: Promise<void>[] = [];
|
|
|
|
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]),
|
|
|
|
);
|
|
|
|
|
2021-12-14 09:25:46 -08:00
|
|
|
if (counter % 100 === 0) {
|
|
|
|
console.log('requested ', counter, ' of ', signaturesToProcess.length);
|
|
|
|
}
|
2021-12-07 00:19:50 -08:00
|
|
|
counter++;
|
|
|
|
|
|
|
|
promises.push(promise);
|
|
|
|
|
|
|
|
// Limit request frequency to avoid request failures due to rate limiting
|
|
|
|
await sleep(requestWaitTime);
|
|
|
|
}
|
2021-12-14 09:25:46 -08:00
|
|
|
|
2021-12-07 00:19:50 -08:00
|
|
|
await (Promise as any).allSettled(promises);
|
|
|
|
|
2022-01-09 12:42:57 -08:00
|
|
|
console.log('transactions received')
|
|
|
|
|
2021-12-07 00:19:50 -08:00
|
|
|
return transactions;
|
|
|
|
}
|
|
|
|
|
2021-12-16 16:37:08 -08:00
|
|
|
export async function getUnprocessedSignatures(
|
2021-12-07 00:19:50 -08:00
|
|
|
pool,
|
|
|
|
programPk,
|
|
|
|
schema,
|
|
|
|
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 limit " +
|
|
|
|
limit,
|
|
|
|
[programPk],
|
|
|
|
);
|
|
|
|
|
|
|
|
signatures = res.rows.map((e) => e['signature']);
|
|
|
|
} finally {
|
|
|
|
client.release();
|
|
|
|
}
|
|
|
|
|
|
|
|
return signatures;
|
|
|
|
}
|