Skip to content

Commit

Permalink
chore: keep the old behavior
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Yanev <victor.yanev@limechain.tech>
  • Loading branch information
victor-yanev committed Dec 17, 2024
1 parent be1b4f8 commit e3fc142
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
6 changes: 4 additions & 2 deletions packages/relay/src/lib/services/hapiService/hapiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,10 @@ export default class HAPIService {
client = Client.forNetwork(JSON.parse(hederaNetwork));
}

const operator = Utils.getOperator(type);
client.setOperator(operator.accountId, operator.privateKey);
const operator = Utils.getOperator(logger, type);
if (operator) {
client.setOperator(operator.accountId, operator.privateKey);
}

// @ts-ignore
client.setTransportSecurity(ConfigService.get('CLIENT_TRANSPORT_SECURITY') ?? false);
Expand Down
10 changes: 7 additions & 3 deletions packages/relay/src/lib/services/hbarLimitService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
*/

import { ConfigService } from '@hashgraph/json-rpc-config-service/dist/services';
import { zeroAddress } from '@ethereumjs/util';
import { AccountId, Hbar } from '@hashgraph/sdk';
import { Logger } from 'pino';
import { Counter, Gauge, Registry } from 'prom-client';
Expand Down Expand Up @@ -99,8 +99,12 @@ export class HbarLimitService implements IHbarLimitService {
) {
this.reset = this.getResetTimestamp();

const operator = Utils.getOperator();
this.operatorAddress = prepend0x(AccountId.fromString(operator.accountId.toString()).toSolidityAddress());
const operator = Utils.getOperator(logger);
if (operator) {
this.operatorAddress = prepend0x(AccountId.fromString(operator.accountId.toString()).toSolidityAddress());
} else {
this.operatorAddress = zeroAddress();

Check warning on line 106 in packages/relay/src/lib/services/hbarLimitService/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/relay/src/lib/services/hbarLimitService/index.ts#L106

Added line #L106 was not covered by tests
}

const totalBudget = HbarLimitService.TIER_LIMITS[SubscriptionTier.OPERATOR];
if (totalBudget.toTinybars().lte(0)) {
Expand Down
8 changes: 5 additions & 3 deletions packages/relay/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ export class Utils {

/**
* Gets operator credentials based on the provided type.
* @param {Logger} logger - The logger instance
* @param {string | null} type - The type of operator (e.g. 'eth_sendRawTransaction')
* @returns {Operator} The operator credentials
* @returns {Operator | null} The operator credentials or null if not found
*/
public static getOperator(type: string | null = null): Operator {
public static getOperator(logger: Logger, type: string | null = null): Operator | null {
let operatorId: string;
let operatorKey: string;

Expand All @@ -157,7 +158,8 @@ export class Utils {
}

if (!operatorId || !operatorKey) {
throw new Error(`Invalid operatorId or operatorKey for ${type ?? 'main'} client.`);
logger.warn(`Invalid operatorId or operatorKey for ${type ?? 'main'} client.`);
return null;

Check warning on line 162 in packages/relay/src/utils.ts

View check run for this annotation

Codecov / codecov/patch

packages/relay/src/utils.ts#L162

Added line #L162 was not covered by tests
}

return {
Expand Down

0 comments on commit e3fc142

Please sign in to comment.