Skip to content

Commit

Permalink
more example factoring
Browse files Browse the repository at this point in the history
  • Loading branch information
dOrgJelli committed Jul 8, 2020
1 parent ea91c76 commit 3e4d6a9
Show file tree
Hide file tree
Showing 22 changed files with 3,045 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
build
codegen
yarn-error.log
4 changes: 4 additions & 0 deletions packages/cli/todo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Subgraph
- [ ] Generate Subgraph.yaml w/ proper network & addresses
- [ ] Codegen queries & mutations & subgraph
- [ ] build queries & mutations & subgraph
12 changes: 12 additions & 0 deletions packages/examples/simple-storage/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@web3api/examples-simple-storage",
"scripts": {
"contracts:build": "",
"subgraph:codegen": "cd subgraph && graph codegen --out-dir codegen/",
"subgraph:build": "cd subgraph && graph build"
},
"devDependencies": {
"@graphprotocol/graph-cli": "^0.18.0",
"@graphprotocol/graph-ts": "^0.18.1"
}
}
Empty file.
26 changes: 26 additions & 0 deletions packages/examples/simple-storage/scripts/deploy-contracts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ethers } from "@nomiclabs/buidler";
import { exec } from 'child_process'

async function main() {
const factory = await ethers.getContract("SimpleStorage");

// If we had constructor arguments, they would be passed into deploy()
let contract = await factory.deploy();

// The address the Contract WILL have once mined
console.log("Contract at address: " + contract.address);

// The transaction that was sent to the network to deploy the Contract
console.log("Tx hash: " + contract.deployTransaction.hash);

// The contract is NOT deployed yet; we must wait until it is mined
await contract.deployed();
exec(`npx buidler verify-contract --contract-name SimpleStorage --address ${contract.address}`)
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
3 changes: 3 additions & 0 deletions packages/examples/simple-storage/src/query/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function getData() {

}
22 changes: 22 additions & 0 deletions packages/examples/simple-storage/src/subgraph/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { store } from '@graphprotocol/graph-ts'
import {
DataSet as DataSetEvent,
SimpleStorage
} from './codegen/schema'

function getStorage(id: string): SimpleStorage {
let storage = SimpleStorage.load(id)

if (storage === null) {
storage = new SimpleStorage(id)
storage.save()
}

return storage
}

export function handleDataSet(event: DataSetEvent) {
const storage = getStorage(event.address.toHexString())
storage.lastSetBy = event.params.from.toHexString()
storage.save()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type SimpleStorage @entity {
id: ID!
lastSet: Address
lastSetBy: Address
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ specVersion: 0.0.2
description: SimpleStorage Subgraph Example
repository: https://github.com/web3-api/prototype
schema:
file: ./subgraph/schema.graphql
file: ./schema.graphql
dataSources:
- kind: ethereum/contract
name: SimpleStorage
Expand All @@ -19,7 +19,7 @@ dataSources:
- SimpleStorage
abis:
- name: SimpleStorage
file: ./contracts/abis/SimpleStorage.json
file: ../contracts/abis/SimpleStorage.json
eventHandlers:
- event: DataSet(address from)
handler: handleDataSet
Empty file.
8 changes: 8 additions & 0 deletions packages/examples/simple-storage/tests/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
TODO:
1. Deploy contract
2. Deploy subgraph
3. Deploy Web3API
4. initWeb3API(signer)
5. query("QmMY_API", "{ setData('hey') { id } }")
*/
Loading

0 comments on commit 3e4d6a9

Please sign in to comment.