|
1 | | -import { BigDecimal, BigInt, ethereum, log } from "@graphprotocol/graph-ts" |
| 1 | +import { BigDecimal, BigInt, Bytes, ethereum, log } from "@graphprotocol/graph-ts" |
2 | 2 | import { AllocationClosed, AllocationCreated, AllocationResized, CurationCutSet, DelegationRatioSet, IndexingRewardsCollected, MaxPOIStalenessSet, ProvisionTokensRangeSet, QueryFeesCollected, RewardsDestinationSet, ServiceProviderRegistered, StakeToFeesRatioSet, ThawingPeriodRangeSet, VerifierCutRangeSet } from "../types/SubgraphService/SubgraphService" |
3 | 3 | import { batchUpdateSubgraphSignalledTokens, calculatePricePerShare, createOrLoadDataService, createOrLoadEpoch, createOrLoadGraphNetwork, createOrLoadIndexerQueryFeePaymentAggregation, createOrLoadPaymentSource, createOrLoadProvision, createOrLoadSubgraphDeployment, joinID, updateDelegationExchangeRate } from "./helpers/helpers" |
4 | | -import { Allocation, PublicPoiSubmission, Indexer, PoiSubmission, SubgraphDeployment } from "../types/schema" |
| 4 | +import { Allocation, Indexer, PoiSubmission, SubgraphDeployment } from "../types/schema" |
5 | 5 | import { addresses } from "../../config/addresses" |
6 | 6 | import { tuplePrefixBytes } from "./helpers/decoder" |
7 | 7 | import { createOrLoadIndexer } from "./helpers/helpers" |
@@ -255,22 +255,40 @@ export function handleIndexingRewardsCollected(event: IndexingRewardsCollected): |
255 | 255 | allocation.poiCount = allocation.poiCount!.plus(BigInt.fromI32(1)) |
256 | 256 | allocation.save() |
257 | 257 |
|
| 258 | + // Decode poi metadata |
| 259 | + let poiBlockNumber = 0 |
| 260 | + let poiIndexingStatus = 0 // 0 is unknown, 1 is healthy, 2 is unhealthy, 3 is failed |
| 261 | + let publicPoi = Bytes.fromHexString('0x') |
| 262 | + let poiMetadataDecoded = false |
| 263 | + |
| 264 | + let poiMetadata = ethereum.decode('(uint256,bytes32,uint8,uint8,uint256)', event.params.poiMetadata) |
| 265 | + if (poiMetadata != null && poiMetadata.kind == ethereum.ValueKind.TUPLE) { |
| 266 | + poiMetadataDecoded = true |
| 267 | + |
| 268 | + let tupleData = poiMetadata.toTuple() |
| 269 | + poiBlockNumber = tupleData[0].toI32() |
| 270 | + publicPoi = tupleData[1].toBytes() |
| 271 | + poiIndexingStatus = tupleData[2].toI32() |
| 272 | + |
| 273 | + // TODO: implement error code handling |
| 274 | + // let errorCode = tupleData[3].toBigInt() |
| 275 | + // let errorBlockNumber = tupleData[4].toBigInt() |
| 276 | + } else { |
| 277 | + log.error("IndexingRewardsCollected failed to decode poi metadata: {}", [event.params.poiMetadata.toHexString()]) |
| 278 | + } |
| 279 | + |
258 | 280 | // Create PoI submission |
259 | 281 | let poiSubmission = new PoiSubmission(joinID([event.transaction.hash.toHexString(), event.logIndex.toString()])) |
260 | 282 | poiSubmission.allocation = allocation.id |
261 | 283 | poiSubmission.poi = event.params.poi |
| 284 | + poiSubmission.publicPoi = publicPoi |
262 | 285 | poiSubmission.submittedAtEpoch = event.params.currentEpoch.toI32() |
263 | 286 | poiSubmission.presentedAtTimestamp = event.block.timestamp.toI32() |
| 287 | + poiSubmission.indexingStatus = poiIndexingStatus |
| 288 | + poiSubmission.blockNumber = poiBlockNumber |
| 289 | + poiSubmission.metadataDecoded = poiMetadataDecoded |
264 | 290 | poiSubmission.save() |
265 | 291 |
|
266 | | - // Create public PoI submission |
267 | | - let publicPoiSubmission = new PublicPoiSubmission(joinID([event.transaction.hash.toHexString(), event.logIndex.toString()])) |
268 | | - publicPoiSubmission.allocation = allocation.id |
269 | | - publicPoiSubmission.publicPoi = event.params.publicPoi |
270 | | - publicPoiSubmission.submittedAtEpoch = event.params.currentEpoch.toI32() |
271 | | - publicPoiSubmission.presentedAtTimestamp = event.block.timestamp.toI32() |
272 | | - publicPoiSubmission.save() |
273 | | - |
274 | 292 | // Update latest POI in allocation |
275 | 293 | allocation.poi = event.params.poi |
276 | 294 | allocation.latestPoiPresentedAt = event.block.timestamp.toI32() |
|
0 commit comments