generator

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

The code generator for the plugin for the Google protocol buffer compiler. It generates Solidity code from the protocol buffer description files read by the main routine.

Index

Constants

View Source
const ExtName = "soltype"

ExtName is the extension name to google.protobuf.FieldOptions its type must be string. Valid string values are keys in SolTypeMap (we don't use enum to avoid having solidity knowledge in chain.proto)

View Source
const ProtoSol = `` /* 6117-byte string literal not displayed */

ProtoSol is the full proto library, appended in the end of generated .sol file

View Source
const SolVer = "^0.5.0;"

SolVer is the compatible solidity/solc version in pragma solidity

View Source
const WireLendel = "Bytes"
View Source
const WireVarint = "Varint"

string const for proto wire types

Variables

View Source
var PassTypeMap = map[string]string{

	"uint32": WireVarint,
	"uint64": WireVarint,
	"bool":   WireVarint,
	"bytes":  WireLendel,
	"string": WireLendel,
}

PassTypeMap is a map of proto types with native solidity support (aka. same type keyword in proto and solidity) to its wire type. keys are values from pbType2Str map below. currently we only support 2 wire types: varint and length-delimited.

View Source
var SolTypeMap = map[string]string{
	"uint8":           "uint32",
	"address":         "bytes",
	"address payable": "bytes",
	"bytes32":         "bytes",
	"uint256":         "bytes",
	"uint":            "uint64",
}

SolTypeMap is a map of solidity types as valid soltype option value to required proto primitive type. eg. a field can have (soltype) = "address payable", it must be defined as proto bytes

Functions

func Error

func Error(err error, msgs ...string)

Error reports a problem, including an error, and exits the program.

func Fail

func Fail(msgs ...string)

Fail reports a problem and exits the program.

Types

type Generator

type Generator struct {
	*bytes.Buffer                               // cache .P() output
	Request       *plugin.CodeGeneratorRequest  // The input.
	Response      *plugin.CodeGeneratorResponse // The output.
	// contains filtered or unexported fields
}

Generator is the type whose methods generate the output, stored in the associated response structure.

func New

func New() *Generator

New creates a new generator and allocates the request and response protobufs.

func (*Generator) GenerateAllFiles

func (g *Generator) GenerateAllFiles()

GenerateAllFiles generates the output for all the files we're outputting.

func (*Generator) In

func (g *Generator) In()

In indents the output 4 spaces stop. per solidity style guide

func (*Generator) Out

func (g *Generator) Out()

Out unindents the output 4 spaces stop.

func (*Generator) P

func (g *Generator) P(str ...interface{})

func (*Generator) ParseParams

func (g *Generator) ParseParams()

func (*Generator) Preprocess

func (g *Generator) Preprocess()

When we want to support multiple .proto and imports, need preprocess to get all definition relationships

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL