@@ -18,34 +18,38 @@ import { IndexerConfig } from './interfaces/chain-indexer';
1818import { TypeOrmModuleOptions } from '@nestjs/typeorm' ;
1919import { web2JsonDefaultParams } from './defaults/web2-json-config' ;
2020import { getDatabaseConfig } from './defaults/indexer-config' ;
21- import { IConfig , VerifierServerConfig } from './interfaces/common' ;
21+ import { IConfig } from './interfaces/common' ;
2222import { Web2JsonConfig , Web2JsonSource } from './interfaces/web2-json' ;
2323import { WEB2_JSON_TEST_SOURCES } from './web2/web2-json-test-sources' ;
2424import { WEB2_JSON_SOURCES } from './web2/web2-json-sources' ;
2525
2626export default ( ) => {
27- const api_keys = getApiKeys ( ) ;
28- const verifier_type = extractVerifierType ( ) ;
27+ const apiKeys = getApiKeys ( ) ;
28+ const verifierType = extractVerifierType ( ) ;
2929 const isTestnet = process . env . TESTNET == 'true' ;
3030
31- const verifierConfig : VerifierServerConfig = {
32- verifierType : verifier_type ,
33- numberOfConfirmations : parseInt ( process . env . NUMBER_OF_CONFIRMATIONS || '6' ) , // TODO: This should be read from db state
34- indexerServerPageLimit : parseInt (
35- process . env . INDEXER_SERVER_PAGE_LIMIT || '100' ,
36- ) ,
37- } ;
38-
3931 const config : IConfig = {
4032 port : parseInt ( process . env . PORT || '3120' ) ,
41- api_keys,
42- verifierConfig,
33+ apiKeys : apiKeys ,
4334 isTestnet,
35+ verifierType,
4436 } ;
45- if ( verifier_type === ChainType . Web2 ) {
46- config . web2JsonConfig = getWeb2Config ( isTestnet ) ;
47- } else {
48- config . indexerConfig = getIndexerConfig ( verifier_type ) ;
37+
38+ switch ( verifierType ) {
39+ case VerifierType . BTC :
40+ case VerifierType . DOGE :
41+ case VerifierType . XRP :
42+ config . indexerConfig = getIndexerConfig ( verifierType ) ;
43+ break ;
44+ case VerifierType . ETH :
45+ case VerifierType . SGB :
46+ case VerifierType . FLR :
47+ config . evmRpcUrl =
48+ process . env . EVM_RPC || 'https://flare-api.flare.network/ext/C/rpc' ;
49+ break ;
50+ case VerifierType . Web2 :
51+ config . web2JsonConfig = getWeb2Config ( isTestnet ) ;
52+ break ;
4953 }
5054
5155 return config ;
@@ -66,28 +70,34 @@ export function getApiKeys(): string[] {
6670 return apiKeys ;
6771}
6872
69- export function extractVerifierType ( ) : ChainType {
73+ export function extractVerifierType ( ) : VerifierType {
7074 const verifierType = process . env . VERIFIER_TYPE ?. toLowerCase ( ) ;
7175 switch ( verifierType ) {
7276 case 'doge' :
73- return ChainType . DOGE ;
77+ return VerifierType . DOGE ;
7478 case 'btc' :
75- return ChainType . BTC ;
79+ return VerifierType . BTC ;
7680 case 'xrp' :
77- return ChainType . XRP ;
81+ return VerifierType . XRP ;
7882 case 'web2' :
79- return ChainType . Web2 ;
83+ return VerifierType . Web2 ;
84+ case 'eth' :
85+ return VerifierType . ETH ;
86+ case 'sgb' :
87+ return VerifierType . SGB ;
88+ case 'flr' :
89+ return VerifierType . FLR ;
8090 default :
8191 throw new Error (
82- `Wrong verifier type: '${ String ( process . env . VERIFIER_TYPE ) } ' provide a valid verifier type: 'doge' | 'btc' | 'xrp' | 'web2'` ,
92+ `Wrong verifier type: '${ String ( process . env . VERIFIER_TYPE ) } ' provide a valid verifier type: 'doge' | 'btc' | 'xrp' | 'web2' | 'eht' | 'sgb' | 'flr' ` ,
8393 ) ;
8494 }
8595}
8696
87- export function getDatabaseEntities ( verifierType : ChainType ) {
97+ export function getDatabaseEntities ( verifierType : VerifierType ) {
8898 switch ( verifierType ) {
89- case ChainType . BTC :
90- case ChainType . DOGE :
99+ case VerifierType . BTC :
100+ case VerifierType . DOGE :
91101 return [
92102 DBUtxoIndexerBlock ,
93103 DBUtxoTransaction ,
@@ -98,7 +108,7 @@ export function getDatabaseEntities(verifierType: ChainType) {
98108 DBPruneSyncState ,
99109 DBIndexerVersion ,
100110 ] ;
101- case ChainType . XRP :
111+ case VerifierType . XRP :
102112 return [
103113 DBXrpIndexerBlock ,
104114 DBXrpTransaction ,
@@ -137,47 +147,73 @@ function getWeb2Config(isTestnet: boolean): Web2JsonConfig {
137147 } ;
138148}
139149
140- function getIndexerConfig ( verifierType : ChainType ) : IndexerConfig {
141- switch ( verifierType ) {
142- case ChainType . BTC :
143- case ChainType . DOGE :
144- case ChainType . XRP : {
145- const entities = getDatabaseEntities ( verifierType ) ;
146- const databaseConfig = getDatabaseConfig ( ) ;
147- const typeOrmModulePartialOptions : TypeOrmModuleOptions = {
148- ...databaseConfig ,
149- type : 'postgres' ,
150- synchronize : false ,
151- migrationsRun : false ,
152- logging : false ,
153- } ;
154- const typeOrmModuleOptions : TypeOrmModuleOptions = {
155- ...typeOrmModulePartialOptions ,
156- entities,
157- } ;
158- return { db : databaseConfig , typeOrmModuleOptions } ;
159- }
160- case ChainType . Web2 :
161- throw new Error ( 'Web2 verifier does not use indexer config' ) ;
162- default :
163- throw new Error ( `Unsupported verifier type: ${ verifierType } ` ) ;
164- }
150+ function getIndexerConfig ( verifierType : VerifierType ) : IndexerConfig {
151+ const entities = getDatabaseEntities ( verifierType ) ;
152+ const databaseConfig = getDatabaseConfig ( ) ;
153+ const typeOrmModulePartialOptions : TypeOrmModuleOptions = {
154+ ...databaseConfig ,
155+ type : 'postgres' ,
156+ synchronize : false ,
157+ migrationsRun : false ,
158+ logging : false ,
159+ } ;
160+ const typeOrmModuleOptions : TypeOrmModuleOptions = {
161+ ...typeOrmModulePartialOptions ,
162+ entities,
163+ } ;
164+ return {
165+ db : databaseConfig ,
166+ typeOrmModuleOptions,
167+ numberOfConfirmations : parseInt ( process . env . NUMBER_OF_CONFIRMATIONS || '6' ) , // TODO: This should be read from db state
168+ indexerServerPageLimit : parseInt (
169+ process . env . INDEXER_SERVER_PAGE_LIMIT || '100' ,
170+ ) ,
171+ } ;
165172}
166173
167- export type ChainSourceNames = 'DOGE' | 'BTC' | 'XRP' ;
168174export type AttestationTypeOptions =
169175 | 'AddressValidity'
170176 | 'BalanceDecreasingTransaction'
171177 | 'ConfirmedBlockHeightExists'
172178 | 'Payment'
173179 | 'ReferencedPaymentNonexistence'
174- | 'Web2Json' ;
180+ | 'Web2Json'
181+ | 'EVMTransaction' ;
175182
176- export enum ChainType {
177- invalid = - 1 ,
183+ export enum VerifierType {
178184 BTC = 0 ,
179185 DOGE = 2 ,
180186 XRP = 3 ,
181187 Web2 = 4 ,
182- // ... make sure IDs are the same as in Flare node
188+ ETH = 5 ,
189+ SGB = 6 ,
190+ FLR = 7 ,
191+ }
192+
193+ export function typeToSource ( type : VerifierType ) : ChainSourceNames {
194+ switch ( type ) {
195+ case VerifierType . BTC :
196+ return 'BTC' ;
197+ case VerifierType . DOGE :
198+ return 'DOGE' ;
199+ case VerifierType . XRP :
200+ return 'XRP' ;
201+ case VerifierType . ETH :
202+ return 'ETH' ;
203+ case VerifierType . SGB :
204+ return 'SGB' ;
205+ case VerifierType . FLR :
206+ return 'FLR' ;
207+ case VerifierType . Web2 :
208+ return 'WEB2' ;
209+ }
183210}
211+
212+ export type ChainSourceNames =
213+ | 'DOGE'
214+ | 'BTC'
215+ | 'XRP'
216+ | 'ETH'
217+ | 'SGB'
218+ | 'FLR'
219+ | 'WEB2' ;
0 commit comments