diff --git a/src/mappings/NewEra.ts b/src/mappings/NewEra.ts index f933d484..05b27af5 100644 --- a/src/mappings/NewEra.ts +++ b/src/mappings/NewEra.ts @@ -35,9 +35,8 @@ async function processEraStakersClipped( const exposures = await api.query.staking.erasStakersClipped.entries(currentEra); - const eraValidatorInfos = exposures.map(([key, exposure]) => { + for (const [key, exposure] of exposures) { const [, validatorId] = key.args; - let validatorIdString = validatorId.toString(); const exp = exposure as unknown as Exposure; const eraValidatorInfo = new EraValidatorInfo( @@ -53,10 +52,8 @@ async function processEraStakersClipped( } as IndividualExposure; }), ); - return eraValidatorInfo.save(); - }); - - await Promise.allSettled(eraValidatorInfos); + await eraValidatorInfo.save(); + } } async function processEraStakersPaged( @@ -95,7 +92,7 @@ async function processEraStakersPaged( {}, ); - const eraValidatorInfos = overview.map(([key, exp]) => { + for (const [key, exp] of overview) { const exposure = ( exp as unknown as Option ).unwrap(); @@ -115,8 +112,6 @@ async function processEraStakersPaged( exposure.own.toBigInt(), others, ); - return eraValidatorInfo.save(); - }); - - await Promise.allSettled(eraValidatorInfos); + await eraValidatorInfo.save(); + } } diff --git a/src/mappings/Rewards.ts b/src/mappings/Rewards.ts index 5d2ea8f3..16e99b7b 100644 --- a/src/mappings/Rewards.ts +++ b/src/mappings/Rewards.ts @@ -350,61 +350,53 @@ async function buildRewardEvents( let blockNumber = block.block.header.number.toString(); let blockTimestamp = timestamp(block); - const [, savingPromises] = block.events.reduce<[A, Promise[]]>( - (accumulator, eventRecord, eventIndex) => { - let [innerAccumulator, currentPromises] = accumulator; - - if ( - !( - eventRecord.event.method == eventMethod && - eventRecord.event.section == eventSection - ) - ) - return accumulator; + let innerAccumulator = initialInnerAccumulator; + for (let eventIndex = 0; eventIndex < block.events.length; eventIndex++) { + const eventRecord = block.events[eventIndex]; - let [account, amount] = decodeDataFromReward( - eventRecordToSubstrateEvent(eventRecord), - ); + if ( + !( + eventRecord.event.method === eventMethod && + eventRecord.event.section === eventSection + ) + ) + continue; - const newAccumulator = produceNewAccumulator( - innerAccumulator, - account.toString(), - ); + let [account, amount] = decodeDataFromReward( + eventRecordToSubstrateEvent(eventRecord), + ); - const eventId = eventIdFromBlockAndIdx( - blockNumber, - eventIndex.toString(), - ); + innerAccumulator = produceNewAccumulator( + innerAccumulator, + account.toString(), + ); - const accountAddress = account.toString(); - const destinationAddress = accountsMapping[accountAddress]; + const eventId = eventIdFromBlockAndIdx(blockNumber, eventIndex.toString()); - const element = new HistoryElement( - eventId, - block.block.header.number.toNumber(), - blockTimestamp, - destinationAddress != undefined ? destinationAddress : accountAddress, - ); + const accountAddress = account.toString(); + const destinationAddress = accountsMapping[accountAddress]; - if (extrinsic !== undefined) { - element.extrinsicHash = extrinsic.extrinsic.hash.toString(); - element.extrinsicIdx = extrinsic.idx; - } - element.reward = produceReward( - newAccumulator, - eventIndex, - accountAddress, - amount.toString(), - ); + const element = new HistoryElement( + eventId, + block.block.header.number.toNumber(), + blockTimestamp, + destinationAddress !== undefined ? destinationAddress : accountAddress, + ); - currentPromises.push(element.save()); + if (extrinsic !== undefined) { + element.extrinsicHash = extrinsic.extrinsic.hash.toString(); + element.extrinsicIdx = extrinsic.idx; + } - return [newAccumulator, currentPromises]; - }, - [initialInnerAccumulator, []], - ); + element.reward = produceReward( + innerAccumulator, + eventIndex, + accountAddress, + amount.toString(), + ); - await Promise.allSettled(savingPromises); + await element.save(); + } } async function updateAccumulatedReward(