mirror of
https://github.com/oceanprotocol/ocean-subgraph.git
synced 2024-12-02 05:57:29 +01:00
add erc725 key/value store (#533)
This commit is contained in:
parent
a74e3edb3a
commit
73089dacc3
@ -113,8 +113,18 @@ type Nft @entity{
|
|||||||
|
|
||||||
"has metadata"
|
"has metadata"
|
||||||
hasMetadata: Boolean!
|
hasMetadata: Boolean!
|
||||||
|
|
||||||
|
nftData: [NftData!] @derivedFrom(field: "nft")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NftData @entity{
|
||||||
|
"nft address+key"
|
||||||
|
id: ID!
|
||||||
|
nft: Nft!
|
||||||
|
key: Bytes
|
||||||
|
value: Bytes
|
||||||
|
}
|
||||||
|
|
||||||
type OrderReuse @entity {
|
type OrderReuse @entity {
|
||||||
id: ID!
|
id: ID!
|
||||||
order: Order!
|
order: Order!
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Nft, NftUpdate } from '../@types/schema'
|
import { Nft, NftUpdate, NftData } from '../@types/schema'
|
||||||
import {
|
import {
|
||||||
MetadataCreated,
|
MetadataCreated,
|
||||||
MetadataState,
|
MetadataState,
|
||||||
@ -13,7 +13,8 @@ import {
|
|||||||
RemovedFromMetadataList,
|
RemovedFromMetadataList,
|
||||||
RemovedManager,
|
RemovedManager,
|
||||||
CleanedPermissions,
|
CleanedPermissions,
|
||||||
Transfer
|
Transfer,
|
||||||
|
DataChanged
|
||||||
} from '../@types/templates/ERC721Template/ERC721Template'
|
} from '../@types/templates/ERC721Template/ERC721Template'
|
||||||
import { NftUpdateType } from './utils/constants'
|
import { NftUpdateType } from './utils/constants'
|
||||||
import { getNftToken, getNftTokenWithID } from './utils/tokenUtils'
|
import { getNftToken, getNftTokenWithID } from './utils/tokenUtils'
|
||||||
@ -257,6 +258,18 @@ export function handleNftTransferred(event: Transfer): void {
|
|||||||
const nft = getNftTokenWithID(id)
|
const nft = getNftTokenWithID(id)
|
||||||
const newOwner = getUser(event.params.to.toHexString())
|
const newOwner = getUser(event.params.to.toHexString())
|
||||||
nft.owner = newOwner.id
|
nft.owner = newOwner.id
|
||||||
|
|
||||||
nft.save()
|
nft.save()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function handleNftData(event: DataChanged): void {
|
||||||
|
const id = event.address.toHexString() + '-' + event.params.key.toHexString()
|
||||||
|
const nft = getNftToken(event.address)
|
||||||
|
let data = NftData.load(id)
|
||||||
|
if (data == null) {
|
||||||
|
data = new NftData(id)
|
||||||
|
}
|
||||||
|
data.key = event.params.key
|
||||||
|
data.value = event.params.value
|
||||||
|
data.nft = nft.id
|
||||||
|
data.save()
|
||||||
|
}
|
||||||
|
@ -97,6 +97,8 @@ templates:
|
|||||||
handler: handleCleanedPermissions
|
handler: handleCleanedPermissions
|
||||||
- event: Transfer(indexed address,indexed address,indexed uint256)
|
- event: Transfer(indexed address,indexed address,indexed uint256)
|
||||||
handler: handleNftTransferred
|
handler: handleNftTransferred
|
||||||
|
- event: DataChanged(indexed bytes32,bytes)
|
||||||
|
handler: handleNftData
|
||||||
|
|
||||||
- name: Dispenser
|
- name: Dispenser
|
||||||
kind: ethereum/contract
|
kind: ethereum/contract
|
||||||
|
@ -285,4 +285,26 @@ describe('NFT tests', async () => {
|
|||||||
assert(updatedNft.block < blockNumber + 50, 'incorrect value for: block')
|
assert(updatedNft.block < blockNumber + 50, 'incorrect value for: block')
|
||||||
assert(updatedNft.orderCount === '0', 'incorrect value for: orderCount')
|
assert(updatedNft.orderCount === '0', 'incorrect value for: orderCount')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Set a key/value in erc725 store', async () => {
|
||||||
|
await nft.setData(nftAddress, publisher, 'test_key', 'test_value')
|
||||||
|
await sleep(2000)
|
||||||
|
const query = {
|
||||||
|
query: `query {
|
||||||
|
nft(id:"${nftAddress}"){
|
||||||
|
nftData{
|
||||||
|
id
|
||||||
|
key
|
||||||
|
value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
}
|
||||||
|
const response = await fetch(subgraphUrl, {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify(query)
|
||||||
|
})
|
||||||
|
const updatedNft = (await response.json()).data.nft
|
||||||
|
assert(updatedNft.nftData.key !== null, 'incorrect value for key')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user