feat: collection and collectionOwner entities (#122)
* feat: add Collection and CollectionOwner entities. Handle CollectionOwner on CollectionRoleGranted and CollectionRoleRevoked events. * feat: collection entity and its handler.
This commit is contained in:
parent
2adb39641b
commit
1fe91a137b
|
|
@ -148,3 +148,15 @@ type Controller @entity {
|
||||||
id: Bytes! #address
|
id: Bytes! #address
|
||||||
tokens: [Token!] @derivedFrom(field: "controllers")
|
tokens: [Token!] @derivedFrom(field: "controllers")
|
||||||
}
|
}
|
||||||
|
type Collection @entity {
|
||||||
|
id: Bytes! #address
|
||||||
|
deployer: Bytes! #address
|
||||||
|
transactionHash: Bytes! #transaction hash
|
||||||
|
owners: [CollectionOwner!]
|
||||||
|
}
|
||||||
|
|
||||||
|
type CollectionOwner @entity {
|
||||||
|
id: Bytes! # address
|
||||||
|
accessGrantedBy: Bytes! #address
|
||||||
|
transactionHash: Bytes!
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Address, Bytes, log } from '@graphprotocol/graph-ts';
|
import { Address, Bytes, log, store, ethereum } from '@graphprotocol/graph-ts';
|
||||||
import {
|
import {
|
||||||
Approval as ApprovalEvent,
|
Approval as ApprovalEvent,
|
||||||
ApprovalForAll as ApprovalForAllEvent,
|
ApprovalForAll as ApprovalForAllEvent,
|
||||||
|
|
@ -18,6 +18,8 @@ import {
|
||||||
import {
|
import {
|
||||||
Approval,
|
Approval,
|
||||||
ApprovalForAll,
|
ApprovalForAll,
|
||||||
|
Collection,
|
||||||
|
CollectionOwner,
|
||||||
CollectionRoleGranted,
|
CollectionRoleGranted,
|
||||||
CollectionRoleRevoked,
|
CollectionRoleRevoked,
|
||||||
Controller,
|
Controller,
|
||||||
|
|
@ -79,6 +81,52 @@ export function handleCollectionRoleGranted(
|
||||||
entity.transactionHash = event.transaction.hash;
|
entity.transactionHash = event.transaction.hash;
|
||||||
|
|
||||||
entity.save();
|
entity.save();
|
||||||
|
|
||||||
|
if (event.params.role === 0) {
|
||||||
|
// Role 0 => Owner [Probably going to change this after the ACL refactor.]
|
||||||
|
// Should create a new CollectionOwner entity with the address from the parameters.
|
||||||
|
// If it already is a collection owner, should log a warning.
|
||||||
|
|
||||||
|
let collectionOwner = CollectionOwner.load(event.params.toAddress);
|
||||||
|
|
||||||
|
if (collectionOwner) {
|
||||||
|
// Collection Owner already exists.
|
||||||
|
// Print warning log message.
|
||||||
|
log.warning(
|
||||||
|
'Although Address {} is already a collection owner, a CollectionRoleGranted event was emitted that indicated the address was granted the same role, again.',
|
||||||
|
[event.params.toAddress.toHexString()]
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Create a new collection owner entity and assign the values
|
||||||
|
collectionOwner = new CollectionOwner(event.params.toAddress);
|
||||||
|
collectionOwner.accessGrantedBy = event.params.byAddress;
|
||||||
|
collectionOwner.transactionHash = event.transaction.hash;
|
||||||
|
|
||||||
|
// Log the new CollectionOwner entity creation.
|
||||||
|
log.info('Created a new collection owner entity with address {}.', [
|
||||||
|
event.params.toAddress.toHexString(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Save the collection owner.
|
||||||
|
collectionOwner.save();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.params.byAddress === event.params.toAddress) {
|
||||||
|
// This is the contract creation transaction.
|
||||||
|
log.warning('This is the contract creation transaction.', []);
|
||||||
|
if (event.receipt) {
|
||||||
|
let receipt = event.receipt as ethereum.TransactionReceipt;
|
||||||
|
log.warning('Contract address is: {}', [
|
||||||
|
receipt.contractAddress.toHexString(),
|
||||||
|
]);
|
||||||
|
let collection = new Collection(receipt.contractAddress);
|
||||||
|
collection.deployer = event.params.byAddress;
|
||||||
|
collection.transactionHash = event.transaction.hash;
|
||||||
|
collection.owners = [event.params.toAddress];
|
||||||
|
collection.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleCollectionRoleRevoked(
|
export function handleCollectionRoleRevoked(
|
||||||
|
|
@ -96,6 +144,13 @@ export function handleCollectionRoleRevoked(
|
||||||
entity.transactionHash = event.transaction.hash;
|
entity.transactionHash = event.transaction.hash;
|
||||||
|
|
||||||
entity.save();
|
entity.save();
|
||||||
|
|
||||||
|
if (event.params.role === 0) {
|
||||||
|
// Role 0 => Owner [Probably going to change this after the ACL refactor.]
|
||||||
|
// Should remove the CollectionOwner entity.
|
||||||
|
|
||||||
|
store.remove('CollectionOwner', event.params.toAddress.toHexString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function handleNewBuild(event: NewBuildEvent): void {
|
export function handleNewBuild(event: NewBuildEvent): void {
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ dataSources:
|
||||||
- Token
|
- Token
|
||||||
- Owner
|
- Owner
|
||||||
- Controller
|
- Controller
|
||||||
|
- CollectionOwner
|
||||||
abis:
|
abis:
|
||||||
- name: FleekNFA
|
- name: FleekNFA
|
||||||
file: ../contracts/artifacts/contracts/FleekERC721.sol/FleekERC721.json
|
file: ../contracts/artifacts/contracts/FleekERC721.sol/FleekERC721.json
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue