Commit 1012057f authored by vicotor's avatar vicotor

add token owners

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