gosolc

package module
v0.0.0-...-122ffec Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2023 License: MPL-2.0 Imports: 15 Imported by: 0

README

Go-solc

Solidity bindings for Golang.

Usage

Declare a project:

p, err := gosolc.NewProject(gosolc.WithContractsDir("."))
if err != nil {
    // handle err
}
p.Compile()

CLI

$ go run cmd/gosolc/main.go [--contracts . --artifacts .]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compile

func Compile(path string, input *solcInput) (*solcOutput, error)

Types

type Artifact

type Artifact struct {
	Abi json.RawMessage `json:"abi"`

	EVM struct {
		Bytecode          *Bytecode         `json:"bytecode"`
		DeployedBytecode  *Bytecode         `json:"deployedBytecode"`
		Opcodes           string            `json:"opcodes"`
		SourceMap         string            `json:"sourceMap"`
		MethodIdentifiers map[string]string `json:"methodIdentifiers"`
	} `json:"evm"`

	Metadata string `json:"metadata"`
}

type Bytecode

type Bytecode struct {
	Object         string          `json:"object"`
	SrcMap         string          `json:"sourceMap"`
	LinkReferences json.RawMessage `json:"linkReferences"`
}

type CompilationResult

type CompilationResult struct {
	// Contracts is the list of contracts compiled
	Contracts []string

	// Runs is the list of independent compilation components
	Runs []*CompilationRun
}

type CompilationRun

type CompilationRun struct {
	// Paths of the Solidity contracts for this run
	Components []string

	// ExecutionTime is the time it took this component to compile
	ExecutionTime time.Duration
}

type Config

type Config struct {
	ContractsDir    string
	ArtifactsDir    string
	SolidityVersion string
	Runs            uint64
}

Config is the Project configuration

func DefaultConfig

func DefaultConfig() *Config

type Contract

type Contract struct {
	// Name is the name of the contract
	Name string

	Source string

	// Abi is the abi encoding of the contract
	Abi json.RawMessage

	Bytecode *Bytecode

	DeployedBytecode *Bytecode

	Metadata string

	MethodIdentifiers map[string]string
}

type FileDiff

type FileDiff struct {
	// Path of the file being updated
	Path string

	// Type of the file update
	Type FileDiffType

	// Time of modification for the file
	Mod time.Time

	// Content is the content of the file
	Content []byte
}

FileDiff describes a file update

type FileDiffType

type FileDiffType string
const (
	FileDiffAdd FileDiffType = "add"
	FileDiffDel FileDiffType = "del"
	FileDiffMod FileDiffType = "mod"
)

type Optimizer

type Optimizer struct {
	Enabled bool
	Runs    int
}

type Option

type Option func(*Config)

func WithArtifactsDir

func WithArtifactsDir(artifactsDir string) Option

func WithContractsDir

func WithContractsDir(contractsDir string) Option

func WithRuns

func WithRuns(runs uint64) Option

func WithSolidityVersion

func WithSolidityVersion(version string) Option

type Project

type Project struct {
	// contains filtered or unexported fields
}

func NewProject

func NewProject(opts ...Option) (*Project, error)

func (*Project) Compile

func (p *Project) Compile() (*CompilationResult, error)

Compile compiles the application

func (*Project) ListContracts

func (p *Project) ListContracts() ([]*Contract, error)

func (*Project) ListSources

func (p *Project) ListSources() ([]*Source, error)

func (*Project) UpsertContract

func (p *Project) UpsertContract(c *Contract) error

func (*Project) UpsertSource

func (p *Project) UpsertSource(src *Source) error

type Source

type Source struct {
	// Dir is the directory of the file
	Dir string

	// Filename is the name of the file
	Filename string

	// ModTime is the modified time of the source
	ModTime time.Time

	// Versions are the required version for this source
	Version []string

	// Imports is the list of imports defined in this source
	Imports []string

	AST json.RawMessage
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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