@@ -23,6 +23,9 @@ export enum UploadTarget {
23
23
}
24
24
25
25
export class Environment {
26
+ private static _instanceSpecificInvitationSafe : GnosisSafeProxy ;
27
+ private static _instanceSpecificInvitationSafeKey : string ;
28
+
26
29
static async validateAndSummarize ( logInfo : boolean = true ) {
27
30
const errors : string [ ] = [ ] ;
28
31
@@ -81,20 +84,6 @@ export class Environment {
81
84
if ( logInfo ) {
82
85
console . log ( ` ${ this . operatorOrganisationAddress } nonce is: ${ nonce } ` ) ;
83
86
}
84
- if ( ! process . env . INVITATION_FUNDS_SAFE_ADDRESS ) {
85
- errors . push ( `The INVITATION_FUNDS_SAFE_ADDRESS environment variable is not set.` ) ;
86
- }
87
-
88
- if ( logInfo ) {
89
- console . log ( "* Testing invitationFundsSafe .." ) ;
90
- }
91
- nonce = await this . invitationFundsSafe . getNonce ( ) ;
92
- if ( logInfo ) {
93
- console . log ( ` ${ this . invitationFundsSafe . address } nonce is: ${ nonce } ` ) ;
94
- }
95
- if ( ! process . env . INVITATION_FUNDS_SAFE_KEY ) {
96
- errors . push ( `The INVITATION_FUNDS_SAFE_KEY environment variable is not set.` ) ;
97
- }
98
87
99
88
if ( logInfo ) {
100
89
console . log ( `* Checking which upload target to use (S3 or GCS) ...` ) ;
@@ -147,18 +136,62 @@ export class Environment {
147
136
console . log ( ` Success` ) ;
148
137
console . log ( `* Testing connection to the readonly api-db ...` ) ;
149
138
}
139
+
150
140
await this . readonlyApiDb . $queryRaw `select 1` ;
151
141
152
142
if ( logInfo ) {
153
143
console . log ( ` Success` ) ;
154
144
console . log ( `* Testing connection to the read/write api-db ...` ) ;
155
145
}
156
146
157
- await this . readWriteApiDb . $queryRaw `select 1` ;
147
+ const apiServerRecord = await this . readWriteApiDb . $queryRaw `insert into "ApiServers" ("instanceId") values (${ this . instanceId } ) returning id;` ;
148
+ const apiServerRecordId = < number > ( < any > apiServerRecord ) [ 0 ] ?. id ;
158
149
159
150
if ( logInfo ) {
160
- console . log ( ` Success` ) ;
151
+ console . log ( ` Success. ApiServer record id: ${ apiServerRecordId } ` ) ;
152
+ }
161
153
154
+ if ( ! process . env . INVITATION_FUNDS_SAFE_ADDRESS ) {
155
+ errors . push ( `The INVITATION_FUNDS_SAFE_ADDRESS environment variable is not set.` ) ;
156
+ }
157
+
158
+ const invitationFundsSafeAddresses = process . env . INVITATION_FUNDS_SAFE_ADDRESS ?. split ( ";" ) ?? [ ] ;
159
+ invitationFundsSafeAddresses . forEach ( ( address ) => {
160
+ if ( RpcGateway . get ( ) . utils . isAddress ( address ) ) {
161
+ return ;
162
+ }
163
+ errors . push ( `The INVITATION_FUNDS_SAFE_ADDRESS environment variable contains an invalid address: ${ address } ` ) ;
164
+ } ) ;
165
+ RpcGateway . get ( ) . utils . isAddress ( invitationFundsSafeAddresses [ 0 ] ) ;
166
+
167
+
168
+ if ( ! process . env . INVITATION_FUNDS_SAFE_KEY ) {
169
+ errors . push ( `The INVITATION_FUNDS_SAFE_KEY environment variable is not set.` ) ;
170
+ }
171
+
172
+ const invitationFundsSafeKeys = process . env . INVITATION_FUNDS_SAFE_KEY ?. split ( ";" ) ?? [ ] ;
173
+ if ( invitationFundsSafeKeys . length != invitationFundsSafeAddresses . length ) {
174
+ errors . push (
175
+ `The INVITATION_FUNDS_SAFE_KEY environment variable contains a different number of keys than INVITATION_FUNDS_SAFE_ADDRESS contains addresses.`
176
+ ) ;
177
+ }
178
+
179
+ const keyIdx = apiServerRecordId % invitationFundsSafeAddresses . length ;
180
+ this . _instanceSpecificInvitationSafe = new GnosisSafeProxy (
181
+ RpcGateway . get ( ) ,
182
+ RpcGateway . get ( ) . utils . toChecksumAddress ( < string > invitationFundsSafeAddresses [ keyIdx ] )
183
+ ) ;
184
+ this . _instanceSpecificInvitationSafeKey = invitationFundsSafeKeys [ keyIdx ] ;
185
+
186
+ if ( logInfo ) {
187
+ console . log ( "* Testing invitationFundsSafe .." ) ;
188
+ }
189
+ nonce = await this . invitationFundsSafe . getNonce ( ) ;
190
+ if ( logInfo ) {
191
+ console . log ( ` ${ this . invitationFundsSafe . address } nonce is: ${ nonce } ` ) ;
192
+ }
193
+
194
+ if ( logInfo ) {
162
195
console . log ( `* Testing connection to the indexer ws endpoint (${ this . blockchainIndexerUrl } ) ...` ) ;
163
196
}
164
197
@@ -382,15 +415,12 @@ export class Environment {
382
415
}
383
416
384
417
static get invitationFundsSafe ( ) : GnosisSafeProxy {
385
- return new GnosisSafeProxy (
386
- RpcGateway . get ( ) ,
387
- RpcGateway . get ( ) . utils . toChecksumAddress ( < string > process . env . INVITATION_FUNDS_SAFE_ADDRESS )
388
- ) ;
418
+ return this . _instanceSpecificInvitationSafe ;
389
419
}
390
420
391
421
static get invitationFundsSafeOwner ( ) : Account {
392
422
return RpcGateway . get ( ) . eth . accounts . privateKeyToAccount (
393
- < string > process . env . INVITATION_FUNDS_SAFE_KEY ? .toLowerCase ( )
423
+ < string > this . _instanceSpecificInvitationSafeKey . toLowerCase ( )
394
424
) ;
395
425
}
396
426
0 commit comments