mirror of
https://github.com/pezkuwichain/pezkuwi-telegram-miniapp.git
synced 2026-11-25 11:59:58 +00:00
TronGrid's free plan allows 10,000 requests a day. Checking every user's TRC20 address on every five-minute run needs ~29,000 a day at 101 users, so the key ran out at 03:00 UTC and every later run was refused. get-deposit-info now records when a user opened the deposit screen. check-deposits checks users seen in the last 24 hours on every run and everyone in one run every six hours (00, 06, 12, 18 UTC): about 3,300 requests a day at 10 active users. A deposit made without opening the screen within the past day waits for the next full scan. The user-list query now reports its error instead of ending the TRC20 check as if there were no users.
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
// The TRC20 check costs one TronGrid request per user, and the free plan
|
|
// allows 10,000 a day ("Exceed the user daily usage (10000)", logged
|
|
// 2026-10-19). Checking every user every five minutes needs ~29,000 a day at
|
|
// 101 users, so only users who opened the deposit screen recently are checked
|
|
// on every run; everyone else is checked by a full scan every six hours.
|
|
|
|
export const ACTIVE_WINDOW_MS = 24 * 60 * 60 * 1000;
|
|
export const FULL_SCAN_EVERY_HOURS = 6;
|
|
// The cron runs every five minutes, so exactly one run per full-scan hour
|
|
// starts inside this window.
|
|
export const FULL_SCAN_WINDOW_MINUTES = 5;
|
|
|
|
export function isFullScanRun(now: Date): boolean {
|
|
return (
|
|
now.getUTCHours() % FULL_SCAN_EVERY_HOURS === 0 &&
|
|
now.getUTCMinutes() < FULL_SCAN_WINDOW_MINUTES
|
|
);
|
|
}
|
|
|
|
export interface Trc20User {
|
|
deposit_info_seen_at: string | null;
|
|
}
|
|
|
|
export function selectTrc20Users<T extends Trc20User>(users: T[], now: Date): T[] {
|
|
if (isFullScanRun(now)) return users;
|
|
const since = now.getTime() - ACTIVE_WINDOW_MS;
|
|
return users.filter((user) => {
|
|
if (!user.deposit_info_seen_at) return false;
|
|
const seen = Date.parse(user.deposit_info_seen_at);
|
|
return !Number.isNaN(seen) && seen >= since;
|
|
});
|
|
}
|