forked from graphprotocol/graph-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from neonlabsorg/NDEV-3235-add-auth-to-graph
Ndev 3235 add auth to graph
- Loading branch information
Showing
10 changed files
with
502 additions
and
1 deletion.
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
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,33 @@ | ||
[ | ||
{ | ||
"inputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"anonymous": false, | ||
"inputs": [ | ||
{ | ||
"indexed": false, | ||
"internalType": "uint16", | ||
"name": "x", | ||
"type": "uint16" | ||
} | ||
], | ||
"name": "Trigger", | ||
"type": "event" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "uint16", | ||
"name": "x", | ||
"type": "uint16" | ||
} | ||
], | ||
"name": "emitTrigger", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
] |
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,27 @@ | ||
{ | ||
"name": "neon-auth", | ||
"version": "0.1.0", | ||
"scripts": { | ||
"build-contracts": "../../common/build-contracts.sh", | ||
"codegen": "graph codegen --skip-migrations", | ||
"test": "yarn build-contracts && truffle test --compile-none --network test", | ||
"neon": "yarn build-contracts && yarn truffle test --compile-none --network neonlabs", | ||
"auth:test": "graph auth $SECURED_GRAPH_NODE_ADMIN_URI $API_KEY", | ||
"create:test": "graph create $SUBGRAPH_NAME --node $SECURED_GRAPH_NODE_ADMIN_URI", | ||
"deploy:test": "graph deploy $SUBGRAPH_NAME --version-label v0.0.1 --ipfs $SECURED_IPFS_URI --node $SECURED_GRAPH_NODE_ADMIN_URI --headers='{\"Authorization\": \"Bearer '$API_KEY'\"}'" | ||
}, | ||
"devDependencies": { | ||
"@graphprotocol/graph-cli": "0.52.0-alpha-20230628121316-48231a7", | ||
"@graphprotocol/graph-ts": "0.31.0", | ||
"solc": "^0.8.2" | ||
}, | ||
"dependencies": { | ||
"@truffle/contract": "^4.3", | ||
"@truffle/hdwallet-provider": "^1.2", | ||
"apollo-fetch": "^0.7.0", | ||
"babel-polyfill": "^6.26.0", | ||
"babel-register": "^6.26.0", | ||
"gluegun": "^4.6.1", | ||
"truffle": "^5.2" | ||
} | ||
} |
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,27 @@ | ||
type Foo @entity { | ||
id: ID! | ||
value: Int! | ||
} | ||
|
||
type Initialize @entity { | ||
id: ID! | ||
block: BigInt! | ||
} | ||
|
||
type Block @entity { | ||
id: ID! | ||
number: BigInt! | ||
hash: Bytes! | ||
} | ||
|
||
type BlockFromPollingHandler @entity { | ||
id: ID! | ||
number: BigInt! | ||
hash: Bytes! | ||
} | ||
|
||
type BlockFromOtherPollingHandler @entity { | ||
id: ID! | ||
number: BigInt! | ||
hash: Bytes! | ||
} |
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,80 @@ | ||
import { Address, BigInt, ethereum, log } from '@graphprotocol/graph-ts'; | ||
import { Contract, Trigger } from '../generated/Contract/Contract'; | ||
import { | ||
BlockFromOtherPollingHandler, | ||
BlockFromPollingHandler, | ||
Block, | ||
Foo, | ||
Initialize, | ||
} from '../generated/schema'; | ||
import { ContractTemplate } from '../generated/templates'; | ||
|
||
export function handleBlock(block: ethereum.Block): void { | ||
log.info('handleBlock {}', [block.number.toString()]); | ||
let blockEntity = new Block(block.number.toString()); | ||
blockEntity.number = block.number; | ||
blockEntity.hash = block.hash; | ||
blockEntity.save(); | ||
|
||
if (block.number == BigInt.fromI32(2)) { | ||
ContractTemplate.create( | ||
Address.fromString('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48') | ||
); | ||
} | ||
} | ||
|
||
export function handleBlockPolling(block: ethereum.Block): void { | ||
log.info('handleBlockPolling {}', [block.number.toString()]); | ||
let blockEntity = new BlockFromPollingHandler(block.number.toString()); | ||
blockEntity.number = block.number; | ||
blockEntity.hash = block.hash; | ||
blockEntity.save(); | ||
} | ||
|
||
export function handleBlockPollingFromTemplate(block: ethereum.Block): void { | ||
log.info('===> handleBlockPollingFromTemplate {}', [block.number.toString()]); | ||
let blockEntity = new BlockFromOtherPollingHandler(block.number.toString()); | ||
blockEntity.number = block.number; | ||
blockEntity.hash = block.hash; | ||
blockEntity.save(); | ||
} | ||
|
||
export function handleTrigger(event: Trigger): void { | ||
// We set the value to 0 to test that the subgraph | ||
// runs initialization handler before all other handlers | ||
if (event.params.x == 1) { | ||
let entity = Foo.load('initialize'); | ||
|
||
// If the intialization handler is called first | ||
// this would set the value to -1 for Foo entity with id 0 | ||
// If it is not called first then the value would be 0 | ||
if (entity != null) { | ||
entity.value = -1; | ||
entity.id = 'initialize'; | ||
entity.save(); | ||
} | ||
} | ||
|
||
let obj = new Foo(event.params.x.toString()); | ||
obj.id = event.params.x.toString(); | ||
obj.value = event.params.x; | ||
|
||
obj.save(); | ||
} | ||
|
||
export function initialize(block: ethereum.Block): void { | ||
log.info('initialize called at block', [block.number.toString()]); | ||
let entity = new Initialize(block.number.toString()); | ||
entity.id = block.number.toString(); | ||
entity.block = block.number; | ||
entity.save(); | ||
|
||
// If initialization handler is called then this would set | ||
// the value to 0 for Foo entity with id 0 | ||
// This is to test that initialization handler is called | ||
// before all other handlers | ||
let foo = new Foo('initialize'); | ||
foo.id = 'initialize'; | ||
foo.value = 0; | ||
foo.save(); | ||
} |
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,63 @@ | ||
specVersion: 0.0.6 | ||
schema: | ||
file: ./schema.graphql | ||
dataSources: | ||
- kind: ethereum/contract | ||
name: Contract | ||
network: neonlabs | ||
source: | ||
address: "0x0000000000000000000000000000000000000000" | ||
abi: Contract | ||
startBlock: 247101047 | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.6 | ||
language: wasm/assemblyscript | ||
abis: | ||
- name: Contract | ||
file: ./abis/Contract.abi | ||
entities: | ||
- Call | ||
eventHandlers: | ||
- event: Trigger(uint16) | ||
handler: handleTrigger | ||
blockHandlers: | ||
- handler: handleBlockPolling | ||
file: ./src/mapping.ts | ||
- kind: ethereum/contract | ||
name: BlockHandlerTest | ||
network: neonlabs | ||
source: | ||
address: "0x0000000000000000000000000000000000000000" | ||
abi: Contract | ||
startBlock: 247101047 | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.6 | ||
language: wasm/assemblyscript | ||
abis: | ||
- name: Contract | ||
file: ./abis/Contract.abi | ||
entities: | ||
- Call | ||
blockHandlers: | ||
- handler: handleBlock | ||
file: ./src/mapping.ts | ||
templates: | ||
- kind: ethereum/contract | ||
name: ContractTemplate | ||
network: neonlabs | ||
source: | ||
abi: Contract | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.6 | ||
language: wasm/assemblyscript | ||
entities: | ||
- Gravatar | ||
abis: | ||
- name: Contract | ||
file: ./abis/Contract.abi | ||
blockHandlers: | ||
- handler: handleBlockPollingFromTemplate | ||
file: ./src/mapping.ts |
Oops, something went wrong.