polycopy 0.1.9 → 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.
Files changed (2) hide show
  1. package/dist/index.js +32 -34
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1291,43 +1291,41 @@ conditionId: ${record.position.conditionId}
1291
1291
  }
1292
1292
  }
1293
1293
  async executeBatches(pendingRecords) {
1294
- for (let i = 0; i < pendingRecords.length; i += this.batchSize) {
1295
- const batch = pendingRecords.slice(i, i + this.batchSize);
1296
- const conditionIds = batch.map((record) => record.position.conditionId);
1297
- if (conditionIds.length === 0) {
1298
- continue;
1294
+ const batch = pendingRecords.slice(0, this.batchSize);
1295
+ const conditionIds = batch.map((record) => record.position.conditionId);
1296
+ if (conditionIds.length === 0) {
1297
+ return true;
1298
+ }
1299
+ try {
1300
+ const txHash = await this.redeemFn?.(conditionIds);
1301
+ batch.forEach((record) => {
1302
+ record.success = true;
1303
+ record.matchedCount = 0;
1304
+ });
1305
+ logger.info(`Redeem 已执行 (批量 ${batch.length}): ${txHash}`);
1306
+ } catch (error) {
1307
+ const errorMsg = error instanceof Error ? error.message : String(error);
1308
+ if (errorMsg.includes("429") || errorMsg.includes("Too Many Requests")) {
1309
+ const resetSeconds = this.parseResetSeconds(errorMsg);
1310
+ logger.warning(`Redeem 限流,${resetSeconds} 秒后重试`);
1311
+ telegramService.warning("Redeem 限流", `${resetSeconds} 秒后重试`);
1312
+ this.pauseAndRestart((resetSeconds + 60) * 1e3);
1313
+ return false;
1299
1314
  }
1300
- try {
1301
- const txHash = await this.redeemFn?.(conditionIds);
1302
- batch.forEach((record) => {
1303
- record.success = true;
1304
- record.matchedCount = 0;
1305
- });
1306
- logger.info(`Redeem 已执行 (批量 ${batch.length}): ${txHash}`);
1307
- } catch (error) {
1308
- const errorMsg = error instanceof Error ? error.message : String(error);
1309
- if (errorMsg.includes("429") || errorMsg.includes("Too Many Requests")) {
1310
- const resetSeconds = this.parseResetSeconds(errorMsg);
1311
- logger.warning(`Redeem 限流,${resetSeconds} 秒后重试`);
1312
- telegramService.warning("Redeem 限流", `${resetSeconds} 秒后重试`);
1313
- this.pauseAndRestart((resetSeconds + 60) * 1e3);
1314
- return false;
1315
- }
1316
- batch.forEach((record) => {
1317
- record.failedCount++;
1318
- });
1319
- logger.error(`Redeem 批量异常 (批量 ${batch.length}): ${errorMsg}`);
1320
- batch.forEach((record) => {
1321
- if (record.failedCount >= MAX_MATCH_TIMES) {
1322
- telegramService.error(
1323
- "Redeem 异常",
1324
- `重试 ${record.failedCount} 次仍失败
1315
+ batch.forEach((record) => {
1316
+ record.failedCount++;
1317
+ });
1318
+ logger.error(`Redeem 批量异常 (批量 ${batch.length}): ${errorMsg}`);
1319
+ batch.forEach((record) => {
1320
+ if (record.failedCount >= MAX_MATCH_TIMES) {
1321
+ telegramService.error(
1322
+ "Redeem 异常",
1323
+ `重试 ${record.failedCount} 次仍失败
1325
1324
  conditionId: ${record.position.conditionId}
1326
1325
  错误: ${errorMsg}`
1327
- );
1328
- }
1329
- });
1330
- }
1326
+ );
1327
+ }
1328
+ });
1331
1329
  }
1332
1330
  return true;
1333
1331
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "polycopy",
3
- "version": "0.1.9",
3
+ "version": "0.2.0",
4
4
  "description": "polycopy test",
5
5
  "main": "dist/index.js",
6
6
  "bin": {