-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
3,874 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,44 @@ | ||
[ | ||
{ | ||
"name": "SignatureSubmittion", | ||
"type": "event", | ||
"inputs": [ | ||
{ | ||
"name": "chainId", | ||
"type": "uint256", | ||
"indexed": true, | ||
"internalType": "uint256" | ||
}, | ||
{ | ||
"name": "signer", | ||
"type": "address", | ||
"indexed": true, | ||
"internalType": "address" | ||
}, | ||
{ | ||
"name": "signature", | ||
"type": "bytes", | ||
"indexed": false, | ||
"internalType": "bytes" | ||
}, | ||
{ | ||
"name": "data", | ||
"type": "bytes", | ||
"indexed": false, | ||
"internalType": "bytes" | ||
} | ||
], | ||
"anonymous": false | ||
}, | ||
{ | ||
"name": "submit", | ||
"type": "function", | ||
"inputs": [ | ||
{ "name": "chainId", "type": "uint256", "internalType": "uint256" }, | ||
{ "name": "signature", "type": "bytes", "internalType": "bytes" }, | ||
{ "name": "data", "type": "bytes", "internalType": "bytes" } | ||
], | ||
"outputs": [], | ||
"stateMutability": "nonpayable" | ||
} | ||
] |
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,7 @@ | ||
{ | ||
"darwinia": { | ||
"SubAPISignaturePub": { | ||
"address": "0x6e40a3621614b12821a0f184a03798ad505e4758" | ||
} | ||
} | ||
} |
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,21 @@ | ||
{ | ||
"name": "signcribe", | ||
"version": "0.0.1", | ||
"scripts": { | ||
"codegen": "graph codegen", | ||
"build": "graph build", | ||
"deploy:studio": "graph deploy --node https://api.studio.thegraph.com/deploy/", | ||
"create:darwinia": "graph create --node https://thegraph-g2.darwinia.network/ormpipe/deploy/", | ||
"remove:darwinia": "graph remove --node https://thegraph-g2.darwinia.network/ormpipe/deploy/", | ||
"deploy:darwinia": "graph deploy --node https://thegraph-g2.darwinia.network/ormpipe/deploy/ --ipfs https://ipfs.network.thegraph.com", | ||
"create:local": "graph create --node http://127.0.0.1:8020", | ||
"remove:local": "graph remove --node http://127.0.0.1:8020", | ||
"deploy:local": "graph deploy --node http://127.0.0.1:8020 --ipfs https://ipfs.network.thegraph.com", | ||
"test": "graph test" | ||
}, | ||
"dependencies": { | ||
"@graphprotocol/graph-cli": "0.55.0", | ||
"@graphprotocol/graph-ts": "0.30.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,12 @@ | ||
|
||
## ======= signcribe | ||
type SignatureSubmittion @entity(immutable: true) { | ||
id: Bytes! | ||
chainId: BigInt! # uint256 | ||
signer: Bytes! # address | ||
signature: Bytes! # bytes | ||
data: Bytes! # bytes | ||
blockNumber: BigInt! | ||
blockTimestamp: BigInt! | ||
transactionHash: 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,20 @@ | ||
import { SignatureSubmittion as SignatureSubmittionEvent } from "../generated/SubAPISignaturePub/SubAPISignaturePub" | ||
import { SignatureSubmittion } from "../generated/schema" | ||
|
||
export function handleSignatureSubmittion( | ||
event: SignatureSubmittionEvent | ||
): void { | ||
let entity = new SignatureSubmittion( | ||
event.transaction.hash.concatI32(event.logIndex.toI32()) | ||
) | ||
entity.chainId = event.params.chainId | ||
entity.signer = event.params.signer | ||
entity.signature = event.params.signature | ||
entity.data = event.params.data | ||
|
||
entity.blockNumber = event.block.number | ||
entity.blockTimestamp = event.block.timestamp | ||
entity.transactionHash = event.transaction.hash | ||
|
||
entity.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,24 @@ | ||
specVersion: 0.0.5 | ||
schema: | ||
file: ./schema.graphql | ||
dataSources: | ||
- kind: ethereum | ||
name: SubAPISignaturePub | ||
network: darwinia | ||
source: | ||
address: "0x6e40a3621614b12821a0f184a03798ad505e4758" | ||
abi: SubAPISignaturePub | ||
startBlock: 1803702 | ||
mapping: | ||
kind: ethereum/events | ||
apiVersion: 0.0.7 | ||
language: wasm/assemblyscript | ||
entities: | ||
- SignatureSubmittion | ||
abis: | ||
- name: SubAPISignaturePub | ||
file: ./abis/SubAPISignaturePub.json | ||
eventHandlers: | ||
- event: SignatureSubmittion(indexed uint256,indexed address,bytes,bytes) | ||
handler: handleSignatureSubmittion | ||
file: ./src/sub-api-signature-pub.ts |
32 changes: 32 additions & 0 deletions
32
thegraph/packages/signcribe/tests/sub-api-signature-pub-utils.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,32 @@ | ||
import { newMockEvent } from "matchstick-as" | ||
import { ethereum, BigInt, Address, Bytes } from "@graphprotocol/graph-ts" | ||
import { SignatureSubmittion } from "../generated/SubAPISignaturePub/SubAPISignaturePub" | ||
|
||
export function createSignatureSubmittionEvent( | ||
chainId: BigInt, | ||
signer: Address, | ||
signature: Bytes, | ||
data: Bytes | ||
): SignatureSubmittion { | ||
let signatureSubmittionEvent = changetype<SignatureSubmittion>(newMockEvent()) | ||
|
||
signatureSubmittionEvent.parameters = new Array() | ||
|
||
signatureSubmittionEvent.parameters.push( | ||
new ethereum.EventParam( | ||
"chainId", | ||
ethereum.Value.fromUnsignedBigInt(chainId) | ||
) | ||
) | ||
signatureSubmittionEvent.parameters.push( | ||
new ethereum.EventParam("signer", ethereum.Value.fromAddress(signer)) | ||
) | ||
signatureSubmittionEvent.parameters.push( | ||
new ethereum.EventParam("signature", ethereum.Value.fromBytes(signature)) | ||
) | ||
signatureSubmittionEvent.parameters.push( | ||
new ethereum.EventParam("data", ethereum.Value.fromBytes(data)) | ||
) | ||
|
||
return signatureSubmittionEvent | ||
} |
74 changes: 74 additions & 0 deletions
74
thegraph/packages/signcribe/tests/sub-api-signature-pub.test.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,74 @@ | ||
import { | ||
assert, | ||
describe, | ||
test, | ||
clearStore, | ||
beforeAll, | ||
afterAll | ||
} from "matchstick-as/assembly/index" | ||
import { BigInt, Address, Bytes } from "@graphprotocol/graph-ts" | ||
import { SignatureSubmittion } from "../generated/schema" | ||
import { SignatureSubmittion as SignatureSubmittionEvent } from "../generated/SubAPISignaturePub/SubAPISignaturePub" | ||
import { handleSignatureSubmittion } from "../src/sub-api-signature-pub" | ||
import { createSignatureSubmittionEvent } from "./sub-api-signature-pub-utils" | ||
|
||
// Tests structure (matchstick-as >=0.5.0) | ||
// https://thegraph.com/docs/en/developer/matchstick/#tests-structure-0-5-0 | ||
|
||
describe("Describe entity assertions", () => { | ||
beforeAll(() => { | ||
let chainId = BigInt.fromI32(234) | ||
let signer = Address.fromString( | ||
"0x0000000000000000000000000000000000000001" | ||
) | ||
let signature = Bytes.fromI32(1234567890) | ||
let data = Bytes.fromI32(1234567890) | ||
let newSignatureSubmittionEvent = createSignatureSubmittionEvent( | ||
chainId, | ||
signer, | ||
signature, | ||
data | ||
) | ||
handleSignatureSubmittion(newSignatureSubmittionEvent) | ||
}) | ||
|
||
afterAll(() => { | ||
clearStore() | ||
}) | ||
|
||
// For more test scenarios, see: | ||
// https://thegraph.com/docs/en/developer/matchstick/#write-a-unit-test | ||
|
||
test("SignatureSubmittion created and stored", () => { | ||
assert.entityCount("SignatureSubmittion", 1) | ||
|
||
// 0xa16081f360e3847006db660bae1c6d1b2e17ec2a is the default address used in newMockEvent() function | ||
assert.fieldEquals( | ||
"SignatureSubmittion", | ||
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1", | ||
"chainId", | ||
"234" | ||
) | ||
assert.fieldEquals( | ||
"SignatureSubmittion", | ||
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1", | ||
"signer", | ||
"0x0000000000000000000000000000000000000001" | ||
) | ||
assert.fieldEquals( | ||
"SignatureSubmittion", | ||
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1", | ||
"signature", | ||
"1234567890" | ||
) | ||
assert.fieldEquals( | ||
"SignatureSubmittion", | ||
"0xa16081f360e3847006db660bae1c6d1b2e17ec2a-1", | ||
"data", | ||
"1234567890" | ||
) | ||
|
||
// More assert options: | ||
// https://thegraph.com/docs/en/developer/matchstick/#asserts | ||
}) | ||
}) |
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", "tests"] | ||
} |
Oops, something went wrong.