0.3.0 • Published 3 years ago

inha v0.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

parse-cosmwasm-schema

Parser for JSON schemas generated from CosmWasm, useful for creating automated contract tooling.

Table of Contents

Quickstart

Add to your package.json by using Yarn or NPM.

$ yarn add parse-cosmwasm-schema

Then, in your program:

import parseSchema from "parse-cosmwasm-schema";

// any schema generated by CosmWasm
const schema = {
  ...
};

parseSchema(schema).then(parseTree => {
  // the resultant parse tree is JSON
  console.log(JSON.stringify(parseTree, null, 2));
})

Introduction

Smart contracts on Terra (powered by CosmWasm) use JSON messages to define interactions. Each smart contract defines its interface through a JSON schema which specifies the structure and expected format of the messages that it can respond to. By reading the JSON schema, we are able to extract information which can be used to automatically generate tools that would otherwise require tedious manual labor.

parse-cosmwasm-schema provides an algorithm that reads in a CosmWasm-generated JSON schema and produces a JSON-based parse tree of the original Rust data. Because it is written in TypeScript, it also provides a set of types that are helpful for walking the parse tree, for writing your own custom solutions.

Output Structure

The output is a parse tree represented as a JSON object, which can be one of several NodeType definitions.

All nodes follow the format:

{
  "type": "<node-type>",
  "value": {
    "title": "<node-title>", // or undefined
    "description": "<node-description>", // or undefined
    ... // additional properties depending on node type
  },
  "ref": "<ref-name>" // if derived from a resolved reference, will be a string.
}

Simple Nodes

None

  • type: none

Boolean

  • type: boolean

String

  • type: string

Integer

  • type: integer
  • properties:
    • size: type of integer (e.g. u32, u64, etc.)

Composite Nodes

The following node types can include other node types.

Enum

  • type: enum
  • properties:
    • variants: a list of possible other node types

Struct

  • type: struct
  • properties:
    • members: an object where keys are member names and values are nodes

Optional

  • type: optional
  • properties:
    • body: a node type

Array

  • type: array
  • properties:
    • contents: node type of array's elements
    • size: number size of array

Vec

  • type: vec
  • properties:
    • contents: node type of vector's elements

Tuple

  • type: tuple
  • properties:
    • contents: an array of node types

List of Tools

parse-cosmwasm-schema is used to power a number of useful contract tools.

By Terraform Labs

NameDescription
gen-contract-docsGenerates documentation for smart contract messages
gen-contract-sdkGenerates Python and JavaScript SDKs for smart contracts
gen-contract-cliGenerates a command-line interface for smart contract
gen-contract-uiWeb-based UI tool for interacting with smart contracts

Community

Made something cool but not on here? Make a pull request to add it to the list.