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/index.js CHANGED
@@ -384,7 +384,7 @@ function isSolanaPayTransaction(programIds, memo) {
384
384
 
385
385
  // ../solana/src/fetcher/transactions.ts
386
386
  async function fetchWalletSignatures(rpc, walletAddress, config = {}) {
387
- const { limit = 1e3, before, until } = config;
387
+ const { limit = 100, before, until } = config;
388
388
  const response = await rpc.getSignaturesForAddress(walletAddress, {
389
389
  limit,
390
390
  before,
@@ -1226,31 +1226,68 @@ function createIndexer(options) {
1226
1226
  },
1227
1227
  async getTransactions(walletAddress, options2 = {}) {
1228
1228
  const { limit = 10, before, until, filterSpam = true, spamConfig } = options2;
1229
- const signatures = await fetchWalletSignatures(client.rpc, walletAddress, {
1230
- limit,
1231
- before,
1232
- until
1233
- });
1234
- if (signatures.length === 0) {
1235
- return [];
1229
+ if (!filterSpam) {
1230
+ const signatures = await fetchWalletSignatures(client.rpc, walletAddress, {
1231
+ limit,
1232
+ before,
1233
+ until
1234
+ });
1235
+ if (signatures.length === 0) {
1236
+ return [];
1237
+ }
1238
+ const signatureObjects = signatures.map(
1239
+ (sig) => parseSignature(sig.signature)
1240
+ );
1241
+ const transactions = await fetchTransactionsBatch(
1242
+ client.rpc,
1243
+ signatureObjects
1244
+ );
1245
+ const classified = transactions.map((tx) => {
1246
+ tx.protocol = detectProtocol(tx.programIds);
1247
+ const legs = transactionToLegs(tx, walletAddress);
1248
+ const classification = classifyTransaction(legs, walletAddress, tx);
1249
+ return { tx, classification, legs };
1250
+ });
1251
+ return classified;
1236
1252
  }
1237
- const signatureObjects = signatures.map(
1238
- (sig) => parseSignature(sig.signature)
1239
- );
1240
- const transactions = await fetchTransactionsBatch(
1241
- client.rpc,
1242
- signatureObjects
1243
- );
1244
- const classified = transactions.map((tx) => {
1245
- tx.protocol = detectProtocol(tx.programIds);
1246
- const legs = transactionToLegs(tx, walletAddress);
1247
- const classification = classifyTransaction(legs, walletAddress, tx);
1248
- return { tx, classification, legs };
1249
- });
1250
- if (filterSpam) {
1251
- return filterSpamTransactions(classified, spamConfig);
1253
+ const accumulated = [];
1254
+ let currentBefore = before;
1255
+ const MAX_ITERATIONS = 10;
1256
+ let iteration = 0;
1257
+ while (accumulated.length < limit && iteration < MAX_ITERATIONS) {
1258
+ iteration++;
1259
+ const batchSize = iteration === 1 ? limit : limit * 2;
1260
+ const signatures = await fetchWalletSignatures(client.rpc, walletAddress, {
1261
+ limit: batchSize,
1262
+ before: currentBefore,
1263
+ until
1264
+ });
1265
+ if (signatures.length === 0) {
1266
+ break;
1267
+ }
1268
+ const signatureObjects = signatures.map(
1269
+ (sig) => parseSignature(sig.signature)
1270
+ );
1271
+ const transactions = await fetchTransactionsBatch(
1272
+ client.rpc,
1273
+ signatureObjects
1274
+ );
1275
+ const classified = transactions.map((tx) => {
1276
+ tx.protocol = detectProtocol(tx.programIds);
1277
+ const legs = transactionToLegs(tx, walletAddress);
1278
+ const classification = classifyTransaction(legs, walletAddress, tx);
1279
+ return { tx, classification, legs };
1280
+ });
1281
+ const nonSpam = filterSpamTransactions(classified, spamConfig);
1282
+ accumulated.push(...nonSpam);
1283
+ const lastSignature = signatures[signatures.length - 1];
1284
+ if (lastSignature) {
1285
+ currentBefore = parseSignature(lastSignature.signature);
1286
+ } else {
1287
+ break;
1288
+ }
1252
1289
  }
1253
- return classified;
1290
+ return accumulated.slice(0, limit);
1254
1291
  },
1255
1292
  async getTransaction(signature2, walletAddress) {
1256
1293
  const tx = await fetchTransaction(client.rpc, signature2);