Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
[v1.6] $ dove view (#211)
Browse files Browse the repository at this point in the history
* dove view

* lang version +1

* clippy

* update cli

* README.md

* non-working code is commented out

* rebase [master]

* removed "const STDOUT_PATH"
added "display_order"

* hints

* mod tests

* hints

* misspell
  • Loading branch information
vladimirovmm authored Feb 21, 2022
1 parent c95fed7 commit 58b39a4
Show file tree
Hide file tree
Showing 22 changed files with 541 additions and 533 deletions.
81 changes: 81 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
members = [
"dove",
"lang",
"net",
"common/git-hash",
"resource-viewer",
"pontem/client"
]
exclude = [ "pontem/hash_project", "pontem/pontemapi"]
Expand Down
106 changes: 106 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,112 @@ dove deploy MODULE_NAME --secret --url https://127.0.0.1:9933 --gas 400
dove deploy PATH/TO/FILE --account //Alice --gas 300
```

## Resource Viewer
Move Resource Viewer is a tool to query [BCS](https://github.com/diem/bcs) resources data from blockchain nodes storage and represent them in JSON or human readable format.

1. The viewer makes a request to the blockchain node by a sending specific query (address + resource type).
2. The viewer send another request to node and query resource type layout.
3. The viewer restores resources using response data and type layout.

## Usage example

Query the user's store contract balance:

```bash
dove view "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY::Store::Store<u64>" --api "ws://127.0.0.1:9946"
```

### Input parameters

- `[QUERY]` resource type-path, e.g.:
- `0x1::Account::Balance<0x1::PONT::PONT>`
- `5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY::Store::Store<u64>`
- In general: `0xDEADBEEF::Module::Struct< 0xBADBEEF::Mod::Struct<...>, ... >`
- Inner address can be omitted, it's inherited by parent:
`0xDEADBEEF::Module::Struct<Mod::Struct>` expands to `0xDEADBEEF::Module::Struct<0xDEADBEEF::Mod::Struct>`
- Query can ends with index `[42]` for `vec`-resources
- Output options:
- `-o` / `--output` fs-path to output file
- `-j` / `--json` sets output format to json. Can be omitted if output file extension is `.json`, so then json format will be chosen automatically.
- `--json-schema` additional json-schema export, fs-path to output schema file.

For more info check out `--help`.

### Output

Two output formats supported:

- Move-like text
- JSON

_The structure of the output in JSON is described in the scheme, which can be obtained by calling with the `--json-schema` parameter._

#### Move-like example:

```rust
resource 00000000::Account::Balance<00000000::Coins::BTC> {
coin: resource 00000000::Dfinance::T<00000000::Coins::BTC> {
value: 1000000000u128
}
}
```

#### JSON example:

```json
{
"is_resource": true,
"type": {
"address": "0000000000000000000000000000000000000001",
"module": "Account",
"name": "Balance",
"type_params": [
{
"Struct": {
"address": "0000000000000000000000000000000000000001",
"module": "Coins",
"name": "BTC",
"type_params": []
}
}
]
},
"value": [
{
"id": "coin",
"value": {
"Struct": {
"is_resource": true,
"type": {
"address": "0000000000000000000000000000000000000001",
"module": "Dfinance",
"name": "T",
"type_params": [
{
"Struct": {
"address": "0000000000000000000000000000000000000001",
"module": "Coins",
"name": "BTC",
"type_params": []
}
}
]
},
"value": [
{
"id": "value",
"value": {
"U128": 1000000000
}
}
]
}
}
}
]
}
```

## LICENSE

[LICENSE](/LICENSE)
Expand Down
4 changes: 4 additions & 0 deletions dove/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ edition = "2021"
[dependencies]
# LOCAL
git-hash = { path = "../common/git-hash" }
resource-viewer = { path = "../resource-viewer" }
lang = { path = "../lang" }
net = { path = "../net" }
pontem-client = { path = "../pontem/client" }

# DIEM
Expand All @@ -28,6 +30,7 @@ move-package = { git = "https://github.com/pontem-network/move.git", branch = "r
move-command-line-common = { git = "https://github.com/pontem-network/move.git", branch = "release-1.6" }
move-cli = { git = "https://github.com/pontem-network/move.git", branch = "release-1.6" }
pontem = { git = "https://github.com/pontem-network/move.git", branch = "release-1.6" }
move-resource-viewer = { package = "move-resource-viewer", git = "https://github.com/pontem-network/move.git", branch = "release-1.6" }

# third-party dependencies
log = "0.4.14"
Expand All @@ -51,6 +54,7 @@ itertools = "0.9.0"
uint = "0.9.1"
smallvec = "1.8.0"
diem-crypto = "0.0.3"
serde_json = "1.0"

# Used for storing access keys
aes = "0.7"
Expand Down
10 changes: 8 additions & 2 deletions dove/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use crate::cmd::clean::Clean;
use crate::cmd::run::Run;
use crate::cmd::call::ExecuteTransaction;
use crate::cmd::key::Key;
use crate::context::Context;

use crate::cmd::deploy::Deploy;
use crate::cmd::view::View;
use crate::context::Context;
use crate::natives::{all_natives, pontem_cost_table};

#[derive(StructOpt)]
Expand Down Expand Up @@ -91,6 +91,11 @@ pub enum DoveCommands {
#[structopt(flatten)]
cmd: Key,
},
#[structopt(about = "Resource viewer", display_order = 19)]
View {
#[structopt(flatten)]
cmd: View,
},
}

fn preprocess_args(args: Vec<String>) -> Vec<String> {
Expand Down Expand Up @@ -152,6 +157,7 @@ pub fn execute(args: Vec<String>, cwd: PathBuf) -> Result<()> {
DoveCommands::Run { mut cmd } => cmd.apply(&mut ctx),
DoveCommands::Call { mut cmd } => cmd.apply(&mut ctx),
DoveCommands::Deploy { mut cmd } => cmd.apply(&mut ctx),
DoveCommands::View { mut cmd } => cmd.apply(&mut ctx),
DoveCommands::Build
| DoveCommands::Test
| DoveCommands::Prove
Expand Down
2 changes: 2 additions & 0 deletions dove/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ pub mod deploy;
pub mod key;
/// Script executor.
pub mod run;
/// resource-viewer
pub mod view;
Loading

0 comments on commit 58b39a4

Please sign in to comment.