tx-indexer 0.1.0 → 0.2.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 +60 -23
- package/dist/client.js.map +1 -1
- package/dist/index.js +60 -23
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -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
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
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
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
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
|
|
1290
|
+
return accumulated.slice(0, limit);
|
|
1254
1291
|
},
|
|
1255
1292
|
async getTransaction(signature2, walletAddress) {
|
|
1256
1293
|
const tx = await fetchTransaction(client.rpc, signature2);
|