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 +61 -24
- package/dist/client.js.map +1 -1
- package/dist/index.js +61 -24
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
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 =
|
|
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
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
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
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
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
|
|
1248
|
+
return accumulated.slice(0, limit);
|
|
1212
1249
|
},
|
|
1213
1250
|
async getTransaction(signature2, walletAddress) {
|
|
1214
1251
|
const tx = await fetchTransaction(client.rpc, signature2);
|