Skip to content

Commit

Permalink
new: storing nft owner address i.e. validator id owner address in val…
Browse files Browse the repository at this point in the history
…idator entity
  • Loading branch information
itzmeanjan committed Jan 1, 2021
1 parent 794c2d8 commit e2b7a57
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
13 changes: 1 addition & 12 deletions root/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
13 changes: 13 additions & 0 deletions root/src/mappings/staking-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'


Expand Down Expand Up @@ -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

Expand Down

0 comments on commit e2b7a57

Please sign in to comment.