solc

package module
v0.0.0-...-48a507a Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: MIT Imports: 8 Imported by: 0

README

Solc-Go

Golang bindings for the Solidity compiler

Example usage

go get github.com/Notation/solc-go

Example:

package main

import (
	"fmt"
	"os"

	"github.com/pkg/errors"
	"github.com/Notation/solc-go"
)

func main() {
	var (
		version    = "0.4.25"
		file       = "./testdata/0.4.25.sol"
		solcBinary = "./solc_bin/soljson-v0.4.25+commit.59dbf8f1.js"
	)
	compiler, err := solc.NewFromFile(solcBinary, version)
	if err != nil {
		panic(errors.Wrap(err, "NewFromFile"))
	}
	fileData, err := os.ReadFile(file)
	if err != nil {
		panic(errors.Wrap(err, "ReadFile"))
	}

	input := &solc.Input{
		Language: "Solidity",
		Sources: map[string]solc.SourceIn{
			file: {Content: string(fileData)},
		},
		Settings: solc.Settings{
			Optimizer: solc.Optimizer{
				Enabled: false,
			},
			OutputSelection: map[string]map[string][]string{
				"*": {
					"*": []string{
						"metadata",
						"evm.bytecode",
						"evm.deployedBytecode",
						"evm.methodIdentifiers",
					},
					"": []string{
						"ast",
					},
				},
			},
		},
	}
	out, err := compiler.Compile(input)
	if err != nil {
		panic(errors.Wrap(err, "Compile"))
	}

	fmt.Println(out)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bytecode

type Bytecode struct {
	Object         string                                `json:"object,omitempty"`
	Opcodes        string                                `json:"opcodes,omitempty"`
	SourceMap      string                                `json:"sourceMap,omitempty"`
	LinkReferences map[string]map[string][]LinkReference `json:"linkReferences,omitempty"`
}

type Compiler

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

func NewFromFile

func NewFromFile(file, ver string) (*Compiler, error)

func (*Compiler) Close

func (c *Compiler) Close()

func (*Compiler) Compile

func (c *Compiler) Compile(input *Input) (*Output, error)

type Contract

type Contract struct {
	ABI      []json.RawMessage `json:"abi,omitempty"`
	Metadata string            `json:"metadata,omitempty"`
	UserDoc  json.RawMessage   `json:"userdoc,omitempty"`
	DevDoc   json.RawMessage   `json:"devdoc,omitempty"`
	IR       string            `json:"ir,omitempty"`
	// StorageLayout StorageLayout     `json:"storageLayout,omitempty"`
	EVM   EVM   `json:"evm,omitempty"`
	EWASM EWASM `json:"ewasm,omitempty"`
}

type EVM

type EVM struct {
	Assembly          string                       `json:"assembly,omitempty"`
	LegacyAssembly    json.RawMessage              `json:"legacyAssembly,omitempty"`
	Bytecode          Bytecode                     `json:"bytecode,omitempty"`
	DeployedBytecode  Bytecode                     `json:"deployedBytecode,omitempty"`
	MethodIdentifiers map[string]string            `json:"methodIdentifiers,omitempty"`
	GasEstimates      map[string]map[string]string `json:"gasEstimates,omitempty"`
}

type EWASM

type EWASM struct {
	Wast string `json:"wast,omitempty"`
	Wasm string `json:"wasm,omitempty"`
}

type Error

type Error struct {
	SourceLocation   SourceLocation `json:"sourceLocation,omitempty"`
	Type             string         `json:"type,omitempty"`
	Component        string         `json:"component,omitempty"`
	Severity         string         `json:"severity,omitempty"`
	Message          string         `json:"message,omitempty"`
	FormattedMessage string         `json:"formattedMessage,omitempty"`
}

type Input

type Input struct {
	Language string              `json:"language,omitempty"`
	Sources  map[string]SourceIn `json:"sources,omitempty"`
	Settings Settings            `json:"settings,omitempty"`
}

type LinkReference

type LinkReference struct {
	Start int `json:"start,omitempty"`
	End   int `json:"end,omitempty"`
}

type Optimizer

type Optimizer struct {
	Enabled bool `json:"enabled,omitempty"`
	Runs    int  `json:"runs,omitempty"`
}

type Output

type Output struct {
	Errors    []Error                        `json:"errors,omitempty"`
	Sources   map[string]SourceOut           `json:"sources,omitempty"`
	Contracts map[string]map[string]Contract `json:"contracts,omitempty"`
}

type Settings

type Settings struct {
	Remappings      []string                       `json:"remappings,omitempty"`
	Optimizer       Optimizer                      `json:"optimizer,omitempty"`
	EVMVersion      string                         `json:"evmVersion,omitempty"`
	OutputSelection map[string]map[string][]string `json:"outputSelection,omitempty"`
}

type SourceIn

type SourceIn struct {
	Keccak256 string `json:"keccak256,omitempty"`
	Content   string `json:"content,omitempty"`
}

type SourceLocation

type SourceLocation struct {
	File  string `json:"file,omitempty"`
	Start int    `json:"start,omitempty"`
	End   int    `json:"end,omitempty"`
}

type SourceOut

type SourceOut struct {
	ID        int             `json:"id,omitempty"`
	AST       json.RawMessage `json:"ast,omitempty"`
	LegacyAST json.RawMessage `json:"legacyAST,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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