Issue28 track metadata updates (#47)

* add datasource for the metadata events.

* handle metadata created/updated events, record (tx, blocknumber, timestamp, user) and update corresponding datatoken with update count.

* add list of metadata updates to the datatoken entity

* fix style issues

* style fix.

Co-authored-by: ssallam <travis@travis-ci.org>
This commit is contained in:
Samer 2021-03-04 11:38:20 +01:00 committed by GitHub
parent 2125e16e91
commit bf158af3c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 2566 additions and 0 deletions

2418
abis/Metadata.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -131,12 +131,26 @@ type Datatoken @entity {
holderCount: BigInt! # Number of addresses holding a balance of datatoken holderCount: BigInt! # Number of addresses holding a balance of datatoken
orderCount: BigInt! # Number of orders executed for this dataset orderCount: BigInt! # Number of orders executed for this dataset
metadataUpdateCount: BigInt!
createTime: Int! # Block time datatoken was created createTime: Int! # Block time datatoken was created
tx: Bytes # Datatoken creation transaction id tx: Bytes # Datatoken creation transaction id
balances: [TokenBalance!] @derivedFrom(field: "datatokenId") balances: [TokenBalance!] @derivedFrom(field: "datatokenId")
orders: [TokenOrder!] @derivedFrom(field: "datatokenId") orders: [TokenOrder!] @derivedFrom(field: "datatokenId")
updates: [MetadataUpdate!] @derivedFrom(field: "datatokenId") # list of MetadataUpdate objects
}
type MetadataUpdate @entity {
id: ID! # update tx + datatokenAddress
datatokenId: Datatoken!
datatokenAddress: String!
userAddress: String!
block: Int!
timestamp: Int!
tx: Bytes!
} }
type TokenOrder @entity { type TokenOrder @entity {

View File

@ -37,6 +37,7 @@ export function handleNewToken(event: TokenRegistered): void {
datatoken.holderCount = BigInt.fromI32(0) datatoken.holderCount = BigInt.fromI32(0)
datatoken.orderCount = BigInt.fromI32(0) datatoken.orderCount = BigInt.fromI32(0)
datatoken.metadataUpdateCount = BigInt.fromI32(0)
datatoken.createTime = event.block.timestamp.toI32() datatoken.createTime = event.block.timestamp.toI32()
datatoken.tx = event.transaction.hash datatoken.tx = event.transaction.hash

45
src/mappings/metadata.ts Normal file
View File

@ -0,0 +1,45 @@
import { BigInt, ethereum } from '@graphprotocol/graph-ts'
import { MetadataUpdated, MetadataCreated } from '../@types/Metadata/Metadata'
import { Datatoken, MetadataUpdate } from '../@types/schema'
export function handleMetadataEvent(
event: ethereum.Event,
dtAddress: string,
updatedBy: string
): void {
const datatoken = Datatoken.load(dtAddress)
const tx = event.transaction.hash
const id = tx.toHexString().concat('-').concat(dtAddress)
const metadataUpdate = new MetadataUpdate(id)
metadataUpdate.tx = tx
metadataUpdate.block = event.block.number.toI32()
metadataUpdate.timestamp = event.block.timestamp.toI32()
metadataUpdate.datatokenAddress = dtAddress
metadataUpdate.userAddress = updatedBy
metadataUpdate.datatokenId = dtAddress
metadataUpdate.save()
datatoken.metadataUpdateCount = datatoken.metadataUpdateCount.plus(
BigInt.fromI32(1)
)
datatoken.save()
}
export function handleMetadataUpdated(event: MetadataUpdated): void {
handleMetadataEvent(
event,
event.params.dataToken.toHexString(),
event.params.updatedBy.toHexString()
)
}
export function handleMetadataCreated(event: MetadataCreated): void {
handleMetadataEvent(
event,
event.params.dataToken.toHexString(),
event.params.createdBy.toHexString()
)
}

View File

@ -44,6 +44,28 @@ dataSources:
eventHandlers: eventHandlers:
- event: TokenRegistered(indexed address,string,string,uint256,indexed address,indexed string) - event: TokenRegistered(indexed address,string,string,uint256,indexed address,indexed string)
handler: handleNewToken handler: handleNewToken
- kind: ethereum/contract
name: Metadata
network: polygon
source:
address: '0x80E63f73cAc60c1662f27D2DFd2EA834acddBaa8'
abi: Metadata
startBlock: 11005247
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
file: ./src/mappings/metadata.ts
entities:
- Metadata
abis:
- name: Metadata
file: ./abis/Metadata.json
eventHandlers:
- event: MetadataCreated(indexed address,indexed address,bytes,bytes)
handler: handleMetadataCreated
- event: MetadataUpdated(indexed address,indexed address,bytes,bytes)
handler: handleMetadataUpdated
templates: templates:
- kind: ethereum/contract - kind: ethereum/contract
name: Pool name: Pool

View File

@ -44,6 +44,28 @@ dataSources:
eventHandlers: eventHandlers:
- event: TokenRegistered(indexed address,string,string,uint256,indexed address,indexed string) - event: TokenRegistered(indexed address,string,string,uint256,indexed address,indexed string)
handler: handleNewToken handler: handleNewToken
- kind: ethereum/contract
name: Metadata
network: rinkeby
source:
address: '0xfd8a7b6297153397b7eb4356c47dbd381d58bff4'
abi: Metadata
startBlock: 7298808
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
file: ./src/mappings/metadata.ts
entities:
- Metadata
abis:
- name: Metadata
file: ./abis/Metadata.json
eventHandlers:
- event: MetadataCreated(indexed address,indexed address,bytes,bytes)
handler: handleMetadataCreated
- event: MetadataUpdated(indexed address,indexed address,bytes,bytes)
handler: handleMetadataUpdated
templates: templates:
- kind: ethereum/contract - kind: ethereum/contract
name: Pool name: Pool

View File

@ -44,6 +44,28 @@ dataSources:
eventHandlers: eventHandlers:
- event: TokenRegistered(indexed address,string,string,uint256,indexed address,indexed string) - event: TokenRegistered(indexed address,string,string,uint256,indexed address,indexed string)
handler: handleNewToken handler: handleNewToken
- kind: ethereum/contract
name: Metadata
network: ropsten
source:
address: '0x3cd7Ef1F207E1a46AAd7D5d7F5f0A5cF081Fc726'
abi: Metadata
startBlock: 9227595
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
file: ./src/mappings/metadata.ts
entities:
- Metadata
abis:
- name: Metadata
file: ./abis/Metadata.json
eventHandlers:
- event: MetadataCreated(indexed address,indexed address,bytes,bytes)
handler: handleMetadataCreated
- event: MetadataUpdated(indexed address,indexed address,bytes,bytes)
handler: handleMetadataUpdated
templates: templates:
- kind: ethereum/contract - kind: ethereum/contract
name: Pool name: Pool

View File

@ -44,6 +44,28 @@ dataSources:
eventHandlers: eventHandlers:
- event: TokenRegistered(indexed address,string,string,uint256,indexed address,indexed string) - event: TokenRegistered(indexed address,string,string,uint256,indexed address,indexed string)
handler: handleNewToken handler: handleNewToken
- kind: ethereum/contract
name: Metadata
network: mainnet
source:
address: '0x1a4b70d8c9DcA47cD6D0Fb3c52BB8634CA1C0Fdf'
abi: Metadata
startBlock: 11105610
mapping:
kind: ethereum/events
apiVersion: 0.0.4
language: wasm/assemblyscript
file: ./src/mappings/metadata.ts
entities:
- Metadata
abis:
- name: Metadata
file: ./abis/Metadata.json
eventHandlers:
- event: MetadataCreated(indexed address,indexed address,bytes,bytes)
handler: handleMetadataCreated
- event: MetadataUpdated(indexed address,indexed address,bytes,bytes)
handler: handleMetadataUpdated
templates: templates:
- kind: ethereum/contract - kind: ethereum/contract
name: Pool name: Pool