File tree 2 files changed +31
-1
lines changed
2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ import type { EventHandlerContext } from "./indexer/indexer.js";
39
39
import { handleEvent as handleAlloV1Event } from "./indexer/allo/v1/handleEvent.js" ;
40
40
import { handleEvent as handleAlloV2Event } from "./indexer/allo/v2/handleEvent.js" ;
41
41
import { Database } from "./database/index.js" ;
42
- import { decodeJsonWithBigInts } from "./utils/index.js" ;
42
+ import { decodeJsonWithBigInts , getExternalIP } from "./utils/index.js" ;
43
43
import { Block } from "chainsauce/dist/cache.js" ;
44
44
import { createPublicClient , http } from "viem" ;
45
45
import { IndexerEvents } from "chainsauce/dist/indexer.js" ;
@@ -121,6 +121,8 @@ async function main(): Promise<void> {
121
121
return decodeJsonWithBigInts ( val ) ;
122
122
} ) ;
123
123
124
+ await getExternalIP ( baseLogger ) ;
125
+
124
126
if ( config . cacheDir ) {
125
127
if ( config . removeCache ) {
126
128
await fs . rm ( config . cacheDir , { recursive : true } ) ;
Original file line number Diff line number Diff line change 1
1
// TODO: why is eslint not recognizing type narrowing?
2
2
/* eslint-disable @typescript-eslint/no-unsafe-argument */
3
+
4
+ import { Logger } from "pino" ;
5
+
3
6
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
4
7
export function encodeJsonWithBigInts ( value : unknown ) : string {
5
8
return JSON . stringify ( value , ( _key , value ) => {
@@ -31,3 +34,28 @@ export const UINT64_MAX = 18446744073709551615n;
31
34
export const getDateFromTimestamp = ( timestamp : bigint ) : Date | null => {
32
35
return timestamp < UINT64_MAX ? new Date ( Number ( timestamp ) * 1000 ) : null ;
33
36
} ;
37
+
38
+ export const getExternalIP = async ( logger : Logger ) : Promise < string > => {
39
+ const urls = [ "https://api.ipify.org?format=json" , "http://ipinfo.io/json" ] ;
40
+ for ( const url of urls ) {
41
+ try {
42
+ logger . debug ( `Attempting to fetch IP address from: ${ url } ` ) ;
43
+ const response = await fetch ( url ) ;
44
+ if ( response . ok ) {
45
+ const { ip } = ( await response . json ( ) ) as { ip : string } ;
46
+ logger . info ( `Successfully fetched IP address: ${ ip } ` ) ;
47
+ return ip ;
48
+ }
49
+ throw new Error ( `Request failed with status: ${ response . status } ` ) ;
50
+ } catch ( error ) {
51
+ if ( error instanceof Error ) {
52
+ logger . error ( `Failed to fetch from ${ url } : ${ error . message } ` ) ;
53
+ } else {
54
+ logger . error ( `Failed to fetch from ${ url } ` ) ;
55
+ }
56
+ }
57
+ }
58
+ throw new Error (
59
+ "Unable to fetch external IP address from both primary and fallback URLs."
60
+ ) ;
61
+ } ;
You can’t perform that action at this time.
0 commit comments