Save load and reset dapp::multi_index data

To enable these features, you must include the advanced multi index with: #define USE_ADVANCED_IPFS at the top of the contract file. If you have already deployed a contract that does not use advanced features, do not add this line, as it is not backwards compatible.

With that, you now have the ability to save the list of shards currently being used to represent the table’s current state. With the saved snapshot, a developer can upload it to another contract, or version the snapshot and save it to be loaded to the contract later. This adds much needed flexibility to maintaining database state in a vRAM table.

Save dapp::multi_index data

Using zeus, a backup file can be created with the following command:

zeus backup-table <CONTRACT> <TABLE>

# optional flags:

--endpoint # endpoint of node
# default: localhost:13115
--output # output file name
# default: vram-backup-${CONTRACT}-${TABLE}-0-1578405972.json

# example
zeus backup-table lqdportfolio users --endpoint=http://kylin-dsp-2.liquidapps.io/

Example: vram-backup-lqdportfolio-users-0-1578405972.json

{
  "contract": "lqdportfolio",
  "table": "users",
  "timestamp": "2020-01-07T14:06:12.339Z",
  "revision": 0,
  "manifest": {
    "next_available_key": 0,
    "shards": 1024,
    "buckets_per_shard": 64,
    "shardbuckets": [
      {
        "key": 2,
        "value": "015512202a1de9ce245a8d14b23512badc076aee71aad3aba30900e9c938243ce25b467d"
      },
      {
        "key": 44,
        "value": "015512205b43f739a9786fbe2c384c504af15d06fe1b5a61b72710f51932c6b62592d800"
      },
      ...
    ]
  }
}

Load manifest

Once a manifest is saved, it can be loaded with the following smart contract action.

With a unit test:

Clear table

By calling the clear command, a table’s version is incremented via the revision param and the next_available_key is reset

Last updated

Was this helpful?