This repository was archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 93
View state #684
Merged
Merged
View state #684
Changes from all commits
Commits
Show all changes
5 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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| const exitOnError = require('../utils/exit-on-error'); | ||
| const connect = require('../utils/connect'); | ||
| const { formatResponse } = require('../utils/inspect-response'); | ||
|
|
||
| module.exports = { | ||
| command: 'view-state <account-id> [prefix]', | ||
| desc: 'View contract storage state', | ||
| builder: (yargs) => yargs | ||
| .option('prefix', { | ||
| desc: 'Return keys only with given prefix.', | ||
| type: 'string', | ||
| default: '' | ||
|
|
||
| }) | ||
| .option('block-id', { | ||
| desc: 'The block number OR the block hash (base58-encoded).', | ||
| type: 'string', | ||
|
|
||
| }) | ||
| .option('finality', { | ||
| desc: '`optimistic` uses the latest block recorded on the node that responded to your query,\n' + | ||
| '`final` is for a block that has been validated on at least 66% of the nodes in the network', | ||
| type: 'string', | ||
| choices: ['optimistic', 'final'], | ||
|
|
||
| }) | ||
| .option('utf8', { | ||
| desc: 'Decode keys and values as UTF-8 strings', | ||
| type: 'boolean', | ||
| default: false | ||
| }), | ||
| handler: exitOnError(viewState) | ||
| }; | ||
|
|
||
| async function viewState(options) { | ||
| const { accountId, prefix, finality, blockId, utf8 } = options; | ||
| const near = await connect(options); | ||
| const account = await near.account(accountId); | ||
|
|
||
| let state = await account.viewState(prefix, { blockId, finality }); | ||
| if (utf8) { | ||
| state = state.map(({ key, value}) => ({ key: key.toString('utf-8'), value: value.toString('utf-8') })); | ||
| } | ||
| console.log(formatResponse(state, options)); | ||
| } | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Semantically it's the same as
state. Should we rename it toview-contract-state, or simplycontract-state? @mikedotexe @evgenykuzyakov @chadoh need your opinion 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.
Once we have the namespaces proposed in near/NEPs#31, I would advocate for
near contract state. But I doubt it makes sense to do that for now.In the meantime, I don't have a strong preference.
near view-state some-contract.nearseems fine to me.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'll just roll as is then and makes sense to me to change to namespaces long term.