Skip to content

Commit cf6ad7c

Browse files
authored
fix: indexing contract (#30)
1 parent 527c038 commit cf6ad7c

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

subgraph/datasources/counter.gql.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,23 @@
44
"fields": [
55
{ "name": "id", "type": "Bytes!" },
66
{ "name": "asCounter", "type": "CounterContract" },
7-
{ "name": "CounterIncrementedEvent", "type": "CounterIncremented!" }
7+
{
8+
"name": "CounterIncrementedEvents",
9+
"type": "CounterIncremented!",
10+
"derived": "emitter"
11+
}
812
]
913
},
1014
{
1115
"name": "CounterContract",
1216
"fields": [
1317
{ "name": "asAccount", "type": "Account!" },
14-
{ "name": "currentValue", "type": "BigInt!" }
18+
{ "name": "currentValue", "type": "BigInt!" },
19+
{
20+
"name": "CounterIncrementedEvent",
21+
"type": "CounterIncremented!",
22+
"derived": "contract"
23+
}
1524
]
1625
},
1726
{
@@ -26,4 +35,4 @@
2635
{ "name": "currentValue", "type": "BigInt!" }
2736
]
2837
}
29-
]
38+
]

subgraph/fetch/counter.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Address } from "@graphprotocol/graph-ts";
2-
import { CounterContract } from "../../generated/schema";
3-
import { fetchAccount } from "./account";
1+
import { Address, BigInt } from '@graphprotocol/graph-ts';
2+
import { CounterContract } from '../../generated/schema';
3+
import { fetchAccount } from './account';
44

55
export function fetchCounter(address: Address): CounterContract {
66
const account = fetchAccount(address);
@@ -10,10 +10,11 @@ export function fetchCounter(address: Address): CounterContract {
1010
contract = new CounterContract(account.id.toHex());
1111
contract.asAccount = account.id;
1212
account.asCounter = contract.id;
13+
contract.currentValue = BigInt.fromString('0');
1314

1415
contract.save();
1516
account.save();
1617
}
1718

1819
return contract as CounterContract;
19-
}
20+
}

0 commit comments

Comments
 (0)