-
Notifications
You must be signed in to change notification settings - Fork 116
Add api examples to monorepo #1155
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
Changes from 1 commit
d19c507
711be6e
4236c3a
bfa0305
36d510b
9dd1cab
ba05fb5
7081f0f
16687b6
c989f88
9e28c05
67f3baf
4f08ea2
0e3362b
0c3770d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,17 @@ | ||
| import { ApiPromise, WsProvider } from '@polkadot/api' | ||
| import { CuratorApplicationId } from '@joystream/types/content-working-group' | ||
| import { BTreeSet } from '@polkadot/types' | ||
| import { BTreeSet, createType, TypeRegistry } from '@polkadot/types' | ||
| import { types } from '@joystream/types' | ||
|
|
||
| async function main() { | ||
| const provider = new WsProvider('ws://127.0.0.1:9944') | ||
| const api = await ApiPromise.create({ provider, types }) | ||
|
|
||
| const wgId = [1, 2] | ||
|
|
||
| // Is it not possible to create the registry without actually connecting to a node? | ||
| const set = new BTreeSet<CuratorApplicationId>(api.registry, CuratorApplicationId, []) | ||
| const registry = new TypeRegistry() | ||
| registry.register(types) | ||
|
|
||
| const set = new BTreeSet<CuratorApplicationId>(registry, CuratorApplicationId, []) | ||
|
|
||
| wgId.forEach((id) => { | ||
| set.add(new CuratorApplicationId(api.registry, id)) | ||
| set.add(createType(registry, 'CuratorApplicationId', id)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found out we can actually use
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah yes that is neater, and one less import :) |
||
| }) | ||
|
|
||
| /* | ||
|
|
@@ -27,8 +25,6 @@ async function main() { | |
|
|
||
| console.log('copy/paste the output below to hire curator applicant(s) with WG IDs:', wgId) | ||
| console.log(set.toHex()) | ||
|
|
||
| api.disconnect() | ||
| } | ||
|
|
||
| main() | ||
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.
This script only needs to create some types and doesn't need to read state from chain, and therefore shouldn't require creating an api instance or connecting to a node. I this type of scenario, what is the proper way to create a type registry and register our types so we can construct them safely.
cc: @Lezek123
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 added a function to do this in https://github.com/Joystream/joystream/pull/1176/files#diff-9e9b5c1632859d4c7bee5d17dd9f7c5c, it's not well-tested yet, but I think it should work fine. I can move this to another PR if needed.
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.
Yes I spotted this also in pioneer react-api:
https://github.com/Joystream/joystream/blob/iznik/pioneer/packages/react-api/src/typeRegistry.ts
https://github.com/Joystream/joystream/blob/iznik/pioneer/packages/react-api/src/Api.tsx#L179
So it looks "safe" and correct way.