txgen

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const TxIDs = "TxIDs"

TxIDs is the name of the transaction IDs map

Variables

View Source
var (

	// ExamplesPath is the path to the generated examples
	ExamplesPath string

	// TransactionPath is the path to the transaction definition file
	TransactionPath string

	// ConstructorsTemplatePath is the path to the Constructors template
	ConstructorsTemplatePath string
	// ConstructorsOutputPath is the path to the Constructors output file
	ConstructorsOutputPath string
	// JSONLiteralsTemplatePath is the path to the JSON literals template
	JSONLiteralsTemplatePath string
	// JSONLiteralsOutputPath is the path to the JSON literals output file
	JSONLiteralsOutputPath string
	// JSTestTemplatePath is the path to the JS test template
	JSTestTemplatePath string
	// JSTestOutputPath is the path to the JS test output file
	JSTestOutputPath string
	// MaketestsTemplatePath is the path to the template which makes the binary which makes the tests
	MaketestsTemplatePath string
	// MaketestsOutputPath is the path to the Maketests output file
	MaketestsOutputPath string
	// SignableBytesTemplatePath is the path to the SignableBytes template
	SignableBytesTemplatePath string
	// SignableBytesOutputPath is the path to the SignableBytes output file
	SignableBytesOutputPath string
	// SignableBytesTestTemplatePath is the path to the SignableBytes tests template
	SignableBytesTestTemplatePath string
	// SignableBytesTestOutputPath is the path to the SignableBytes tests output file
	SignableBytesTestOutputPath string
)

Functions

func ApplyTemplate

func ApplyTemplate(t *template.Template, c *Context, output string) error

ApplyTemplate applies the template to the transaction

func GetTxNames

func GetTxNames(n ast.Node) ([]string, error)

GetTxNames gets the names of the transactions from the TxIDs map

func ParseTemplate

func ParseTemplate(path string) (*template.Template, error)

ParseTemplate parses the template definition

func ParseTransactions

func ParseTransactions() (*ast.File, error)

ParseTransactions parses the transaction definition file

Types

type Context

type Context struct {
	Transactions []Transaction
}

Context defines all the info the template needs

func MakeContext

func MakeContext() (*Context, error)

MakeContext makes a context object from ndau transactions

func MakeContextWithExamples

func MakeContextWithExamples(examples []metatx.Transactable) (*Context, error)

MakeContextWithExamples makes a context object from ndau transactions

In addition to constructing the AST-based context, when provided with a list of instantiated transactions, it will match them and inject them appropriately into the context. This allows, for example, writing tests which include auto- generated SignableBytes calls

type DefinitionFinder

type DefinitionFinder struct {
	Name           string
	Root           ast.Node
	DefinitionType string
	Definition     ast.Expr
}

DefinitionFinder finds definitions of variables by name within a node

func FindDefinition

func FindDefinition(node ast.Node, name string) *DefinitionFinder

FindDefinition finds the definition of a named variable or constant

The returned struct will be nil if the definition was not found, or a struct locating the definition of the value otherwise

func (*DefinitionFinder) Visit

func (t *DefinitionFinder) Visit(n ast.Node) ast.Visitor

Visit implements ast.Visitor

func (*DefinitionFinder) Write

func (t *DefinitionFinder) Write(w io.Writer) error

type Field

type Field struct {
	Name        string
	Type        string
	Transaction *Transaction

	FallibleLiteral bool
	PointerLiteral  bool

	Length        func(string) string
	Bytes         func(string) string
	FallibleBytes bool
	// contains filtered or unexported fields
}

Field stores metadata about a field

func NewField

func NewField(name, nativeType string, tx *Transaction) Field

NewField creates a new Field struct

func ParseField

func ParseField(f *ast.Field, tx *Transaction) ([]Field, error)

ParseField parses the given node of the AST as if it were a Field

Because an AST field might define multiple logical fields, this may return multiple values

func (*Field) Comment

func (f *Field) Comment() string

Comment returns useful comments about a field.

Mainly intended for []byte

func (*Field) IsSignature

func (f *Field) IsSignature() bool

IsSignature is true if the field is a signature field

func (*Field) IsSlice

func (f *Field) IsSlice() bool

IsSlice is true when the field type is a slice

func (Field) Literal

func (f Field) Literal() string

Literal returns an appropriate literal for this field

If the transaction has an example, the example's value is used. Otherwise, a newly-generated value is used.

func (*Field) LiteralName

func (f *Field) LiteralName() string

LiteralName returns an appropriate literal name for an instance of this field

type Transaction

type Transaction struct {
	Name    string
	Fields  []Field
	Example metatx.Transactable
}

Transaction stores metadata about a transaction

func ParseTransaction

func ParseTransaction(name string, node ast.Node, examplesMap map[string]metatx.Transactable) (out Transaction, err error)

ParseTransaction parses the given node of the AST as if it were a Transaction

func (Transaction) HasField

func (t Transaction) HasField(name string) bool

HasField is true if the transaction has a field with the specified name

func (Transaction) JSON

func (t Transaction) JSON() string

JSON returns the JSON form of this transaction's example

func (Transaction) Multisig

func (t Transaction) Multisig() bool

Multisig is true if this transaction supports multiple signatures

Jump to

Keyboard shortcuts

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