|
| 1 | +import { GroupRunner } from '@chainlink/external-adapter-framework/util/group-runner' |
1 | 2 | import { TransportDependencies } from '@chainlink/external-adapter-framework/transports' |
2 | 3 | import { AdapterResponse, makeLogger, sleep } from '@chainlink/external-adapter-framework/util' |
3 | 4 | import { SubscriptionTransport } from '@chainlink/external-adapter-framework/transports/abstract/subscription' |
@@ -95,24 +96,18 @@ export class DLCBTCPorTransport extends SubscriptionTransport<TransportTypes> { |
95 | 96 | getBitcoinNetwork(this.settings.BITCOIN_NETWORK), |
96 | 97 | ) |
97 | 98 |
|
98 | | - let totalPoR = 0 |
99 | 99 | const concurrencyGroupSize = this.settings.BITCOIN_RPC_GROUP_SIZE || vaultData.length |
| 100 | + |
100 | 101 | // Process vault batches sequentially to not overload the BITCOIN_RPC server |
101 | | - for (let i = 0; i < vaultData.length; i += concurrencyGroupSize) { |
102 | | - let group = [] |
103 | | - if (this.settings.BITCOIN_RPC_GROUP_SIZE > 0) { |
104 | | - group = vaultData.slice(i, i + concurrencyGroupSize) |
105 | | - } else { |
106 | | - group = vaultData |
107 | | - } |
108 | | - const deposits = await Promise.all( |
109 | | - group.map(async (vault) => { |
110 | | - return await this.verifyVaultDeposit(vault, attestorPublicKey) |
111 | | - }), |
112 | | - ) |
113 | | - // totalPoR represents total proof of reserves value in bitcoins |
114 | | - totalPoR += deposits.reduce((sum, deposit) => sum + deposit, 0) |
115 | | - } |
| 102 | + const runner = new GroupRunner(concurrencyGroupSize) |
| 103 | + const getVaultDeposit = runner.wrapFunction((vault: RawVault) => |
| 104 | + this.verifyVaultDeposit(vault, attestorPublicKey), |
| 105 | + ) |
| 106 | + |
| 107 | + const deposits = await Promise.all(vaultData.map(getVaultDeposit)) |
| 108 | + |
| 109 | + // totalPoR represents total proof of reserves value in bitcoins |
| 110 | + const totalPoR = deposits.reduce((sum, deposit) => sum + deposit, 0) |
116 | 111 |
|
117 | 112 | // multiply by 10^8 to convert to satoshis |
118 | 113 | const result = totalPoR * 10 ** 8 |
|
0 commit comments