-
Notifications
You must be signed in to change notification settings - Fork 82
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
View function poc - do not merge #153
Changes from 1 commit
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { ApiPromise } from '@polkadot/api' | ||
import { TypeRegistry } from '@polkadot/types' | ||
import { hexToU8a } from '@polkadot/util' | ||
|
||
import { Config } from './schema' | ||
import { runTask, taskHandler } from './executor' | ||
import { setup } from './setup' | ||
|
||
export const nonce = async (argv: Config) => { | ||
const accountId = argv['accountId'] as `0x${string}` | ||
|
||
const context = await setup(argv) | ||
const wasm = await context.chain.head.wasm | ||
const block = context.chain.head | ||
const parent = await block.parentBlock | ||
|
||
const getNonce = async () => { | ||
const result = await runTask( | ||
{ | ||
wasm, | ||
calls: [['AccountNonceApi_account_nonce', accountId]], | ||
storage: [], | ||
mockSignatureHost: false, | ||
allowUnresolvedImports: false, | ||
}, | ||
taskHandler(parent) | ||
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. this is not correct. this need to be head 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. this can be |
||
) | ||
if (result.Error) { | ||
throw new Error(result.Error) | ||
} | ||
|
||
const registry = new TypeRegistry(); | ||
return { | ||
result: registry.createType('u64', hexToU8a(result.Call.result)).toNumber(), | ||
accessedStorageKeys: result.Call.accessedStorageKeys, | ||
} | ||
} | ||
|
||
const { accessedStorageKeys } = await getNonce() | ||
|
||
const api = await ApiPromise.create({ provider: context.api.provider }) | ||
const unsub = await api.rpc.state.subscribeStorage(accessedStorageKeys, async (_changes) => { | ||
const nonce = await getNonce(); | ||
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. need to resub the new storages just in case it is accessing something else |
||
console.log('>>> nonce:', nonce.result) | ||
}) | ||
|
||
// process.exit(0) | ||
} |
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.
need to deupe this