Skip to content

Commit

Permalink
fix: do not ignore error when EVM address is not provided to `addExpe…
Browse files Browse the repository at this point in the history
…nse`

Signed-off-by: Victor Yanev <[email protected]>
  • Loading branch information
victor-yanev committed Dec 10, 2024
1 parent 0307f32 commit 44823cd
Show file tree
Hide file tree
Showing 2 changed files with 381 additions and 264 deletions.
18 changes: 6 additions & 12 deletions packages/relay/src/lib/services/hbarLimitService/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class HbarLimitService implements IHbarLimitService {
}
let spendingPlan = await this.getSpendingPlan(evmAddress, requestDetails);
if (!spendingPlan) {
// Create a basic spending plan if none exists for the evm address or ip address
// Create a basic spending plan if none exists for the evm address
spendingPlan = await this.createSpendingPlanForAddress(evmAddress, requestDetails);
}

Expand Down Expand Up @@ -283,6 +283,8 @@ export class HbarLimitService implements IHbarLimitService {

const operatorPlan = await this.getOperatorSpendingPlan(requestDetails);
await this.hbarSpendingPlanRepository.addToAmountSpent(operatorPlan.id, cost, requestDetails, this.limitDuration);
// Done asynchronously in the background
this.updateAverageAmountSpentPerSubscriptionTier(operatorPlan.subscriptionTier, requestDetails).then();

const remainingBudget = await this.getRemainingBudget(requestDetails);
this.hbarLimitRemainingGauge.set(remainingBudget.toTinybars().toNumber());
Expand All @@ -297,15 +299,7 @@ export class HbarLimitService implements IHbarLimitService {

let spendingPlan = await this.getSpendingPlan(evmAddress, requestDetails);
if (!spendingPlan) {
if (evmAddress) {
// Create a basic spending plan if none exists for the evm address
spendingPlan = await this.createSpendingPlanForAddress(evmAddress, requestDetails);
} else {
this.logger.warn(
`${requestDetails.formattedRequestId} Cannot add expense to a spending plan without an evm address or ip address`,
);
return;
}
spendingPlan = await this.createSpendingPlanForAddress(evmAddress, requestDetails);
}

if (this.logger.isLevelEnabled('trace')) {
Expand Down Expand Up @@ -458,7 +452,6 @@ export class HbarLimitService implements IHbarLimitService {
return await this.getSpendingPlanByEvmAddress(evmAddress, requestDetails);
} catch (error) {
this.logger.warn(
error,
`${requestDetails.formattedRequestId} Failed to get spending plan for evm address '${evmAddress}'`,
);
}
Expand All @@ -468,9 +461,10 @@ export class HbarLimitService implements IHbarLimitService {
try {
return await this.getSpendingPlanByIPAddress(requestDetails);
} catch (error) {
this.logger.warn(error, `${requestDetails.formattedRequestId} Failed to get spending plan`);
this.logger.warn(`${requestDetails.formattedRequestId} Failed to get spending plan for ip address`);
}
}

return null;
}

Expand Down
Loading

0 comments on commit 44823cd

Please sign in to comment.