Skip to content

Commit

Permalink
made changes to new entities
Browse files Browse the repository at this point in the history
  • Loading branch information
NorVirae committed Nov 16, 2022
1 parent 4c2e362 commit 5a285c3
Show file tree
Hide file tree
Showing 8 changed files with 298 additions and 60 deletions.
44 changes: 43 additions & 1 deletion abis/PodShipSupporterNFT.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,26 @@
"type": "bool"
}
],
"name": "PodShipSupporterNFTApprovalForAll",
"name": "ApprovalForAll",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
Expand Down Expand Up @@ -174,6 +193,20 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "from", "type": "address" },
Expand Down Expand Up @@ -226,6 +259,15 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "address", "name": "newOwner", "type": "address" }
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "uint256", "name": "_id", "type": "uint256" }],
"name": "uri",
Expand Down
2 changes: 1 addition & 1 deletion networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"address": "0xFdc217E2867717ca21A5Edc13Fb8feA73192292D"
},
"PodShipSupporterNFT": {
"address": "0x0E2a4F18CEBE45f863ff8Dc7381B812295a02397"
"address": "0x643089d3eb7Cc0291a3A16F57c9CB8154A98477A"
}
}
}
58 changes: 57 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,29 @@ type Podcast @entity {
creator: User
}

type SupporterNFT @entity{
id: ID!
metadataURI: String
created: BigInt
ownerAddress: User
creator: User
}

type User @entity{
id: ID!
podcasts: [Podcast!] @derivedFrom(field: "ownerAddress")
isRecentWinner: Boolean
SupporterNFTs: [SupporterNFT!] @derivedFrom(field: "ownerAddress")
created: [Podcast!] @derivedFrom(field: "creator")
bids: [Bid!] @derivedFrom(field: "bidder")
tips: [Tip!] @derivedFrom(field: "supporter")
}

type Tip @entity{
id: ID!
tip: BigInt
supporter: User
podcast: Podcast
}


Expand All @@ -35,4 +53,42 @@ type Bid @entity{
bidder: User
adrr: String
bid: BigInt
}
}


# type ApprovalForAll @entity {
# id: ID!
# account: Bytes! # address
# operator: Bytes! # address
# approved: Boolean! # bool
# }

# type OwnershipTransferred @entity {
# id: ID!
# previousOwner: Bytes! # address
# newOwner: Bytes! # address
# }

# type TransferBatch @entity {
# id: ID!
# operator: Bytes! # address
# from: Bytes! # address
# to: Bytes! # address
# ids: [BigInt]! # uint256[]
# values: [BigInt]! # uint256[]
# }

# type TransferSingle @entity {
# id: ID!
# operator: Bytes! # address
# from: Bytes! # address
# to: Bytes! # address
# id: BigInt! # uint256
# value: BigInt! # uint256
# }

# type URI @entity {
# id: ID!
# value: String! # string
# id: BigInt! # uint256
# }
47 changes: 43 additions & 4 deletions src/pod-ship-auction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
Tipping,
Transfer
} from "../generated/PodShipAuction/PodShipAuction"
import { Bid, Podcast, PodSale, User } from "../generated/schema"
import { Bid, Podcast, PodSale, Tip, User } from "../generated/schema"

export function handleApproval(event: Approval): void {
// // Entities can be loaded from the store using a string ID; this ID
Expand Down Expand Up @@ -172,11 +172,50 @@ export function handlePodShipContractDeployed(

export function handleProdcastCreated(event: ProdcastCreated): void {}

export function handleRecentWinner(event: RecentWinner): void {}
export function handleRecentWinner(event: RecentWinner): void {
let user = User.load(event.transaction.from.toHexString())
if (!user) {
user = new User(event.transaction.from.toHexString())
user.isRecentWinner = true
user.save()
}

if(user){
user.isRecentWinner = true
user.save()
}
}

export function handleRequestedWinner(event: RequestedWinner): void {
// let user = User.load(event.transaction.from.toHexString())
// if (!user) {
// user = new User(event.transaction.from.toHexString())
// user.isRecentWinner = true
// user.save()
// }

// if(user){
// user.isRecentWinner = true
// user.save()
// }
}

export function handleTipping(event: Tipping): void {

let tip = new Tip(event.address.toHex() + '-' + event.params.podcastId.toString())
tip.tip = event.params.tip
tip.supporter = event.transaction.from.toHexString()
tip.podcast = event.params.podcastId.toHex()
tip.save()

let user = User.load(event.transaction.from.toHexString())

export function handleRequestedWinner(event: RequestedWinner): void {}
if (!user) {
user = new User(event.transaction.from.toHexString())
user.save()
}

export function handleTipping(event: Tipping): void {}
}

export function handleTransfer(event: Transfer): void {

Expand Down
82 changes: 82 additions & 0 deletions src/pod-ship-supporter-nft.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import {
ApprovalForAll as ApprovalForAllEvent,
OwnershipTransferred as OwnershipTransferredEvent,
PodShipSupporterNFT,
TransferBatch as TransferBatchEvent,
TransferSingle as TransferSingleEvent,
URI as URIEvent
} from "../generated/PodShipSupporterNFT/PodShipSupporterNFT"
import { User, SupporterNFT } from "../generated/schema"
// import {
// ApprovalForAll,
// OwnershipTransferred,
// TransferBatch,
// TransferSingle,
// URI
// } from "../generated/schema"

export function handleApprovalForAll(event: ApprovalForAllEvent): void {

}

export function handleOwnershipTransferred(
event: OwnershipTransferredEvent
): void {

}

export function handleTransferBatch(event: TransferBatchEvent): void {
// let supporterNft = SupporterNFT.load(event.params.ids.toHex())
// if (!supporterNft) {
// supporterNft = new SupporterNFT(event.params.id.toHex())

// let podshipNftContract = PodShipSupporterNFT.bind(event.address)
// supporterNft.metadataURI = podshipNftContract.uri(event.params.id)
// supporterNft.creator = event.params.from.toHexString()
// supporterNft.ownerAddress = event.params.to.toHexString()
// supporterNft.created = event.block.timestamp
// supporterNft.save()
// }

// if(supporterNft){
// supporterNft.ownerAddress = event.params.to.toHexString()
// }

// let user = User.load(event.transaction.from.toHexString())
// if (!user) {
// user = new User(event.transaction.from.toHexString())
// user.save()
// }
}

export function handleTransferSingle(event: TransferSingleEvent): void {
let supporterNft = SupporterNFT.load(event.params.id.toHex())
if (!supporterNft) {
supporterNft = new SupporterNFT(event.params.id.toHex())

let podshipNftContract = PodShipSupporterNFT.bind(event.address)
supporterNft.metadataURI = podshipNftContract.uri(event.params.id)
supporterNft.creator = event.params.from.toHexString()
supporterNft.ownerAddress = event.params.to.toHexString()
supporterNft.created = event.block.timestamp
supporterNft.save()
}

if(supporterNft){
supporterNft.ownerAddress = event.params.to.toHexString()
}

let user = User.load(event.transaction.from.toHexString())
if (!user) {
user = new User(event.transaction.from.toHexString())
user.save()
}
}

export function handleURI(event: URIEvent): void {
let supporterNft = SupporterNFT.load(event.params.id.toHex())
if (supporterNft) {
supporterNft.metadataURI = event.params.value
supporterNft.save()
}
}
57 changes: 28 additions & 29 deletions subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ dataSources:
- PodSale
- Podcast
- User

abis:
- name: PodShipAuction
file: ./abis/PodShipAuction.json
Expand Down Expand Up @@ -55,31 +54,31 @@ dataSources:
- event: Transfer(indexed address,indexed address,indexed uint256)
handler: handleTransfer
file: ./src/pod-ship-auction.ts
# - kind: ethereum
# name: PodShipSupporterNFT
# network: mumbai
# source:
# address: "0x0E2a4F18CEBE45f863ff8Dc7381B812295a02397"
# abi: PodShipSupporterNFT
# mapping:
# kind: ethereum/events
# apiVersion: 0.0.6
# language: wasm/assemblyscript
# entities:
# - PodShipSupporterNFTApprovalForAll
# - TransferBatch
# - TransferSingle
# - URI
# abis:
# - name: PodShipSupporterNFT
# file: ./abis/PodShipSupporterNFT.json
# eventHandlers:
# - event: PodShipSupporterNFTApprovalForAll(indexed address,indexed address,bool)
# handler: handlePodShipSupporterNFTApprovalForAll
# - event: TransferBatch(indexed address,indexed address,indexed address,uint256[],uint256[])
# handler: handleTransferBatch
# - event: TransferSingle(indexed address,indexed address,indexed address,uint256,uint256)
# handler: handleTransferSingle
# - event: URI(string,indexed uint256)
# handler: handleURI
# file: ./src/pod-ship-supporter-nft.ts
- kind: ethereum
name: PodShipSupporterNFT
network: mumbai
source:
address: "0x643089d3eb7Cc0291a3A16F57c9CB8154A98477A"
abi: PodShipSupporterNFT
startBlock: 29165229
mapping:
kind: ethereum/events
apiVersion: 0.0.6
language: wasm/assemblyscript
entities:
- SupporterNFT
abis:
- name: PodShipSupporterNFT
file: ./abis/PodShipSupporterNFT.json
eventHandlers:
- event: ApprovalForAll(indexed address,indexed address,bool)
handler: handleApprovalForAll
- event: OwnershipTransferred(indexed address,indexed address)
handler: handleOwnershipTransferred
- event: TransferBatch(indexed address,indexed address,indexed address,uint256[],uint256[])
handler: handleTransferBatch
- event: TransferSingle(indexed address,indexed address,indexed address,uint256,uint256)
handler: handleTransferSingle
- event: URI(string,indexed uint256)
handler: handleURI
file: ./src/pod-ship-supporter-nft.ts
Loading

0 comments on commit 5a285c3

Please sign in to comment.