@@ -73,18 +73,18 @@ async function main() {
7373 const imageBuffer = await ( await fetch ( imageUrl ) ) . buffer ( )
7474 const imageSharp = sharp ( imageBuffer )
7575 const metadata = await imageSharp . metadata ( )
76-
76+
7777 console . debug ( `Image metadata:` , metadata )
78-
78+
7979 if ( ! metadata . format ) {
8080 throw new Error ( 'Unsupported image format' )
8181 }
82-
82+
8383 const resizedImageBuffer = await imageSharp . resize ( 64 , 64 ) . png ( ) . toBuffer ( )
84-
84+
8585 console . info ( ` Pinning shrunk image to ${ process . env . IPFS_GATEWAY } ` )
8686 let ipfsResponse : IPFSResponse [ ] | null = null
87-
87+
8888 for ( let attemptIPFS = 1 ; attemptIPFS <= 5 ; attemptIPFS ++ ) {
8989 try {
9090 ipfsResponse = await ipfsPublish (
@@ -107,16 +107,16 @@ async function main() {
107107 }
108108 }
109109 }
110-
110+
111111 if ( ! ipfsResponse ) {
112112 console . error ( )
113113 throw new Error (
114114 `Failed to upload ${ token . symbol } image to ipfs gateway. Halting` ,
115115 )
116116 }
117-
118- const multihash = ipfsResponse [ 0 ] . hash
119-
117+
118+ const multihash = ipfsResponse [ 0 ] . hash
119+
120120 if ( ipfsResponse ) {
121121 // Was successfully pinned to IPFS, no point in resubmitting.
122122 console . log ( ` Caching ${ multihash } ` )
@@ -125,7 +125,7 @@ async function main() {
125125 multihash ,
126126 )
127127 }
128-
128+
129129 tokensWithLogo . push ( {
130130 ...token ,
131131 logoURI : `ipfs://${ multihash } ` ,
@@ -140,7 +140,7 @@ async function main() {
140140 }
141141 }
142142 }
143-
143+
144144 }
145145 }
146146
@@ -154,15 +154,32 @@ async function main() {
154154 't2cr.tokenlist.json' ,
155155 )
156156
157- // Update tokens list in ENS (if needed)
158- await checkPublishErc20 (
159- tokensWithLogo ,
160- provider ,
161- process . env . LATEST_TOKENLIST_URL ,
162- process . env . ENS_TOKENLIST_NAME ,
163- 'Tokens' ,
164- 'tokenlist.tokenlist.json' ,
165- )
157+ // Update tokens list in ENS (if needed)
158+ await checkPublishErc20 (
159+ tokensWithLogo ,
160+ provider ,
161+ process . env . LATEST_TOKENLIST_URL ,
162+ process . env . ENS_TOKENLIST_NAME ,
163+ 'Tokens' ,
164+ 'tokenlist.tokenlist.json' ,
165+ )
166+
167+ // Do a heartbeat to monitoring that the bot has completed the task
168+ if ( process . env . HEARTBEAT_ENDPOINT ) {
169+ await fetch ( process . env . HEARTBEAT_ENDPOINT )
170+ . then ( ( response ) => {
171+ if ( response . status !== 200 ) {
172+ console . log ( 'Error: Not succesfull status when trying to do the heartbeat.' ) ;
173+ return
174+ }
175+ console . log ( 'Heartbeat succesfully performed.' ) ;
176+ } )
177+ . catch ( ( error ) => {
178+ console . log ( error ) ;
179+ }
180+ )
181+ }
182+
166183}
167184
168185main ( ) . catch ( ( err ) => {
0 commit comments