GithubHelp home page GithubHelp logo

sambacha / solidity-protoc Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 530 KB

fork of pb3-gen-sol

License: GNU General Public License v3.0

Go 38.63% Shell 2.00% Solidity 33.74% JavaScript 25.41% PureBasic 0.21%
protobufs solidity ethereum

solidity-protoc's Introduction

pb3-gen-sol

go

pb3-gen-sol is a proto3 to solidity library generator that supports proto3 native types and uses field option for solidity native types. Both the message and generated code are more efficient than other solutions. It also includes a library to decode protobuf wireformat. Currently it generates decoders, with encoder support planned.

Install

Install Prereqs.

./scripts/setup.sh

Build

./scripts/install.sh

Usage

.proto files

Example:

syntax = "proto3";
// package name is used for both generated .sol file name and library
name
package mytest;

import "google/protobuf/descriptor.proto";
extend google.protobuf.FieldOptions {
    string soltype = 54321;  // must > 1001 and not conflict with other
extensions
}

message MyMsg {
    bytes addr = 1 [ (soltype) = "address" ];
    uint32 num = 2 [ (soltype) = "uint8" ];
    bool has_moon = 3;  // for matching native types, no need for
soltype option
}

Check .proto files under test folder for more examples.

Generate solidity library

Run

$ go build -o protoc-gen-sol
$ export PATH=$PWD:$PATH
$ protoc --sol_out=. [list of proto files]

proto files can have different package names, and generated .sol file name is proto package name.

Params

  • msg: only generate solidity struct and decode functions for msg name. Multiple can be specified.
  • importpb: default false, if set to true, generated .sol file will import pb.sol instead of embed library pb in the file

Example:

--sol_out=msg=Msg1,msg=Msg2,msg=Msg3,importpb=true:test/solidity/contracts/lib/
test/test.proto

solidity-protoc's People

Contributors

dependabot[bot] avatar i9 avatar stevenlcf avatar xiaozhou avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.