Skip to content

Commit

Permalink
Feat: adding health endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
AvbrehtLuka committed Nov 28, 2024
1 parent 9c648a5 commit c105809
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.17.1
v20.18.1
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
},
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
}
22 changes: 20 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { SGBEVMTransactionVerifierController } from "./controller/sgb/sgb-evm-tr
import { ETHEVMTransactionVerifierService } from "./service/eth/eth-evm-transaction-verifier.service";
import { FLREVMTransactionVerifierService } from "./service/flr/flr-evm-transaction-verifier.service";
import { SGBEVMTransactionVerifierService } from "./service/sgb/sgb-evm-transaction-verifier.service";
import { ETHHealthController, FLRHealthController, SGBHealthController } from "./controller/health.controller";
import { SGBEvmHealthServiceBase, FLREvmHealthServiceBase, ETHEvmHealthServiceBase } from "./service/health.service";

@Module({
imports: [
Expand All @@ -19,7 +21,23 @@ import { SGBEVMTransactionVerifierService } from "./service/sgb/sgb-evm-transact
}),
AuthModule,
],
controllers: [ETHEVMTransactionVerifierController, FLREVMTransactionVerifierController, SGBEVMTransactionVerifierController],
providers: [ApiKeyStrategy, AuthService, ETHEVMTransactionVerifierService, FLREVMTransactionVerifierService, SGBEVMTransactionVerifierService],
controllers: [
ETHEVMTransactionVerifierController,
FLREVMTransactionVerifierController,
SGBEVMTransactionVerifierController,
SGBHealthController,
FLRHealthController,
ETHHealthController,
],
providers: [
ApiKeyStrategy,
AuthService,
ETHEVMTransactionVerifierService,
FLREVMTransactionVerifierService,
SGBEVMTransactionVerifierService,
SGBEvmHealthServiceBase,
FLREvmHealthServiceBase,
ETHEvmHealthServiceBase,
],
})
export class AppModule {}
41 changes: 41 additions & 0 deletions src/controller/health.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Controller, Get } from "@nestjs/common";
import { ApiTags } from "@nestjs/swagger";

import { ETHEvmHealthServiceBase, EvmHealthServiceBase, FLREvmHealthServiceBase, SGBEvmHealthServiceBase } from "../service/health.service";

abstract class BaseHealthController {
protected abstract healthService: EvmHealthServiceBase;

/**
* Gets the state entries from the indexer database.
* @returns
*/
@Get("health")
public async indexerState(): Promise<boolean> {
return this.healthService.checkHealth();
}
}

@ApiTags("Health")
@Controller("sgb/")
export class SGBHealthController extends BaseHealthController {
constructor(protected healthService: SGBEvmHealthServiceBase) {
super();
}
}

@ApiTags("Health")
@Controller("flr/")
export class FLRHealthController extends BaseHealthController {
constructor(protected healthService: FLREvmHealthServiceBase) {
super();
}
}

@ApiTags("Health")
@Controller("eth/")
export class ETHHealthController extends BaseHealthController {
constructor(protected healthService: ETHEvmHealthServiceBase) {
super();
}
}
147 changes: 7 additions & 140 deletions src/dto/EVMTransaction.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,152 +2,16 @@
/////// THIS CODE IS AUTOGENERATED. DO NOT CHANGE!!! /////////
//////////////////////////////////////////////////////////////////////////////////////////
import { ApiProperty, OmitType } from "@nestjs/swagger";
import { Type } from "class-transformer";
import { Transform, Type } from "class-transformer";
import {
Validate,
IsBoolean,
ValidationArguments,
ValidatorConstraint,
ValidatorConstraintInterface,
IsDefined,
IsNotEmptyObject,
IsObject,
ValidateNested,
Validate,
ValidateNested
} from "class-validator";

///////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////// CUSTOM VALIDATORS ////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////

/**
* Validator constraint if the given value is a number or 0x-prefixed hexadecimal string.
*/
@ValidatorConstraint({ name: "unsigned-int", async: false })
class IsUnsignedIntLike implements ValidatorConstraintInterface {
/**
* Validates if the given value is a string of decimal unsigned number or 0x-prefixed hexadecimal string.
* @param text
* @param args
* @returns
*/
validate(text: any, _args: ValidationArguments) {
return typeof text === "string" && (/^0x[0-9a-fA-F]+$/i.test(text) || /^[0-9]+$/i.test(text));
}

/**
* Returns the default error message template.
* @param args
* @returns
*/
defaultMessage(_args: ValidationArguments) {
return "($property) value ($value) is not a decimal number in string or 0x-prefixed hexadecimal string";
}
}

/**
* Validator constraint if the given value is a number or 0x-prefixed hexadecimal string.
*/
@ValidatorConstraint({ name: "signed-int", async: false })
class IsSignedIntLike implements ValidatorConstraintInterface {
/**
* Validates if the given value is a number or 0x-prefixed hexadecimal string.
* @param text
* @param args
* @returns
*/
validate(text: any, _args: ValidationArguments) {
return typeof text === "string" && (/^-?0x[0-9a-fA-F]+$/i.test(text) || /^-?[0-9]+$/i.test(text));
}

/**
* Returns the default error message template.
* @param args
* @returns
*/
defaultMessage(_args: ValidationArguments) {
return "($property) value ($value) is not a signed decimal integer in string or signed 0x-prefixed hexadecimal string";
}
}

/**
* Validator constraint if the given value is a 0x-prefixed hexadecimal string representing 32 bytes.
*/
@ValidatorConstraint({ name: "hash-32", async: false })
class IsHash32 implements ValidatorConstraintInterface {
/**
* Validates if the given value is a 0x-prefixed hexadecimal string representing 32 bytes.
* @param text
* @param args
* @returns
*/
validate(text: any, _args: ValidationArguments) {
return typeof text === "string" && /^0x[0-9a-f]{64}$/i.test(text);
}

/**
* Returns the default error message template.
* @param args
* @returns
*/
defaultMessage(_args: ValidationArguments) {
return "($property) value ($value) is not 0x-prefixed hexadecimal string representing 32 bytes";
}
}

/**
* Validator constraint if the given value is a 0x-prefixed hexadecimal string
*/
@ValidatorConstraint({ name: "hash-0x", async: false })
class Is0xHex implements ValidatorConstraintInterface {
/**
* Validates if the given value is a 0x-prefixed hexadecimal string
* @param text
* @param args
* @returns
*/
validate(text: any, _args: ValidationArguments) {
return typeof text === "string" && /^0x[0-9a-f]+$/i.test(text);
}

/**
* Returns the default error message template.
* @param args
* @returns
*/
defaultMessage(_args: ValidationArguments) {
return "($property) value ($value) is not 0x-prefixed hexadecimal string";
}
}

/**
* Validator constraint if the given value is an EVM address, hence 0x-prefixed hexadecimal string representing 20 bytes.
*/
@ValidatorConstraint({ name: "evm-address", async: false })
class IsEVMAddress implements ValidatorConstraintInterface {
/**
* Validates if the given value is an EVM address, hence 0x-prefixed hexadecimal string representing 20 bytes.
* @param text
* @param args
* @returns
*/
validate(text: any, _args: ValidationArguments) {
return typeof text === "string" && /^0x[0-9a-f]{40}$/i.test(text);
}

/**
* Returns the default error message template.
* @param args
* @returns
*/
defaultMessage(_args: ValidationArguments) {
return "($property) value ($value) is not 0x-prefixed hexadecimal string representing 20 bytes (EVM address)";
}
}

///////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////// DTOs /////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////

import { IsUnsignedIntLike, IsEVMAddress, IsHash32, Is0xHex, prefix0x } from "./dto-validators";
/**
* Attestation status
*/
Expand Down Expand Up @@ -195,13 +59,15 @@ export class EVMTransaction_Event {
* The address of the contract that emitted the event.
*/
@Validate(IsEVMAddress)
@Transform(({ value }) => prefix0x(value).toLowerCase())
@ApiProperty({ description: `The address of the contract that emitted the event.`, example: "0x5d4BEB38B6b71aaF6e30D0F9FeB6e21a7Ac40b3a" })
emitterAddress: string;

/**
* An array of up to four 32-byte strings of indexed log arguments. The first string is the signature of the event.
*/
@Validate(IsHash32, { each: true })
@Transform(({ value }) => (value as string[]).map((val) => prefix0x(val).toLowerCase()))
@ApiProperty({
description: `An array of up to four 32-byte strings of indexed log arguments. The first string is the signature of the event.`,
example: ["0x0000000000000000000000000000000000000000000000000000000000000000"],
Expand All @@ -212,6 +78,7 @@ export class EVMTransaction_Event {
* Concatenated 32-byte strings of non-indexed log arguments. At least 32 bytes long.
*/
@Validate(Is0xHex)
@Transform(({ value }) => prefix0x(value).toLowerCase())
@ApiProperty({ description: `Concatenated 32-byte strings of non-indexed log arguments. At least 32 bytes long.`, example: "0x1234abcd" })
data: string;

Expand Down
Loading

0 comments on commit c105809

Please sign in to comment.