snipe-list.cache.ts 817 B

12345678910111213141516171819202122232425262728293031323334
  1. import fs from 'fs';
  2. import path from 'path';
  3. import { logger, SNIPE_LIST_REFRESH_INTERVAL } from '../helpers';
  4. export class SnipeListCache {
  5. private snipeList: string[] = [];
  6. constructor() {
  7. setInterval(this.loadSnipeList, SNIPE_LIST_REFRESH_INTERVAL);
  8. }
  9. public init() {
  10. this.loadSnipeList();
  11. }
  12. public isInList(mint: string) {
  13. return this.snipeList.includes(mint);
  14. }
  15. private loadSnipeList() {
  16. logger.trace('Refreshing snipe list...');
  17. const count = this.snipeList.length;
  18. const data = fs.readFileSync(path.join(__dirname, 'snipe-list.txt'), 'utf-8');
  19. this.snipeList = data
  20. .split('\n')
  21. .map((a) => a.trim())
  22. .filter((a) => a);
  23. if (this.snipeList.length != count) {
  24. logger.info(`Loaded snipe list: ${this.snipeList.length}`);
  25. }
  26. }
  27. }