Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
klkgraph
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
klkgraph
Commits
6cf4c21f
Commit
6cf4c21f
authored
Mar 17, 2025
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add token owners
parent
91386f8b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
1 deletion
+78
-1
schema.ts
generated/schema.ts
+63
-0
schema.graphql
schema.graphql
+7
-0
drago.ts
src/drago.ts
+8
-1
No files found.
generated/schema.ts
View file @
6cf4c21f
...
...
@@ -522,3 +522,66 @@ export class Minted extends Entity {
this
.
set
(
"
transactionHash
"
,
Value
.
fromBytes
(
value
));
}
}
// 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
)
{
super
();
this
.
set
(
"
id
"
,
Value
.
fromBigInt
(
id
));
}
save
():
void
{
let
id
=
this
.
get
(
"
id
"
);
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
()}
`
,
);
store
.
set
(
"
TokenOwner
"
,
id
.
toString
(),
this
);
}
}
static
load
(
id
:
BigInt
):
TokenOwner
|
null
{
return
changetype
<
TokenOwner
|
null
>
(
store
.
get
(
"
TokenOwner
"
,
id
.
toString
()));
}
get
id
():
BigInt
{
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
();
}
}
set
id
(
value
:
BigInt
)
{
this
.
set
(
"
id
"
,
Value
.
fromBigInt
(
value
));
}
get
owner
():
Bytes
{
let
value
=
this
.
get
(
"
owner
"
);
if
(
!
value
||
value
.
kind
==
ValueKind
.
NULL
)
{
throw
new
Error
(
"
Cannot return null for a required field.
"
);
}
else
{
return
value
.
toBytes
();
}
}
set
owner
(
value
:
Bytes
)
{
this
.
set
(
"
owner
"
,
Value
.
fromBytes
(
value
));
}
get
tokenId
():
BigInt
{
let
value
=
this
.
get
(
"
tokenId
"
);
if
(
!
value
||
value
.
kind
==
ValueKind
.
NULL
)
{
throw
new
Error
(
"
Cannot return null for a required field.
"
);
}
else
{
return
value
.
toBigInt
();
}
}
set
tokenId
(
value
:
BigInt
)
{
this
.
set
(
"
tokenId
"
,
Value
.
fromBigInt
(
value
));
}
}
\ No newline at end of file
schema.graphql
View file @
6cf4c21f
...
...
@@ -39,3 +39,10 @@ type ApprovalForAll @entity(immutable: true) {
blockTimestamp
:
BigInt
!
transactionHash
:
Bytes
!
}
//
add
TokenOwner
entity
type
TokenTransfer
@
entity
(
immutable
:
true
)
{
id
:
BigInt
!
owner
:
Bytes
!
#address
tokenId
:
BigInt
!
# uint256
}
\ No newline at end of file
src/drago.ts
View file @
6cf4c21f
...
...
@@ -3,7 +3,7 @@ import {
Approval
as
ApprovalEvent
,
ApprovalForAll
as
ApprovalForAllEvent
}
from
"
../generated/Drago/Drago
"
import
{
Transfer
,
Approval
,
ApprovalForAll
,
Minted
}
from
"
../generated/schema
"
import
{
Transfer
,
Approval
,
ApprovalForAll
,
Minted
,
TokenOwner
}
from
"
../generated/schema
"
import
{
store
,
Bytes
,
...
...
@@ -24,6 +24,13 @@ export function handleTransfer(event: TransferEvent): void {
entity
.
transactionHash
=
event
.
transaction
.
hash
entity
.
save
()
// update TokenOwner
if
(
true
)
{
let
ownerEntity
=
new
TokenOwner
(
event
.
params
.
tokenId
)
ownerEntity
.
owner
=
event
.
params
.
to
ownerEntity
.
tokenId
=
event
.
params
.
tokenId
ownerEntity
.
save
()
}
if
(
event
.
params
.
from
.
toHexString
()
==
"
0x0000000000000000000000000000000000000000
"
)
{
// Mint
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment