Utility function getAllSignatures
This commit is contained in:
parent
99bae5a33a
commit
7d474ed608
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue