Skip to content

Commit

Permalink
feat: add satp logging in all satges
Browse files Browse the repository at this point in the history
1. Improved SATP client and server stage services with databse logging.
2. Added a new logging file to centralize and simplify log operations.
3. Integrated Knex config into the Gateway.

Signed-off-by: Yogesh01000100 <[email protected]>
  • Loading branch information
Yogesh01000100 authored and RafaelAPB committed Dec 6, 2024
1 parent 7c16201 commit 0f9fb71
Show file tree
Hide file tree
Showing 20 changed files with 2,063 additions and 1,033 deletions.
4 changes: 3 additions & 1 deletion packages/cactus-plugin-satp-hermes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"db:migrate": "knex migrate:latest --knexfile src/knex/knexfile.js",
"db:migrate:production": "knex migrate:latest --env production --knexfile src/knex/knexfile.ts",
"db:seed": "knex seed:run --knexfile src/knex/knexfile.ts",
"db:cleanup": "find src/knex/data -name '.dev-*.sqlite3' -delete"
"db:cleanup": "find src/knex/ -name '.dev.local-*.sqlite3' -delete"
},
"jest": {
"moduleNameMapper": {
Expand Down Expand Up @@ -137,6 +137,7 @@
"kubo-rpc-client": "3.0.1",
"npm-run-all": "4.1.5",
"openzeppelin-solidity": "3.4.2",
"pg": "8.13.1",
"safe-stable-stringify": "2.5.0",
"secp256k1": "4.0.3",
"socket.io": "4.6.2",
Expand All @@ -160,6 +161,7 @@
"@types/fs-extra": "11.0.4",
"@types/google-protobuf": "3.15.12",
"@types/node": "18.18.2",
"@types/pg": "8.11.10",
"@types/swagger-ui-express": "4.1.6",
"@types/tape": "4.13.4",
"@types/uuid": "10.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import path from "path";
import { v4 as uuidv4 } from "uuid";
import dotenv from "dotenv";
import { Knex } from "knex";

const envPath = process.env.ENV_PATH;
dotenv.config({ path: envPath });

module.exports = {
const config: { [key: string]: Knex.Config } = {
development: {
client: "sqlite3",
connection: {
Expand All @@ -20,7 +21,7 @@ module.exports = {
client: "pg",
connection: {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
port: Number(process.env.DB_PORT),
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
Expand All @@ -30,3 +31,5 @@ module.exports = {
},
},
};

export default config;
9 changes: 6 additions & 3 deletions packages/cactus-plugin-satp-hermes/src/knex/knexfile.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import path from "path";
import { v4 as uuidv4 } from "uuid";
import dotenv from "dotenv";
import { Knex } from "knex";

const envPath = process.env.ENV_PATH;
dotenv.config({ path: envPath });

module.exports = {
const config: { [key: string]: Knex.Config } = {
development: {
client: "sqlite3",
connection: {
filename: path.join(__dirname, "data", "/.dev-" + uuidv4() + ".sqlite3"),
filename: path.resolve(__dirname, `.dev.local-${uuidv4()}.sqlite3`),
},
migrations: {
directory: path.resolve(__dirname, "migrations"),
Expand All @@ -23,7 +24,7 @@ module.exports = {
client: "pg",
connection: {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
port: Number(process.env.DB_PORT),
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
Expand All @@ -33,3 +34,5 @@ module.exports = {
},
},
};

export default config;
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import { IntegrationsEndpointV1 } from "../web-services/integrations-endpoint";
import { executeGetHealthCheck } from "./admin/get-healthcheck-handler-service";
import { executeGetStatus } from "./admin/get-status-handler-service";
import { executeTransact } from "./transaction/transact-handler-service";
import {
ILocalLogRepository,
IRemoteLogRepository,
} from "../repository/interfaces/repository";

export interface BLODispatcherOptions {
logger: Logger;
Expand All @@ -41,6 +45,8 @@ export interface BLODispatcherOptions {
signer: JsObjectSigner;
bridgesManager: SATPBridgesManager;
pubKey: string;
localRepository: ILocalLogRepository;
remoteRepository: IRemoteLogRepository;
}

export class BLODispatcher {
Expand All @@ -54,19 +60,26 @@ export class BLODispatcher {
private manager: SATPManager;
private orchestrator: GatewayOrchestrator;
private bridgeManager: SATPBridgesManager;
private localRepository: ILocalLogRepository;
private remoteRepository: IRemoteLogRepository;

constructor(public readonly options: BLODispatcherOptions) {
const fnTag = `${BLODispatcher.CLASS_NAME}#constructor()`;
Checks.truthy(options, `${fnTag} arg options`);

this.level = this.options.logLevel || "INFO";
this.label = this.className;
this.logger = LoggerProvider.getOrCreate({ level: this.level, label: this.label });
this.logger = LoggerProvider.getOrCreate({
level: this.level,
label: this.label,
});
this.instanceId = options.instanceId;
this.logger.info(`Instantiated ${this.className} OK`);
this.orchestrator = options.orchestrator;
const signer = options.signer;
const ourGateway = this.orchestrator.ourGateway;
this.localRepository = options.localRepository;
this.remoteRepository = options.remoteRepository;

this.bridgeManager = options.bridgesManager;

Expand All @@ -78,6 +91,8 @@ export class BLODispatcher {
bridgeManager: this.bridgeManager,
orchestrator: this.orchestrator,
pubKey: options.pubKey,
localRepository: this.localRepository,
remoteRepository: this.remoteRepository,
};

this.manager = new SATPManager(SATPManagerOpts);
Expand Down
Loading

0 comments on commit 0f9fb71

Please sign in to comment.