0.1.18 • Published 7 years ago

solidity-structure v0.1.18

Weekly downloads
5
License
ISC
Repository
github
Last release
7 years ago

Solidity structure

Parse structure of ethereum solidity contract, including enums,constructor, structs. Based on Solidity Parser library from ConsenSys.

The goal of it is to take Solidity code as input and return an object as output that can be used to describe all parts of Solidity smart contract.

Build status Coverage bitHound Code

Instalation

npm install solidity-structure

Usage in code

const SolidityStructure = require("solidity-structure");

// Parse Solidity code as a string:
let result = SolidityStructure.parse("contract { ... }");

// Or, parse a file:
let result = SolidityStructure.parseFile("./path/to/file.sol");

Usage in command line

(suppose solidity-structure package installed globally )

user@host:/solidity-structure MyContract.sol > contract-structure.json

Examples

Contract constructor structure

Solidity contract HasConstructor

pragma solidity ^0.4.4;

/**
* Contract with constructor
*/
contract WithConstructor {

  /**
   * My constructor long long description
   * @dev my constructor short description
   * @param uintParam Description of item 1
   * @param uintParam2
   */
   function  WithConstructor (  uint uintParam,  string stringParam,  uint uintParam2) {
     //empty
   }
}

Structure of constructor

{
        name: 'WithConstructor',
        title: 'my constructor short description',
        description: 'My constructor long long description',
        paramsSeq: [
          'uintParam',
          'stringParam',
          'uintParam2'
        ],
        params: {
          uintParam: {
            name : 'uintParam',
            description: 'Description of item 1',
            type: 'uint',
            typeHint: null
          },
          stringParam: {
            name: 'stringParam',
            type: 'string'
          },
          uintParam2: {
            name : 'uintParam2',
            description: '',
            type: 'uint',
            typeHint: null
          },
        }
}

Contract enum structure

Solidity contract HasEnum

pragma solidity ^0.4.4;

/**
* Contract has enum
*/
contract HasEnum {

   /**
   * My enum lon long description
   * @dev my enum short description
   * @param item1 Description of item 1
   * @param item2
   * @param item4 Item 4 some description
   */
   enum MyEnum  {
      item1,
      item2,
      item3,
      item4
   }
}

Structure of enum

{
        MyEnum: {
          name: 'MyEnum',
          title: 'my enum short description',
          description: 'My enum lon long description',
          members: [
            'item1',
            'item2',
            'item3',
            'item4'
          ],
          params: {
            item1: {
              description: 'Description of item 1'
            },
            item2: {
              description : ''
            },
            item4: {
              description: 'Item 4 some description'
            }
          }

        }
}

Other examples can be found in tests

0.1.18

7 years ago

0.1.17

7 years ago

0.1.16

7 years ago

0.1.15

7 years ago

0.1.14

7 years ago

0.1.13

7 years ago

0.1.12

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago