Skip to content

Commit 7f222bc

Browse files
committed
fix(notification): update Discord webhook payload format for error notifications
- Changed the payload key from "text" to "content" in the Discord webhook notification for daily balance snapshot failures. - Updated README documentation to reflect changes in API request structure, including removal of request body and addition of query parameters. - Enhanced wallet processing logic to include fallback to signer stake keys for network determination. - Improved documentation on batch processing features and configuration options.
1 parent 14c32c0 commit 7f222bc

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

.github/workflows/daily-balance-snapshots.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
echo "❌ Daily balance snapshot job failed"
5252
if [ -n "${{ secrets.SNAPSHOT_ERROR_DISCORD_WEBHOOK_URL }}" ]; then
5353
curl -X POST -H 'Content-type: application/json' \
54-
--data "{\"text\":\"❌ Daily balance snapshots failed. Check the GitHub Actions logs.\"}" \
54+
--data "{\"content\":\"❌ Daily balance snapshots failed. Check the GitHub Actions logs.\"}" \
5555
${{ secrets.SNAPSHOT_ERROR_DISCORD_WEBHOOK_URL }} || echo "Failed to send Discord notification"
5656
else
5757
echo "SNAPSHOT_ERROR_DISCORD_WEBHOOK_URL not configured, skipping notification"

src/pages/api/v1/stats/README.md

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,7 @@ The endpoint requires authentication using the `SNAPSHOT_AUTH_TOKEN` environment
2424
- **Method**: POST
2525
- **Purpose**: Processes a batch of wallets for balance snapshots (main endpoint)
2626
- **Authentication**: Required (Bearer token)
27-
- **Content-Type**: `application/json`
28-
- **Body**:
29-
```json
30-
{
31-
"batchId": "string",
32-
"batchNumber": number,
33-
"batchSize": number
34-
}
35-
```
27+
- **Parameters**: passed via query string (no request body)
3628
- **Query Parameters**:
3729
- `batchId`: Unique identifier for the batch session
3830
- `batchNumber`: Current batch number (1-based, must be ≥ 1)
@@ -74,7 +66,12 @@ The endpoint requires authentication using the `SNAPSHOT_AUTH_TOKEN` environment
7466
"isArchived": boolean,
7567
"verified": number,
7668
"hasDRepKeys": boolean,
77-
"hasClarityApiKey": boolean
69+
"scriptCborLength": number,
70+
"stakeCredentialLength": number,
71+
"signersAddressesLength": number,
72+
"signersStakeKeysLength": number,
73+
"signersDRepKeysLength": number,
74+
"signersDescriptionsLength": number
7875
}
7976
}
8077
]
@@ -83,6 +80,14 @@ The endpoint requires authentication using the `SNAPSHOT_AUTH_TOKEN` environment
8380
}
8481
```
8582

83+
#### Example (curl)
84+
85+
```bash
86+
curl -X POST \
87+
"$API_BASE_URL/api/v1/stats/run-snapshots-batch?batchId=snapshot-$(date +%s)&batchNumber=1&batchSize=5" \
88+
-H "Authorization: Bearer $SNAPSHOT_AUTH_TOKEN"
89+
```
90+
8691
## Batch Processing System
8792

8893
The new system processes wallets in small batches to avoid timeout issues:
@@ -94,6 +99,8 @@ The new system processes wallets in small batches to avoid timeout issues:
9499
4. **Fault Tolerant**: Failed batches can be retried individually
95100
5. **Input Validation**: Comprehensive validation for batch parameters
96101
6. **Error Tracking**: Detailed error reporting with wallet structure information
102+
7. **Network Fallback**: If no UTxOs are found on the inferred network, the opposite network is tried
103+
8. **Wallet Build Strategy**: Uses ordered keys via `MultisigWallet` when `signersStakeKeys` exist; otherwise falls back to legacy `buildWallet`
97104

98105
### Orchestrator Script
99106
The `scripts/batch-snapshot-orchestrator.ts` script manages the entire process:
@@ -112,7 +119,7 @@ The `scripts/batch-snapshot-orchestrator.ts` script manages the entire process:
112119
- **`BATCH_SIZE`**: Wallets per batch (default: 5, range: 1-5)
113120
- **`DELAY_BETWEEN_BATCHES`**: Seconds between batches (default: 10)
114121
- **`MAX_RETRIES`**: Retry attempts for failed batches (default: 3)
115-
- **`REQUEST_TIMEOUT`**: Request timeout in seconds (default: 60)
122+
- **`REQUEST_TIMEOUT`**: Request timeout in seconds (default: 45)
116123

117124
## GitHub Actions Integration
118125

@@ -182,11 +189,13 @@ The orchestrator will:
182189

183190
### Type Safety & Validation
184191
- **Fixed Decimal Type**: Proper handling of Decimal types in database operations
185-
- **Input Validation**: Comprehensive validation for batch parameters (batch number ≥ 1, batch size 1-100)
192+
- **Input Validation**: Comprehensive validation for batch parameters (batch number ≥ 1, batch size 1-5)
186193
- **Error Tracking**: Enhanced error handling with detailed wallet structure information
187194

188195
### Configuration & Reliability
189196
- **Configurable Timeouts**: Request timeout now configurable via `REQUEST_TIMEOUT` environment variable
190197
- **Enhanced Error Handling**: UTxO fetch failures are now properly tracked and reported
191198
- **Network-Specific Reporting**: Separate tracking for mainnet and testnet wallets and balances
192-
- **Improved Documentation**: Updated documentation to reflect all recent changes
199+
- **Improved Documentation**: Updated documentation to reflect all recent changes
200+
- **Network Fallback**: Attempts the opposite network if no UTxOs are found
201+
- **Wallet Build Logic**: Uses ordered keys with `MultisigWallet` when stake keys are available, with legacy fallback (no stake keys)

src/pages/api/v1/stats/run-snapshots-batch.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,16 @@ export default async function handler(
259259
try {
260260
console.log(` Processing wallet: (${wallet.id.slice(0, 8)}...)`);
261261

262-
// Determine network from signer addresses
262+
// Determine network from signer addresses, fallback to signer stake keys
263263
let network = 1; // Default to mainnet
264264
if (wallet.signersAddresses.length > 0) {
265265
const signerAddr = wallet.signersAddresses[0]!;
266266
network = addressToNetwork(signerAddr);
267+
} else if (wallet.signersStakeKeys && wallet.signersStakeKeys.length > 0) {
268+
const stakeAddr = wallet.signersStakeKeys.find((s) => !!s);
269+
if (stakeAddr) {
270+
network = addressToNetwork(stakeAddr);
271+
}
267272
}
268273

269274
// Build wallet conditionally: use MultisigSDK ordering if signersStakeKeys exist
@@ -299,6 +304,7 @@ export default async function handler(
299304
);
300305
walletAddress = mWallet.getScript().address;
301306
} else {
307+
// Fallback: build the wallet without enforcing key ordering (legacy payment-script build)
302308
const builtWallet = buildWallet(wallet, network);
303309
walletAddress = builtWallet.address;
304310
}

0 commit comments

Comments
 (0)