diff --git a/root/schema.graphql b/root/schema.graphql index d201338..762a40c 100644 --- a/root/schema.graphql +++ b/root/schema.graphql @@ -74,18 +74,7 @@ type TokenMapping @entity { type Validator @entity { id: ID! validatorId: BigInt! - # Below could be added, but that causes one - # issue : In handler function how should we be able to - # understand which chain we're currently working with ? - # - # Because that affects our which contract should be called - # for checking ownership of NFT contract - # - # It's better done offline, before serving request, backend can - # query blockchain node for this piece of data using standard `ownerOf` - # function call of standard ERC721, where parameter should be passed `validatorId` - # - # owner: Bytes! + owner: Bytes! signer: Bytes! signerPubKey: Bytes! liquidatedRewards: BigInt! diff --git a/root/src/mappings/staking-info.ts b/root/src/mappings/staking-info.ts index a07e5c8..6ab68d4 100644 --- a/root/src/mappings/staking-info.ts +++ b/root/src/mappings/staking-info.ts @@ -30,6 +30,14 @@ import { ConfirmAuction, } from '../../generated/StakingInfo/StakingInfo' +// using network address from config file +// to be passed to client when creating instance +// of contract, StakingNft, for calling `ownerOf` function +import NetworkConfig from '../network.json' + +// This is the contract we're going to interact with when `Staked` event is emitted +import {StakingNft} from '../../generated/StakingNft/StakingNft' + const STAKING_PARAMS_ID = 'staking:params' @@ -65,6 +73,11 @@ export function handleStaked(event: Staked): void { validator.signer = event.params.signer validator.activationEpoch = event.params.activationEpoch + // Keeping NFT owner address, to be helpful while responding + // client queries in staking API + let nft = StakingNft.bind(Address.fromString(NetworkConfig.stakingNft.address)) + validator.owner = nft.ownerOf(event.params.validatorId) + validator.totalStaked = event.params.total validator.selfStake = event.params.amount