|
| 1 | +import { GroupRunner } from '@chainlink/external-adapter-framework/util/group-runner' |
1 | 2 | import { EndpointContext } from '@chainlink/external-adapter-framework/adapter' |
2 | 3 | import { BaseEndpointTypes, inputParameters } from '../endpoint/balance' |
3 | 4 | import { TransportDependencies } from '@chainlink/external-adapter-framework/transports' |
4 | 5 | import { SubscriptionTransport } from '@chainlink/external-adapter-framework/transports/abstract/subscription' |
5 | | -import { |
6 | | - AdapterResponse, |
7 | | - makeLogger, |
8 | | - sleep, |
9 | | - splitArrayIntoChunks, |
10 | | -} from '@chainlink/external-adapter-framework/util' |
| 6 | +import { AdapterResponse, makeLogger, sleep } from '@chainlink/external-adapter-framework/util' |
11 | 7 | import { ApiPromise, WsProvider } from '@polkadot/api' |
12 | 8 |
|
13 | 9 | const logger = makeLogger('PolkadotBalanceLogger') |
@@ -78,23 +74,23 @@ export class BalanceTransport extends SubscriptionTransport<BalanceTransportType |
78 | 74 | try { |
79 | 75 | // Break addresses down into batches to execute asynchronously |
80 | 76 | // Firing requests for all addresses all at once could hit rate limiting for large address pools |
81 | | - const batchedAddresses = splitArrayIntoChunks(addresses, this.config.BATCH_SIZE) |
82 | | - for (const batch of batchedAddresses) { |
83 | | - await Promise.all( |
84 | | - batch.map((address) => { |
85 | | - const balancePromise = this.api.query.system.account(address).then((codec) => { |
86 | | - const balance = codec.toJSON() as unknown as ProviderResponse |
87 | | - if (balance) { |
88 | | - result.push({ |
89 | | - address, |
90 | | - balance: parseInt(balance.data?.free || '0x0', 16).toString(), |
91 | | - }) |
92 | | - } |
93 | | - }) |
94 | | - return balancePromise |
95 | | - }), |
96 | | - ) |
97 | | - } |
| 77 | + const runner = new GroupRunner(this.config.BATCH_SIZE) |
| 78 | + const queryAccount = runner.wrapFunction((address) => this.api.query.system.account(address)) |
| 79 | + |
| 80 | + await Promise.all( |
| 81 | + addresses.map((address) => { |
| 82 | + const balancePromise = queryAccount(address).then((codec) => { |
| 83 | + const balance = codec.toJSON() as unknown as ProviderResponse |
| 84 | + if (balance) { |
| 85 | + result.push({ |
| 86 | + address, |
| 87 | + balance: parseInt(balance.data?.free || '0x0', 16).toString(), |
| 88 | + }) |
| 89 | + } |
| 90 | + }) |
| 91 | + return balancePromise |
| 92 | + }), |
| 93 | + ) |
98 | 94 | } catch (e) { |
99 | 95 | logger.error(e, 'Failed to retrieve balances') |
100 | 96 | return { |
|
0 commit comments