-
Notifications
You must be signed in to change notification settings - Fork 4
Moving code from api-examples repo #1
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
Merged
Merged
Changes from 1 commit
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 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 |
|---|---|---|
| @@ -1,2 +1,12 @@ | ||
| # runtime-state-export-tools | ||
| Scripts for exporting runtime state | ||
| # Runtime state export tools | ||
| Scripts to export state from a running chain over rpc. | ||
|
|
||
|
|
||
| ## Run export scripts | ||
|
|
||
| ``` | ||
| yarn | ||
| yarn export-members > members.json | ||
| yarn export-forum > forum.json | ||
| yarn export-content > content.json | ||
| ``` |
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,26 @@ | ||
| { | ||
| "name": "@joystream/api-examples", | ||
| "version": "1.0.0", | ||
| "license": "GPL-3.0-only", | ||
| "scripts": { | ||
| "postinstall": "yarn tsc", | ||
| "export-members": "node lib/export_members", | ||
| "export-forum": "node lib/export_forum", | ||
| "export-content": "node lib/export_content", | ||
| "export-balances": "node lib/export_balances" | ||
| }, | ||
| "dependencies": { | ||
| "@joystream/types": "^0.12.0", | ||
| "@polkadot/api": "^0.96.1", | ||
| "@polkadot/keyring": "^1.7.0-beta.5", | ||
| "@polkadot/types": "^0.96.1", | ||
| "@polkadot/util": "^1.7.0-beta.5", | ||
| "@polkadot/util-crypto": "^1.7.0-beta.5", | ||
| "@types/bn.js": "^4.11.5", | ||
| "bn.js": "^4.11.8" | ||
| }, | ||
| "devDependencies": { | ||
| "@polkadot/ts": "^0.1.56", | ||
| "typescript": "3.7.2" | ||
| } | ||
| } |
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,21 @@ | ||
| // @ts-check | ||
|
|
||
| import { ApiPromise, WsProvider } from '@polkadot/api'; | ||
| import { registerJoystreamTypes } from '@joystream/types'; | ||
|
|
||
| export default async function create_api () { | ||
| // Get URL to websocket endpoint from environment or connect to local node by default | ||
| const WS_URL = process.env['WS_URL'] || 'ws://127.0.0.1:9944' | ||
|
|
||
| // Initialise the provider | ||
| const provider = new WsProvider(WS_URL); | ||
|
|
||
| // register types before creating the api | ||
| registerJoystreamTypes(); | ||
|
|
||
| // Create the API and wait until ready | ||
| let api = await ApiPromise.create({ provider }); | ||
| await api.isReady; | ||
|
|
||
| return api; | ||
| } |
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,67 @@ | ||
| import create_api from './api' | ||
| import { ApiPromise } from '@polkadot/api' | ||
| import { Profile, MemberId } from '@joystream/types/members' | ||
| import { Option } from '@polkadot/types/' | ||
| import { AccountId } from '@polkadot/types/interfaces' | ||
|
|
||
| main() | ||
|
|
||
| async function main () { | ||
| const api = await create_api() | ||
| // WIP | ||
| console.log(await enumerate_member_accounts(api)) | ||
| api.disconnect() | ||
| } | ||
|
|
||
| // member accounts: get freebalance and reserved balances (council participation) | ||
| async function enumerate_member_accounts(api: ApiPromise) : Promise<AccountId[]> { | ||
| const first = 0 | ||
| const next = (await api.query.members.membersCreated() as MemberId).toNumber(); | ||
|
|
||
| let accounts: AccountId[] = []; | ||
|
|
||
| for (let id = first; id < next; id++ ) { | ||
| const profile = await api.query.members.memberProfile(id) as Option<Profile>; | ||
|
|
||
| if (profile.isSome) { | ||
| const p = profile.unwrap(); | ||
| if (!accounts.includes(p.root_account)) { | ||
| accounts.push(p.root_account) | ||
| } | ||
| if (!accounts.includes(p.controller_account)) { | ||
| accounts.push(p.controller_account) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return accounts; | ||
| } | ||
|
|
||
| // TODO: | ||
| // staked amounts: we will computer the staked amount associated with various roles and | ||
| // add it to the free balance to be the starting freebalance on new chain. | ||
|
|
||
| // * enumerate council seat accounts and backers | ||
| // calculated stake amount from council/election structures or just reserved balance from balances module? | ||
| // * working groups | ||
| // storage -> stake_id -> staked amount (staking account) | ||
| // role account | ||
| // identify the member by member id and balances to the member account balance | ||
| // content -> curators -> stake_id (role and application) -> staked amount? | ||
| // role account | ||
| // identify the member by member id and add balances to the member account balance | ||
| // * Stake behind an active proposal - proposal created by a member -> add to their root account balance | ||
| // * Validators -> stash and controller accounts - can't identify an associated member so just include the | ||
| // the accounts as is, read lock information real balance in the stash account, controller just free balance. | ||
|
|
||
| // since we have not enabled the account indices OnNewAccount hook, we cannot enumerate accounts. | ||
| // there may be accounts used in past roles that have balances but at snapshot time are not associated | ||
| // with a member or active role. | ||
| // To enumerate these accounts we must iterate over past Events from the system | ||
| // transfer event and or account created events | ||
| // assume no locks, reservation or stake is associated, so just lookup the freebalance for these accounts | ||
|
|
||
| // to avoid doing this search for accounts, we can advise members if they have any balance in accounts | ||
| // not associated with a member or role to transfer that balance to one of their member accounts | ||
|
|
||
| // compare the computed balance with total issuance as a sanity check. | ||
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.
This is still a Work in progress will update in later PR today hopefully.
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.
basic implementation done in 0b787aa
will improve in future PR