Commit 1012057f authored by vicotor's avatar vicotor

add token owners

parent 6cf4c21f
......@@ -525,9 +525,9 @@ export class Minted extends Entity {
// add a entity to store token id to owner, id use token id, and owner use address.
export class TokenOwner extends Entity {
constructor(id: BigInt) {
constructor(id: string) {
super();
this.set("id", Value.fromBigInt(id));
this.set("id", Value.fromString(id));
}
save(): void {
......@@ -535,28 +535,28 @@ export class TokenOwner extends Entity {
assert(id != null, "Cannot save TokenOwner entity without an ID");
if (id) {
assert(
id.kind == ValueKind.BIGINT,
`Entities of type TokenOwner must have an ID of type BigInt but the id '${id.displayData()}' is of type ${id.displayKind()}`,
id.kind == ValueKind.STRING,
`Entities of type TokenOwner must have an ID of type string but the id '${id.displayData()}' is of type ${id.displayKind()}`,
);
store.set("TokenOwner", id.toString(), this);
}
}
static load(id: BigInt): TokenOwner | null {
return changetype<TokenOwner | null>(store.get("TokenOwner", id.toString()));
static load(id: string): TokenOwner | null {
return changetype<TokenOwner | null>(store.get("TokenOwner", id));
}
get id(): BigInt {
get id(): string {
let value = this.get("id");
if (!value || value.kind == ValueKind.NULL) {
throw new Error("Cannot return null for a required field.");
} else {
return value.toBigInt();
return value.toString();
}
}
set id(value: BigInt) {
this.set("id", Value.fromBigInt(value));
set id(value: string) {
this.set("id", Value.fromString(value));
}
get owner(): Bytes {
......
......@@ -42,7 +42,7 @@ type ApprovalForAll @entity(immutable: true) {
// add TokenOwner entity
type TokenTransfer @entity(immutable: true) {
id: BigInt!
id: string!
owner: Bytes! #address
tokenId: BigInt! # uint256
}
\ No newline at end of file
......@@ -26,7 +26,7 @@ export function handleTransfer(event: TransferEvent): void {
entity.save()
// update TokenOwner
if (true) {
let ownerEntity= new TokenOwner(event.params.tokenId)
let ownerEntity= new TokenOwner(event.params.tokenId.toString())
ownerEntity.owner = event.params.to
ownerEntity.tokenId = event.params.tokenId
ownerEntity.save()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment