Skip to content
Merged
Changes from all commits
Commits
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
56 changes: 35 additions & 21 deletions src/subdomains/supporting/log/log-job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ export class LogJobService {

private readonly unavailableClientWarningsLogged = new Set<Blockchain>();

private paymentBalanceCache: Map<number, BlockchainTokenBalance> = new Map();
private paymentBalanceCacheTime: Date = new Date(0);

private customBalanceCache: { blockchain: Blockchain; balances: BlockchainTokenBalance[] }[] = [];
private customBalanceCacheTime: Date = new Date(0);

constructor(
private readonly tradingRuleService: TradingRuleService,
private readonly assetService: AssetService,
Expand Down Expand Up @@ -216,32 +222,40 @@ export class LogJobService {
}),
);

const customBalances = await Promise.all(
Array.from(customAssetMap.entries()).map(async ([b, a]) => {
try {
const client = this.blockchainRegistryService.getClient(b);
if (!client) {
if (!this.unavailableClientWarningsLogged.has(b)) {
this.logger.warn(`Blockchain client not configured for ${b} - skipping custom balances`);
this.unavailableClientWarningsLogged.add(b);
if (Util.minutesDiff(this.customBalanceCacheTime) >= 60) {
this.customBalanceCache = await Promise.all(
Array.from(customAssetMap.entries()).map(async ([b, a]) => {
try {
const client = this.blockchainRegistryService.getClient(b);
if (!client) {
if (!this.unavailableClientWarningsLogged.has(b)) {
this.logger.warn(`Blockchain client not configured for ${b} - skipping custom balances`);
this.unavailableClientWarningsLogged.add(b);
}
return { blockchain: b, balances: [] };
}

const balances = await Util.timeout(
this.getCustomBalances(client, a, Config.financialLog.customAddresses).then((b) => b.flat()),
30000,
);
return { blockchain: b, balances };
} catch (e) {
this.logger.error(`Error in FinanceLog customBalances for blockchain ${b}:`, e);
return { blockchain: b, balances: [] };
}

const balances = await Util.timeout(
this.getCustomBalances(client, a, Config.financialLog.customAddresses).then((b) => b.flat()),
30000,
);
return { blockchain: b, balances };
} catch (e) {
this.logger.error(`Error in FinanceLog customBalances for blockchain ${b}:`, e);
return { blockchain: b, balances: [] };
}
}),
);
}),
);
this.customBalanceCacheTime = new Date();
}
const customBalances = this.customBalanceCache;

// payment deposit address balance (Monero/Lightning have no separated balance)
const paymentDepositBalances = await this.paymentBalanceService.getPaymentBalances(assets, true);
if (Util.minutesDiff(this.paymentBalanceCacheTime) >= 60) {
this.paymentBalanceCache = await this.paymentBalanceService.getPaymentBalances(assets, true);
this.paymentBalanceCacheTime = new Date();
}
const paymentDepositBalances = this.paymentBalanceCache;

// banks
const olkyBank = await this.bankService.getBankInternal(IbanBankName.OLKY, 'EUR');
Expand Down
Loading