File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,10 @@ const SCHNAPS_API_URL = process.env.SCHNAPS_API_URL;
12
12
const NETWORK_PREFIX = process . env . NETWORK === 'mainnet' ? 's:' : 's-tn:' ;
13
13
const RUN_INTERVAL = 10 * 1e3 ; // 10 seconds
14
14
15
+ const provider = snapshot . utils . getProvider ( process . env . DEFAULT_NETWORK , {
16
+ broviderUrl : process . env . BROVIDER_URL || 'https://rpc.snapshot.org'
17
+ } ) ;
18
+
15
19
// Periodically sync the turbo status of spaces with the schnaps-api
16
20
export async function trackTurboStatuses ( ) {
17
21
if ( ! SCHNAPS_API_URL ) return ;
@@ -63,6 +67,10 @@ async function updateTurboStatuses(spaces: { id: string; turbo_expiration: numbe
63
67
async function getSpacesExpirationDates ( ) : Promise < Space [ ] > {
64
68
const query = `
65
69
query GetSpaces {
70
+ _metadata(id: "last_indexed_block") {
71
+ id
72
+ value
73
+ }
66
74
spaces {
67
75
id
68
76
turbo_expiration
@@ -87,6 +95,12 @@ async function getSpacesExpirationDates(): Promise<Space[]> {
87
95
return [ ] ;
88
96
}
89
97
98
+ const block = await provider . getBlock ( 'latest' ) ;
99
+ if ( block . number - Number ( data . data . _metadata . value ) > 10 ) {
100
+ console . log ( 'Schnaps API is outdated. Skipping update.' ) ;
101
+ return [ ] ;
102
+ }
103
+
90
104
return data . data . spaces ;
91
105
} catch ( e ) {
92
106
capture ( e ) ;
You can’t perform that action at this time.
0 commit comments