Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
57ee9a5
commit 28855ee
Showing
16 changed files
with
655 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import axios from 'axios'; | ||
import Logger from '../Logger'; | ||
|
||
type BlocksConfig = { | ||
urls?: string[]; | ||
}; | ||
|
||
class Blocks { | ||
private blocked = new Set<string>(); | ||
|
||
constructor( | ||
private readonly logger: Logger, | ||
private readonly config: BlocksConfig, | ||
) {} | ||
|
||
public updateBlocks = async () => { | ||
if (this.config.urls === undefined || this.config.urls.length === 0) { | ||
return; | ||
} | ||
|
||
const addresses = await Promise.all( | ||
this.config.urls.map(async (url) => { | ||
const response = await axios.get<string[]>(url); | ||
this.logger.verbose( | ||
`Fetched ${response.data.length} blocked addresses from: ${url}`, | ||
); | ||
return response.data; | ||
}), | ||
); | ||
|
||
for (const addr of addresses.flat()) { | ||
this.blocked.add(addr); | ||
} | ||
}; | ||
|
||
public isBlocked = (addr: string) => this.blocked.has(addr); | ||
} | ||
|
||
export default Blocks; | ||
export { BlocksConfig }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.