From 7d474ed6085a24c8489b36aace193227bba4be76 Mon Sep 17 00:00:00 2001 From: Nicholas Clarke Date: Tue, 25 Jan 2022 15:50:00 -0800 Subject: [PATCH] Utility function getAllSignatures --- src/tests/testParseTransactions.ts | 41 ++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/src/tests/testParseTransactions.ts b/src/tests/testParseTransactions.ts index 64f8c43..d5582b4 100644 --- a/src/tests/testParseTransactions.ts +++ b/src/tests/testParseTransactions.ts @@ -100,3 +100,44 @@ async function consumeTransactions() { } consumeTransactions(); + + +async function getAllSignatures(addressPk: PublicKey, connection: Connection) { + let signatures; + const limit = 1000; + let before = null; + let options; + let allSignaturesInfo: ConfirmedSignatureInfo[] = []; + + while (true) { + if (before === null) { + options = { limit: limit }; + } else { + options = { limit: limit, before: before }; + } + + let signaturesInfo = await connection.getConfirmedSignaturesForAddress2( + addressPk, + options, + ); + signatures = signaturesInfo.map((x) => x['signature']); + + allSignaturesInfo = allSignaturesInfo.concat(signaturesInfo); + + if (signaturesInfo.length !== limit) { + break + } + + before = signatures[signatures.length - 1]; + + console.log( + new Date( + signaturesInfo[signaturesInfo.length - 1].blockTime! * 1000, + ).toISOString(), + ); + + } + + return allSignaturesInfo; +} +