Skip to content

Commit df39c0f

Browse files
committed
Move over EVM Verifier
1 parent 65f7a2a commit df39c0f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2344
-415
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- `Web2Json`: added `PublicWeb2` source support, allows calling any public Web2 endpoint. Only available on testnets.
13+
- Migrated `evm` verifier type with `EVMTransaction` attestation type support into this repository from the [evm-verifier](https://gitlab.com/flarenetwork/fdc/evm-verifier) repository, which is now deprecated.
1314

1415
### Changed
1516

docker/verifier-evm/compose.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
services:
2+
verifier_eth:
3+
build: ../../
4+
restart: unless-stopped
5+
container_name: verifier_eth
6+
environment:
7+
VERIFIER_TYPE: eth
8+
TESTNET: false
9+
API_KEYS: "123456"
10+
PORT: 3100
11+
EVM_RPC: "https://ethereum.publicnode.com"
12+
ports:
13+
- "3004:3100"
14+
15+
verifier_flr:
16+
build: ../../
17+
restart: unless-stopped
18+
container_name: verifier_flr
19+
environment:
20+
VERIFIER_TYPE: flr
21+
TESTNET: false
22+
API_KEYS: "123456"
23+
PORT: 3100
24+
EVM_RPC: "https://flare-api.flare.network/ext/C/rpc"
25+
ports:
26+
- "3005:3100"
27+
28+
verifier_sgb:
29+
build: ../../
30+
restart: unless-stopped
31+
container_name: verifier_sgb
32+
environment:
33+
VERIFIER_TYPE: sgb
34+
TESTNET: false
35+
API_KEYS: "123456"
36+
PORT: 3100
37+
EVM_RPC: "https://songbird-api.flare.network/ext/C/rpc"
38+
ports:
39+
- "3006:3100"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "fasset-verifier-server",
2+
"name": "fdc-verifier-server",
33
"version": "0.0.1",
44
"description": "",
55
"author": "",

src/auth/auth.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export class AuthService {
77
API_KEYS: string[];
88

99
constructor(private readonly configService: ConfigService<IConfig>) {
10-
const API_KEYS: string[] = this.configService.get('api_keys');
10+
const API_KEYS: string[] = this.configService.get('apiKeys');
1111
if (!API_KEYS) {
1212
throw new Error('Env variables are missing (API_KEYS)');
1313
}

src/config/configuration.ts

Lines changed: 93 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,38 @@ import { IndexerConfig } from './interfaces/chain-indexer';
1818
import { TypeOrmModuleOptions } from '@nestjs/typeorm';
1919
import { web2JsonDefaultParams } from './defaults/web2-json-config';
2020
import { getDatabaseConfig } from './defaults/indexer-config';
21-
import { IConfig, VerifierServerConfig } from './interfaces/common';
21+
import { IConfig } from './interfaces/common';
2222
import { Web2JsonConfig, Web2JsonSource } from './interfaces/web2-json';
2323
import { WEB2_JSON_TEST_SOURCES } from './web2/web2-json-test-sources';
2424
import { WEB2_JSON_SOURCES } from './web2/web2-json-sources';
2525

2626
export 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';
168174
export 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';

src/config/interfaces/chain-indexer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,14 @@ export interface DatabaseConfig {
3030
export interface IndexerConfig {
3131
db: DatabaseConfig;
3232
typeOrmModuleOptions: TypeOrmModuleOptions;
33+
34+
/**
35+
* The page size for indexer API queries when listing outputs
36+
*/
37+
indexerServerPageLimit: number;
38+
39+
/**
40+
* The number of confirmations required for a transaction to be considered confirmed
41+
*/
42+
numberOfConfirmations: number;
3343
}

src/config/interfaces/common.ts

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,17 @@
1-
import { ChainType } from '../configuration';
1+
import { VerifierType } from '../configuration';
22
import { Web2JsonConfig } from './web2-json';
33
import { IndexerConfig } from './chain-indexer';
44

55
export interface IConfig {
66
/** Server port (PORT) */
77
port: number;
88
/** Comma-separated list of API keys (API_KEYS) */
9-
api_keys: string[];
10-
9+
apiKeys: string[];
1110
isTestnet: boolean;
12-
13-
verifierConfig: VerifierServerConfig;
11+
verifierType: VerifierType;
1412
/** Indexer configuration for BTC, DOGE and XRP verifiers */
1513
indexerConfig?: IndexerConfig;
1614
/** Security and source configuration for Web2Json verifier */
1715
web2JsonConfig?: Web2JsonConfig;
18-
}
19-
20-
export interface VerifierServerConfig {
21-
verifierType: ChainType;
22-
23-
/**
24-
* The page size for indexer API queries when listing outputs
25-
*/
26-
indexerServerPageLimit: number;
27-
28-
/**
29-
* The number of confirmations required for a transaction to be considered confirmed
30-
*/
31-
numberOfConfirmations: number;
16+
evmRpcUrl?: string;
3217
}

0 commit comments

Comments
 (0)