Skip to content

Latest commit

 

History

History

resource-viewer

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Move Resource Viewer

Move Resource Viewer is a tool to query LCS resources data from blockchain nodes storage (i.e. dnode or diem) and represent them in JSON or human readable format.

How does it works?

  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.

Installation

Requirements:

  • Rust toolchain, the easiest way to get it is to use Rustup.

Using cargo:

cargo install --git https://github.com/dfinance/move-tools.git move-resource-viewer

Build with optional features

  • json-schema - adds option to export json schema for output format
  • dfinance_address - support DFinance node & address format
  • libra_address - support Libra/Diem address format
  • ps_address - support Substrate node & ss58 address format

Add shousen features as list to the command line:

cargo install --git https://github.com/dfinance/move-tools.git move-resource-viewer \
    --no-default-features \
    --features="feature, feature, feature"

For example To build Resource Viewer for Polkadot/Substrate use:

    --no-default-features --features="ps_address"

Usage example

Query the user's ETH balance:

move-resource-viewer -a wallet1n9w22mvaq7uuswr4j53usd0spd2mznphq3q3zp \
                          -q "0x1::Account::Balance<0x1::ETH::T>" \
                          --api="https://rest.testnet.dfinance.co" \
                          -o=output.json
# optional block number:  --height 42

# Optionally add          --json-schema schema.json
# or just                 --json-schema -
# It exports schema for output format to specified file (schema.json)
# In case of `-` as path, it just prints schema to stdout.

Input parameters

  • -a / --account can be in Dfinance bech32 or hex 0x…{16-20 bytes} encoding formats
  • -q / --query resource type-path, e.g.:
    • 0x1::Account::Balance<0x1::XFI::T>
    • 0x1::Account::Balance<0x1::Coins::ETH>
    • 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.

Substrate

Additionally if Resource Viewer was built with ps_address feature, ss58-addresses are acceptable for --account and --query parameters.

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:

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

JSON example:

{
  "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
              }
            }
          ]
        }
      }
    }
  ]
}