-
Notifications
You must be signed in to change notification settings - Fork 227
Feature/near data source template #824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
maoueh
wants to merge
2
commits into
graphprotocol:ci/sf/feature/schema-per-protocol
Choose a base branch
from
streamingfast:feature/near-data-source-template
base: ci/sf/feature/schema-per-protocol
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,86 @@ | ||
scalar String | ||
scalar File | ||
scalar BigInt | ||
|
||
type SubgraphManifest { | ||
specVersion: String! | ||
features: [String!] | ||
schema: Schema! | ||
description: String | ||
repository: String | ||
graft: Graft | ||
dataSources: [DataSource!]! | ||
templates: [DataSourceTemplate!] | ||
} | ||
|
||
type Schema { | ||
file: File! | ||
} | ||
|
||
type DataSource { | ||
kind: String! | ||
name: String! | ||
network: String | ||
source: ContractSource! | ||
mapping: ContractMapping! | ||
} | ||
|
||
type ContractSource { | ||
address: String | ||
abi: String! | ||
startBlock: BigInt | ||
} | ||
|
||
type ContractMapping { | ||
kind: String | ||
apiVersion: String! | ||
language: String! | ||
file: File! | ||
entities: [String!]! | ||
abis: [ContractAbi!]! | ||
blockHandlers: [BlockHandler!] | ||
callHandlers: [CallHandler!] | ||
eventHandlers: [ContractEventHandler!] | ||
} | ||
|
||
type ContractAbi { | ||
name: String! | ||
file: File! | ||
} | ||
|
||
type BlockHandler { | ||
handler: String! | ||
filter: BlockFilter | ||
} | ||
|
||
type BlockFilter { | ||
kind: String! | ||
} | ||
|
||
type CallHandler { | ||
function: String! | ||
handler: String! | ||
} | ||
|
||
type ContractEventHandler { | ||
event: String! | ||
topic0: String | ||
handler: String! | ||
} | ||
|
||
type Graft { | ||
base: String! | ||
block: BigInt! | ||
} | ||
|
||
type DataSourceTemplate { | ||
kind: String! | ||
name: String! | ||
network: String | ||
source: ContractSourceTemplate! | ||
mapping: ContractMapping! | ||
} | ||
|
||
type ContractSourceTemplate { | ||
abi: String! | ||
} |
This file contains hidden or 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,59 @@ | ||
scalar String | ||
scalar File | ||
scalar BigInt | ||
|
||
type SubgraphManifest { | ||
specVersion: String! | ||
schema: Schema! | ||
description: String | ||
repository: String | ||
graft: Graft | ||
dataSources: [DataSource!]! | ||
templates: [DataSourceTemplate!] | ||
} | ||
|
||
type Schema { | ||
file: File! | ||
} | ||
|
||
type DataSource { | ||
kind: String! | ||
name: String! | ||
network: String | ||
source: ContractSource! | ||
mapping: ContractMapping! | ||
} | ||
|
||
type ContractSource { | ||
account: String | ||
startBlock: BigInt | ||
} | ||
|
||
type ContractMapping { | ||
apiVersion: String! | ||
language: String! | ||
file: File! | ||
entities: [String!]! | ||
blockHandlers: [BlockHandler!] | ||
receiptHandlers: [ReceiptHandler!] | ||
} | ||
|
||
type BlockHandler { | ||
handler: String! | ||
} | ||
|
||
type ReceiptHandler { | ||
handler: String! | ||
} | ||
|
||
type Graft { | ||
base: String! | ||
block: BigInt! | ||
} | ||
|
||
type DataSourceTemplate { | ||
kind: String! | ||
name: String! | ||
network: String | ||
mapping: ContractMapping! | ||
} |
This file contains hidden or 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 hidden or 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,40 @@ | ||
const tsCodegen = require('../../../codegen/typescript') | ||
|
||
module.exports = class NearTemplateCodeGen { | ||
constructor(template) { | ||
this.template = template | ||
} | ||
|
||
generateModuleImports() { | ||
return [] | ||
} | ||
|
||
generateCreateMethod() { | ||
const name = this.template.get('name') | ||
|
||
return tsCodegen.staticMethod( | ||
'create', | ||
[tsCodegen.param('account', tsCodegen.namedType('string'))], | ||
tsCodegen.namedType('void'), | ||
` | ||
DataSourceTemplate.create('${name}', [account]) | ||
`, | ||
) | ||
} | ||
|
||
generateCreateWithContextMethod() { | ||
const name = this.template.get('name') | ||
|
||
return tsCodegen.staticMethod( | ||
'createWithContext', | ||
[ | ||
tsCodegen.param('account', tsCodegen.namedType('string')), | ||
tsCodegen.param('context', tsCodegen.namedType('DataSourceContext')), | ||
], | ||
tsCodegen.namedType('void'), | ||
` | ||
DataSourceTemplate.createWithContext('${name}', [account], context) | ||
`, | ||
) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you'll need to add
'near'
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not required because there is actually no
near
type involved in the generated code:I tested the full flow of NEAR data source template and it worked great.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see why I thought that, that's because you're not using the
Account
type from thenear
module. I would prefer that instead of usingstring
directly. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm ambivalent.
If we go with
Account
, it should be used thoroughly everywhere, right now it's a mixed usage ingraph-ts
(mostly 50/50).The second thing that makes it me doubt is how people on NEAR are used to work directly with
string
. I've research this a little bit and it seemsAccountId
is used more (https://github.com/near/near-sdk-rs/blob/05c389c75a568af3f37a3346d6f7b4064852e1de/near-sdk/src/types/account_id.rs#L39) although I've seen various example dealing with String directly. The AssemblyScript however does not seems to have an AccountId alias and seems to deal withstring
directly: https://github.com/near/near-sdk-as/blob/master/sdk-core/assembly/contract.ts#L12.I prefer
string
personally as it make the cognitive load lower. If we choose to still wrap it, I'm voting more forAccountId
to align with the Rust SDK for NEAR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I see 🤔
Well we can discuss that later then, I'm gonna merge this, thanks for the PR!!