Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e75f585
adds factory pattern for relay class, to support future redis client …
konstantinabl Oct 14, 2025
7d14b31
imports from dist
konstantinabl Oct 14, 2025
84a514c
fixes acceptance tests
konstantinabl Oct 15, 2025
3e06df5
fixes integration tests
konstantinabl Oct 15, 2025
1671238
fix relay logger
konstantinabl Oct 15, 2025
8ad1fdd
remove relay return
konstantinabl Oct 15, 2025
930a838
adds register clean
konstantinabl Oct 16, 2025
43ca2a8
fixes ws server tests and transforms them to unit
konstantinabl Oct 16, 2025
89916d5
removes eslint disable
konstantinabl Oct 16, 2025
782b71a
addresses PR comments
konstantinabl Oct 16, 2025
51cce80
fixes tests in server.spec
konstantinabl Oct 16, 2025
dd8477e
removes eslint disabled
konstantinabl Oct 16, 2025
a8ee86e
fixes comments
konstantinabl Oct 16, 2025
0063ff1
improves commenting
konstantinabl Oct 16, 2025
ffd9d08
removes unused variables
konstantinabl Oct 16, 2025
bd2f3bb
reverts check out of scope
konstantinabl Oct 16, 2025
09dad39
removes require from acceptance tests
konstantinabl Oct 16, 2025
d59e2d7
removes unused variable
konstantinabl Oct 16, 2025
96e560c
removes unused import
konstantinabl Oct 16, 2025
e7ea819
adds dynamic loading for tier variables in method config
konstantinabl Oct 16, 2025
dce661d
fixes relay init
konstantinabl Oct 16, 2025
002ddbb
fixes unit tests
konstantinabl Oct 17, 2025
894988c
turnoff unused expression rules for tests
konstantinabl Oct 17, 2025
5412778
removes unused var app
konstantinabl Oct 17, 2025
1af001d
fixes ws server tests
konstantinabl Oct 17, 2025
409cdeb
reverts changes to assertions
konstantinabl Oct 17, 2025
67f6e89
removes unused eslint disable
konstantinabl Oct 17, 2025
5138a52
improves integration test
konstantinabl Oct 17, 2025
3d7d9cd
removes all instantiations using new isntead of init from tests
konstantinabl Oct 17, 2025
dd4e210
removes unused methods
konstantinabl Oct 17, 2025
071aa7c
adds comment
konstantinabl Oct 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ module.exports = {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-var-requires": "warn",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/ban-types": "warn",
"no-trailing-spaces": "error",
"no-useless-escape": "warn",
"prefer-const": "error",
Expand Down
30 changes: 27 additions & 3 deletions packages/relay/src/lib/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ export class Relay {
private readonly rpcMethodDispatcher: RpcMethodDispatcher;

/**
* Initializes the main components of the relay service, including Hedera network clients,
* Ethereum-compatible interfaces, caching, metrics, and subscription management.
* Private constructor to prevent direct instantiation.
* Use Relay.init() static factory method instead.
*
* @param {Logger} logger - Logger instance for logging system messages.
* @param {Registry} register - Registry instance for registering metrics.
*/
constructor(
private constructor(
private readonly logger: Logger,
register: Registry,
) {
Expand Down Expand Up @@ -341,4 +341,28 @@ export class Relay {
this.logger.info(`Operator account '${operator}' has balance: ${balance}`);
}
}

/**
* Static factory method to create and initialize a Relay instance.
* This is the recommended way to create a Relay instance as it ensures
* all async initialization (operator balance check) is complete.
*
* @param {Logger} logger - Logger instance for logging system messages.
* @param {Registry} register - Registry instance for registering metrics.
* @returns {Promise<Relay>} A fully initialized Relay instance.
*
* @example
* ```typescript
* const relay = await Relay.init(logger, register);
* ```
*/
static async init(logger: Logger, register: Registry): Promise<Relay> {
// Create Relay instance
const relay = new Relay(logger, register);

// Check operator balance if not in read-only mode
await relay.ensureOperatorHasBalance();

return relay;
}
}
16 changes: 8 additions & 8 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';

import { setServerTimeout } from './koaJsonRpc/lib/utils'; // Import the 'setServerTimeout' function from the correct location
import app, { logger, relay } from './server';
import { setServerTimeout } from './koaJsonRpc/lib/utils';
import { initializeServer, logger } from './server';

async function main() {
try {
await relay.ensureOperatorHasBalance();
// Initialize server with the fully initialized Relay
const { app } = await initializeServer();
const server = app.listen({ port: ConfigService.get('SERVER_PORT'), host: ConfigService.get('SERVER_HOST') });

// set request timeout to ensure sockets are closed after specified time of inactivity
setServerTimeout(server);
} catch (error) {
logger.fatal(error);
process.exit(1);
}

const server = app.listen({ port: ConfigService.get('SERVER_PORT'), host: ConfigService.get('SERVER_HOST') });

// set request timeout to ensure sockets are closed after specified time of inactivity
setServerTimeout(server);
}

main();
Loading
Loading