-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
following along with https://thegraph.com/docs/en/developing/creating-a-subgraph/ ran `graph init` options selected: ✔ Protocol · near ✔ Subgraph name · TENK-DAO/v2.tenk.testnet ✔ Directory to create the subgraph in · subgraph ✔ NEAR network · near-testnet ✔ Contract account · v2.tenk.testnet ✔ Contract Name · Contract ——— Generate subgraph Write subgraph to directory ✔ Create subgraph scaffold ✔ Initialize networks config ✔ Initialize subgraph repository ✔ Install dependencies with yarn ✔ Generate ABI and schema types with yarn codegen ✔ Add another contract? (y/N) · false
- Loading branch information
Showing
7 changed files
with
3,590 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
|
||
import { | ||
TypedMap, | ||
Entity, | ||
Value, | ||
ValueKind, | ||
store, | ||
Bytes, | ||
BigInt, | ||
BigDecimal | ||
} from "@graphprotocol/graph-ts"; | ||
|
||
export class ExampleEntity extends Entity { | ||
constructor(id: string) { | ||
super(); | ||
this.set("id", Value.fromString(id)); | ||
} | ||
|
||
save(): void { | ||
let id = this.get("id"); | ||
assert(id != null, "Cannot save ExampleEntity entity without an ID"); | ||
if (id) { | ||
assert( | ||
id.kind == ValueKind.STRING, | ||
`Entities of type ExampleEntity must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}` | ||
); | ||
store.set("ExampleEntity", id.toString(), this); | ||
} | ||
} | ||
|
||
static load(id: string): ExampleEntity | null { | ||
return changetype<ExampleEntity | null>(store.get("ExampleEntity", id)); | ||
} | ||
|
||
get id(): string { | ||
let value = this.get("id"); | ||
return value!.toString(); | ||
} | ||
|
||
set id(value: string) { | ||
this.set("id", Value.fromString(value)); | ||
} | ||
|
||
get block(): Bytes { | ||
let value = this.get("block"); | ||
return value!.toBytes(); | ||
} | ||
|
||
set block(value: Bytes) { | ||
this.set("block", Value.fromBytes(value)); | ||
} | ||
|
||
get count(): BigInt { | ||
let value = this.get("count"); | ||
return value!.toBigInt(); | ||
} | ||
|
||
set count(value: BigInt) { | ||
this.set("count", Value.fromBigInt(value)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"near-testnet": { | ||
"Contract": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "v2.tenk.testnet", | ||
"license": "UNLICENSED", | ||
"scripts": { | ||
"codegen": "graph codegen", | ||
"build": "graph build", | ||
"deploy": "graph deploy --node https://api.thegraph.com/deploy/ TENK-DAO/v2.tenk.testnet", | ||
"create-local": "graph create --node http://localhost:8020/ TENK-DAO/v2.tenk.testnet", | ||
"remove-local": "graph remove --node http://localhost:8020/ TENK-DAO/v2.tenk.testnet", | ||
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 TENK-DAO/v2.tenk.testnet", | ||
"test": "graph test" | ||
}, | ||
"dependencies": { | ||
"@graphprotocol/graph-cli": "0.33.0", | ||
"@graphprotocol/graph-ts": "0.27.0" | ||
}, | ||
"devDependencies": { "matchstick-as": "0.5.0" } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { near, BigInt } from "@graphprotocol/graph-ts" | ||
import { ExampleEntity } from "../generated/schema" | ||
|
||
export function handleReceipt( | ||
receiptWithOutcome: near.ReceiptWithOutcome | ||
): void { | ||
// Entities can be loaded from the store using a string ID; this ID | ||
// needs to be unique across all entities of the same type | ||
let entity = ExampleEntity.load(receiptWithOutcome.receipt.id.toHex()) | ||
|
||
// Entities only exist after they have been saved to the store; | ||
// `null` checks allow to create entities on demand | ||
if (!entity) { | ||
entity = new ExampleEntity(receiptWithOutcome.receipt.id.toHex()) | ||
|
||
// Entity fields can be set using simple assignments | ||
entity.count = BigInt.fromI32(0) | ||
} | ||
|
||
// BigInt and BigDecimal math are supported | ||
entity.count = entity.count + BigInt.fromI32(1) | ||
|
||
// Entity fields can be set based on receipt information | ||
entity.block = receiptWithOutcome.block.header.hash | ||
|
||
// Entities can be written to the store with `.save()` | ||
entity.save() | ||
|
||
// Note: If a handler doesn't require existing field values, it is faster | ||
// _not_ to load the entity from the store. Instead, create it fresh with | ||
// `new Entity(...)`, set the fields that should be updated and save the | ||
// entity back to the store. Fields that were not set or unset remain | ||
// unchanged, allowing for partial updates to be applied. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
specVersion: 0.0.4 | ||
schema: | ||
file: ./schema.graphql | ||
dataSources: | ||
- kind: near | ||
name: Contract | ||
network: near-testnet | ||
source: | ||
account: "v2.tenk.testnet" | ||
mapping: | ||
apiVersion: 0.0.6 | ||
language: wasm/assemblyscript | ||
entities: | ||
- ExampleEntity | ||
receiptHandlers: | ||
- handler: handleReceipt | ||
file: ./src/contract.ts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", | ||
"include": ["src"] | ||
} |
Oops, something went wrong.