tx-indexer 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.js CHANGED
@@ -372,7 +372,7 @@ function isSolanaPayTransaction(programIds, memo) {
372
372
 
373
373
  // ../solana/src/fetcher/transactions.ts
374
374
  async function fetchWalletSignatures(rpc, walletAddress, config = {}) {
375
- const { limit = 1e3, before, until } = config;
375
+ const { limit = 100, before, until } = config;
376
376
  const response = await rpc.getSignaturesForAddress(walletAddress, {
377
377
  limit,
378
378
  before,
@@ -1184,31 +1184,68 @@ function createIndexer(options) {
1184
1184
  },
1185
1185
  async getTransactions(walletAddress, options2 = {}) {
1186
1186
  const { limit = 10, before, until, filterSpam = true, spamConfig } = options2;
1187
- const signatures = await fetchWalletSignatures(client.rpc, walletAddress, {
1188
- limit,
1189
- before,
1190
- until
1191
- });
1192
- if (signatures.length === 0) {
1193
- return [];
1187
+ if (!filterSpam) {
1188
+ const signatures = await fetchWalletSignatures(client.rpc, walletAddress, {
1189
+ limit,
1190
+ before,
1191
+ until
1192
+ });
1193
+ if (signatures.length === 0) {
1194
+ return [];
1195
+ }
1196
+ const signatureObjects = signatures.map(
1197
+ (sig) => parseSignature(sig.signature)
1198
+ );
1199
+ const transactions = await fetchTransactionsBatch(
1200
+ client.rpc,
1201
+ signatureObjects
1202
+ );
1203
+ const classified = transactions.map((tx) => {
1204
+ tx.protocol = detectProtocol(tx.programIds);
1205
+ const legs = transactionToLegs(tx, walletAddress);
1206
+ const classification = classifyTransaction(legs, walletAddress, tx);
1207
+ return { tx, classification, legs };
1208
+ });
1209
+ return classified;
1194
1210
  }
1195
- const signatureObjects = signatures.map(
1196
- (sig) => parseSignature(sig.signature)
1197
- );
1198
- const transactions = await fetchTransactionsBatch(
1199
- client.rpc,
1200
- signatureObjects
1201
- );
1202
- const classified = transactions.map((tx) => {
1203
- tx.protocol = detectProtocol(tx.programIds);
1204
- const legs = transactionToLegs(tx, walletAddress);
1205
- const classification = classifyTransaction(legs, walletAddress, tx);
1206
- return { tx, classification, legs };
1207
- });
1208
- if (filterSpam) {
1209
- return filterSpamTransactions(classified, spamConfig);
1211
+ const accumulated = [];
1212
+ let currentBefore = before;
1213
+ const MAX_ITERATIONS = 10;
1214
+ let iteration = 0;
1215
+ while (accumulated.length < limit && iteration < MAX_ITERATIONS) {
1216
+ iteration++;
1217
+ const batchSize = iteration === 1 ? limit : limit * 2;
1218
+ const signatures = await fetchWalletSignatures(client.rpc, walletAddress, {
1219
+ limit: batchSize,
1220
+ before: currentBefore,
1221
+ until
1222
+ });
1223
+ if (signatures.length === 0) {
1224
+ break;
1225
+ }
1226
+ const signatureObjects = signatures.map(
1227
+ (sig) => parseSignature(sig.signature)
1228
+ );
1229
+ const transactions = await fetchTransactionsBatch(
1230
+ client.rpc,
1231
+ signatureObjects
1232
+ );
1233
+ const classified = transactions.map((tx) => {
1234
+ tx.protocol = detectProtocol(tx.programIds);
1235
+ const legs = transactionToLegs(tx, walletAddress);
1236
+ const classification = classifyTransaction(legs, walletAddress, tx);
1237
+ return { tx, classification, legs };
1238
+ });
1239
+ const nonSpam = filterSpamTransactions(classified, spamConfig);
1240
+ accumulated.push(...nonSpam);
1241
+ const lastSignature = signatures[signatures.length - 1];
1242
+ if (lastSignature) {
1243
+ currentBefore = parseSignature(lastSignature.signature);
1244
+ } else {
1245
+ break;
1246
+ }
1210
1247
  }
1211
- return classified;
1248
+ return accumulated.slice(0, limit);
1212
1249
  },
1213
1250
  async getTransaction(signature2, walletAddress) {
1214
1251
  const tx = await fetchTransaction(client.rpc, signature2);