@graphprotocol/graph-cli 0.23.0-alpha.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/tests/cli/init/from-contract/abis/Contract.json +69 -0
- package/tests/cli/init/from-contract/package.json +16 -0
- package/tests/cli/init/from-contract/schema.graphql +6 -0
- package/tests/cli/init/from-contract/src/mapping.ts +49 -0
- package/tests/cli/init/from-contract/subgraph.yaml +26 -0
package/package.json
CHANGED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"constant": true,
|
|
4
|
+
"inputs": [],
|
|
5
|
+
"name": "proxyOwner",
|
|
6
|
+
"outputs": [{ "name": "", "type": "address" }],
|
|
7
|
+
"payable": false,
|
|
8
|
+
"stateMutability": "view",
|
|
9
|
+
"type": "function"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"constant": true,
|
|
13
|
+
"inputs": [],
|
|
14
|
+
"name": "currentContract",
|
|
15
|
+
"outputs": [{ "name": "", "type": "address" }],
|
|
16
|
+
"payable": false,
|
|
17
|
+
"stateMutability": "view",
|
|
18
|
+
"type": "function"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"constant": true,
|
|
22
|
+
"inputs": [],
|
|
23
|
+
"name": "owner",
|
|
24
|
+
"outputs": [{ "name": "", "type": "address" }],
|
|
25
|
+
"payable": false,
|
|
26
|
+
"stateMutability": "view",
|
|
27
|
+
"type": "function"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"constant": false,
|
|
31
|
+
"inputs": [
|
|
32
|
+
{ "name": "newContract", "type": "address" },
|
|
33
|
+
{ "name": "data", "type": "bytes" }
|
|
34
|
+
],
|
|
35
|
+
"name": "upgrade",
|
|
36
|
+
"outputs": [],
|
|
37
|
+
"payable": false,
|
|
38
|
+
"stateMutability": "nonpayable",
|
|
39
|
+
"type": "function"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"constant": false,
|
|
43
|
+
"inputs": [{ "name": "_newOwner", "type": "address" }],
|
|
44
|
+
"name": "transferOwnership",
|
|
45
|
+
"outputs": [],
|
|
46
|
+
"payable": false,
|
|
47
|
+
"stateMutability": "nonpayable",
|
|
48
|
+
"type": "function"
|
|
49
|
+
},
|
|
50
|
+
{ "payable": true, "stateMutability": "payable", "type": "fallback" },
|
|
51
|
+
{
|
|
52
|
+
"anonymous": false,
|
|
53
|
+
"inputs": [
|
|
54
|
+
{ "indexed": true, "name": "newContract", "type": "address" },
|
|
55
|
+
{ "indexed": false, "name": "initializedWith", "type": "bytes" }
|
|
56
|
+
],
|
|
57
|
+
"name": "Upgrade",
|
|
58
|
+
"type": "event"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
"anonymous": false,
|
|
62
|
+
"inputs": [
|
|
63
|
+
{ "indexed": false, "name": "_prevOwner", "type": "address" },
|
|
64
|
+
{ "indexed": false, "name": "_newOwner", "type": "address" }
|
|
65
|
+
],
|
|
66
|
+
"name": "OwnerUpdate",
|
|
67
|
+
"type": "event"
|
|
68
|
+
}
|
|
69
|
+
]
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "subgraph-from-contract",
|
|
3
|
+
"license": "UNLICENSED",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"codegen": "graph codegen",
|
|
6
|
+
"build": "graph build",
|
|
7
|
+
"deploy": "graph deploy --node https://api.studio.thegraph.com/deploy/ user/subgraph-from-contract",
|
|
8
|
+
"create-local": "graph create --node http://localhost:8020/ user/subgraph-from-contract",
|
|
9
|
+
"remove-local": "graph remove --node http://localhost:8020/ user/subgraph-from-contract",
|
|
10
|
+
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 user/subgraph-from-contract"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@graphprotocol/graph-cli": "file:../../../../",
|
|
14
|
+
"@graphprotocol/graph-ts": "0.22.1"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { BigInt } from "@graphprotocol/graph-ts"
|
|
2
|
+
import { Contract, Upgrade, OwnerUpdate } from "../generated/Contract/Contract"
|
|
3
|
+
import { ExampleEntity } from "../generated/schema"
|
|
4
|
+
|
|
5
|
+
export function handleUpgrade(event: Upgrade): void {
|
|
6
|
+
// Entities can be loaded from the store using a string ID; this ID
|
|
7
|
+
// needs to be unique across all entities of the same type
|
|
8
|
+
let entity = ExampleEntity.load(event.transaction.from.toHex())
|
|
9
|
+
|
|
10
|
+
// Entities only exist after they have been saved to the store;
|
|
11
|
+
// `null` checks allow to create entities on demand
|
|
12
|
+
if (!entity) {
|
|
13
|
+
entity = new ExampleEntity(event.transaction.from.toHex())
|
|
14
|
+
|
|
15
|
+
// Entity fields can be set using simple assignments
|
|
16
|
+
entity.count = BigInt.fromI32(0)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// BigInt and BigDecimal math are supported
|
|
20
|
+
entity.count = entity.count + BigInt.fromI32(1)
|
|
21
|
+
|
|
22
|
+
// Entity fields can be set based on event parameters
|
|
23
|
+
entity.newContract = event.params.newContract
|
|
24
|
+
entity.initializedWith = event.params.initializedWith
|
|
25
|
+
|
|
26
|
+
// Entities can be written to the store with `.save()`
|
|
27
|
+
entity.save()
|
|
28
|
+
|
|
29
|
+
// Note: If a handler doesn't require existing field values, it is faster
|
|
30
|
+
// _not_ to load the entity from the store. Instead, create it fresh with
|
|
31
|
+
// `new Entity(...)`, set the fields that should be updated and save the
|
|
32
|
+
// entity back to the store. Fields that were not set or unset remain
|
|
33
|
+
// unchanged, allowing for partial updates to be applied.
|
|
34
|
+
|
|
35
|
+
// It is also possible to access smart contracts from mappings. For
|
|
36
|
+
// example, the contract that has emitted the event can be connected to
|
|
37
|
+
// with:
|
|
38
|
+
//
|
|
39
|
+
// let contract = Contract.bind(event.address)
|
|
40
|
+
//
|
|
41
|
+
// The following functions can then be called on this contract to access
|
|
42
|
+
// state variables and other data:
|
|
43
|
+
//
|
|
44
|
+
// - contract.proxyOwner(...)
|
|
45
|
+
// - contract.currentContract(...)
|
|
46
|
+
// - contract.owner(...)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function handleOwnerUpdate(event: OwnerUpdate): void {}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
specVersion: 0.0.1
|
|
2
|
+
schema:
|
|
3
|
+
file: ./schema.graphql
|
|
4
|
+
dataSources:
|
|
5
|
+
- kind: ethereum/contract
|
|
6
|
+
name: Contract
|
|
7
|
+
network: mainnet
|
|
8
|
+
source:
|
|
9
|
+
address: "0xF87E31492Faf9A91B02Ee0dEAAd50d51d56D5d4d"
|
|
10
|
+
abi: Contract
|
|
11
|
+
mapping:
|
|
12
|
+
kind: ethereum/events
|
|
13
|
+
apiVersion: 0.0.5
|
|
14
|
+
language: wasm/assemblyscript
|
|
15
|
+
entities:
|
|
16
|
+
- Upgrade
|
|
17
|
+
- OwnerUpdate
|
|
18
|
+
abis:
|
|
19
|
+
- name: Contract
|
|
20
|
+
file: ./abis/Contract.json
|
|
21
|
+
eventHandlers:
|
|
22
|
+
- event: Upgrade(indexed address,bytes)
|
|
23
|
+
handler: handleUpgrade
|
|
24
|
+
- event: OwnerUpdate(address,address)
|
|
25
|
+
handler: handleOwnerUpdate
|
|
26
|
+
file: ./src/mapping.ts
|