Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add which standard the token is #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generated/persisted_state.envio.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"has_run_db_migrations":true,"config_hash":"b2670a66fe3ea530f9e04003e27dce31c59b4c31926bb50a1a191edcac6bbe8c","schema_hash":"43ff9276960cca0460cf430db51c8da2bb6cfc4be3b06716e73af6f6dcf7ebc3","handler_files_hash":"2bf798587ecddbb0bcdeb806defe1d730c5c92515784332a1cd84b4761c58f38","abi_files_hash":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}
{"has_run_db_migrations":true,"config_hash":"74b7df50a76dc93cade163b0a25b19736c61e0c7bd6202531a5f6535cae9dfed","schema_hash":"46ae8352a6ad9458d29e50ca072865a6d52601b9859d7d41d2af5d2223410ef2","handler_files_hash":"46253e4b5d63fef38796cd057ab70b06b5eb248d9991252bfe11ab54d7a19fbe","abi_files_hash":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Token @entity {
owner: User!
value: BigInt! # This is mostly relevant to ERC1155 tokens where each token has a value or 'number'
metadata: Metadata @derivedFrom(field: "token_id")
standard: String!
}

type Metadata @entity {
Expand Down
58 changes: 40 additions & 18 deletions src/EventHandlers.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 21 additions & 9 deletions src/EventHandlers.res
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Handlers.ERC721Contract.Transfer.handler((~event, ~context) => {
collection: event.srcAddress->Ethers.ethAddressToString,
owner: event.params.to->Ethers.ethAddressToString,
value: 1->Ethers.BigInt.fromInt,
standard: "ERC721",
}

switch context.nftcollection.nftCollectionUpdated() {
Expand All @@ -42,6 +43,9 @@ Handlers.ERC721Contract.Transfer.handler((~event, ~context) => {
contractAddress: event.srcAddress->Ethers.ethAddressToString,
//First NFT is being created so current suplly is 1
currentSupply: 1,
name: None,
symbol: None,
maxSupply: None,
}

context.nftcollection.set(newNftCollection)
Expand Down Expand Up @@ -81,6 +85,7 @@ Handlers.ERC1155Contract.TransferSingle.handler((~event, ~context) => {
collection: event.srcAddress->Ethers.ethAddressToString,
owner: event.params.to->Ethers.ethAddressToString,
value: event.params.value,
standard: "ERC1155",
}

switch context.nftcollection.nftCollectionUpdated() {
Expand All @@ -106,6 +111,9 @@ Handlers.ERC1155Contract.TransferSingle.handler((~event, ~context) => {
contractAddress: event.srcAddress->Ethers.ethAddressToString,
//First NFT is being created so current suplly is 1
currentSupply: 1,
name: None,
symbol: None,
maxSupply: None,
}

context.nftcollection.set(newNftCollection)
Expand Down Expand Up @@ -133,24 +141,25 @@ Handlers.ERC1155Contract.TransferSingle.handler((~event, ~context) => {

Handlers.ERC1155Contract.TransferBatch.loader((~event, ~context) => {
context.nftcollection.nftCollectionUpdatedLoad(event.srcAddress->Ethers.ethAddressToString)
event.params.ids->Belt.Array.forEach(id => {
context.token.existingTransferredTokenLoad(
event.srcAddress->Ethers.ethAddressToString ++ id->Ethers.BigInt.toString,
~loaders={},
)
})
event.params.ids->Belt.Array.forEach(id => {
context.token.existingTransferredTokenLoad(
event.srcAddress->Ethers.ethAddressToString ++ id->Ethers.BigInt.toString,
~loaders={},
)
})
})

Handlers.ERC1155Contract.TransferBatch.handler((~event, ~context) => {
Js.log("in handler event.params.ids")
Js.log(event.params.ids)
let _ = event.params.ids->Belt.Array.mapWithIndex((index, id) => {
let token = {
id: `${event.srcAddress->Ethers.ethAddressToString}-${id->Ethers.BigInt.toString}`,
tokenId: id,
collection: event.srcAddress->Ethers.ethAddressToString,
owner: event.params.to->Ethers.ethAddressToString,
value: event.params.values->Belt.Array.get(index)->Belt.Option.getWithDefault(1->Ethers.BigInt.fromInt),
value: event.params.values
->Belt.Array.get(index)
->Belt.Option.getWithDefault(1->Ethers.BigInt.fromInt),
standard: "ERC1155",
}

switch context.nftcollection.nftCollectionUpdated() {
Expand All @@ -176,6 +185,9 @@ Handlers.ERC1155Contract.TransferBatch.handler((~event, ~context) => {
contractAddress: event.srcAddress->Ethers.ethAddressToString,
//First NFT is being created so current suplly is 1
currentSupply: 1,
name: None,
symbol: None,
maxSupply: None,
}

context.nftcollection.set(newNftCollection)
Expand Down