Skip to content

Commit

Permalink
fix: abi.decode potential decoding failure
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmardefago committed Feb 24, 2025
1 parent dfa15dd commit 3c5144b
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/mappings/subgraphService.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { ethereum } from "@graphprotocol/graph-ts"
import { ethereum, ValueKind, log } from "@graphprotocol/graph-ts"
import { RewardsDestinationSet, ServiceProviderRegistered } from "../types/SubgraphService/SubgraphService"
import { createOrLoadProvision } from "./helpers/helpers"

export function handleServiceProviderRegistered(event: ServiceProviderRegistered): void {
let decodedCalldata = ethereum.decode('(string,string,address)', event.params.data).toTuple()
let provision = createOrLoadProvision(event.params.serviceProvider, event.address, event.block.timestamp)
provision.url = decodedCalldata[0].toString()
provision.geoHash = decodedCalldata[1].toString()
provision.save()
let decodedCalldata = ethereum.decode('(string,string,address)', event.params.data)
if( decodedCalldata != null && decodedCalldata.kind == ethereum.ValueKind.TUPLE) {
let tupleData = decodedCalldata.toTuple()
let provision = createOrLoadProvision(event.params.serviceProvider, event.address, event.block.timestamp)
provision.url = tupleData[0].toString()
provision.geoHash = tupleData[1].toString()
provision.save()
} else {
log.warning("ServiceProviderRegistered failed to decode: {}", [event.params.data.toHexString()])
}
}

export function handleRewardsDestinationSet(event: RewardsDestinationSet): void {
Expand Down

0 comments on commit 3c5144b

Please # to comment.