fix: decrement total tokens by one for each burn, fix the collection id, remove tokens field of git repo in the mapping file. (#249)

This commit is contained in:
Shredder 2023-05-02 19:19:02 +03:30 committed by GitHub
parent d2f81ee98e
commit 85d14483cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 13 deletions

View File

@ -1,4 +1,4 @@
import { log, ethereum, BigInt } from '@graphprotocol/graph-ts';
import { log, ethereum, BigInt, Address } from '@graphprotocol/graph-ts';
// Event Imports [based on the yaml config]
import { Initialized as InitializedEvent } from '../generated/FleekNFA/FleekNFA';
@ -15,7 +15,7 @@ export function handleInitialized(event: InitializedEvent): void {
]);
// start collection entity
const collection = new Collection(event.address.toHexString());
const collection = new Collection(event.address);
collection.totalTokens = BigInt.fromU32(0);
collection.save();

View File

@ -92,16 +92,8 @@ export function handleNewMint(event: NewMintEvent): void {
repository = new GitRepository(gitRepository);
}
let repositoryTokens = repository.tokens;
if (repositoryTokens === null) {
repositoryTokens = [token.id];
} else {
repositoryTokens.push(token.id);
}
repository.tokens = repositoryTokens;
// Increase total tokens counter
const collection = Collection.load(event.address.toHexString());
const collection = Collection.load(event.address);
if (collection) {
collection.totalTokens = collection.totalTokens.plus(BigInt.fromU32(1));
collection.save();

View File

@ -1,10 +1,10 @@
import { Bytes, log, store } from '@graphprotocol/graph-ts';
import { BigInt, Bytes, log, store } from '@graphprotocol/graph-ts';
// Event Imports [based on the yaml config]
import { Transfer as TransferEvent } from '../generated/FleekNFA/FleekNFA';
// Entity Imports [based on the schema]
import { Owner, Token, Transfer } from '../generated/schema';
import { Collection, Owner, Token, Transfer } from '../generated/schema';
export function handleTransfer(event: TransferEvent): void {
const transfer = new Transfer(
@ -39,6 +39,14 @@ export function handleTransfer(event: TransferEvent): void {
// Remove the entity from storage
// Its controllers and owner will be affected.
store.remove('Token', TokenId.toString());
// decrement the collection entity's token count
const collection = Collection.load(event.address);
if (collection) {
collection.totalTokens = collection.totalTokens.minus(
BigInt.fromU32(1)
);
collection.save();
}
} else {
// Transfer
// Load the Token by using its TokenId