diff --git a/cmd/abigen/main.go b/cmd/abigen/main.go
index 911aada3797c..054cc96e19cd 100644
--- a/cmd/abigen/main.go
+++ b/cmd/abigen/main.go
@@ -17,19 +17,15 @@
package main
import (
- "encoding/json"
"fmt"
"io"
"os"
- "path/filepath"
"regexp"
"strings"
- "github.com/ethereum/go-ethereum/accounts/abi"
+ "errors"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/cmd/utils"
- "github.com/ethereum/go-ethereum/common/compiler"
- "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/log"
"gopkg.in/urfave/cli.v1"
@@ -59,24 +55,6 @@ var (
Name: "combined-json",
Usage: "Path to the combined-json file generated by compiler",
}
- solFlag = cli.StringFlag{
- Name: "sol",
- Usage: "Path to the Ethereum contract Solidity source to build and bind",
- }
- solcFlag = cli.StringFlag{
- Name: "solc",
- Usage: "Solidity compiler to use if source builds are requested",
- Value: "solc",
- }
- vyFlag = cli.StringFlag{
- Name: "vy",
- Usage: "Path to the Ethereum contract Vyper source to build and bind",
- }
- vyperFlag = cli.StringFlag{
- Name: "vyper",
- Usage: "Vyper compiler to use if source builds are requested",
- Value: "vyper",
- }
excFlag = cli.StringFlag{
Name: "exc",
Usage: "Comma separated types to exclude from binding",
@@ -107,10 +85,6 @@ func init() {
binFlag,
typeFlag,
jsonFlag,
- solFlag,
- solcFlag,
- vyFlag,
- vyperFlag,
excFlag,
pkgFlag,
outFlag,
@@ -122,10 +96,13 @@ func init() {
}
func abigen(c *cli.Context) error {
- utils.CheckExclusive(c, abiFlag, jsonFlag, solFlag, vyFlag) // Only one source can be selected.
+ utils.CheckExclusive(c, abiFlag, jsonFlag) // Only one source can be selected.
if c.GlobalString(pkgFlag.Name) == "" {
utils.Fatalf("No destination package specified (--pkg)")
}
+ if c.GlobalString(abiFlag.Name) == "" {
+ return errors.New("abi flag must be specified")
+ }
var lang bind.Lang
switch c.GlobalString(langFlag.Name) {
case "go":
@@ -146,101 +123,37 @@ func abigen(c *cli.Context) error {
sigs []map[string]string
libs = make(map[string]string)
aliases = make(map[string]string)
+ abi []byte
+ err error
)
- if c.GlobalString(abiFlag.Name) != "" {
- // Load up the ABI, optional bytecode and type name from the parameters
- var (
- abi []byte
- err error
- )
- input := c.GlobalString(abiFlag.Name)
- if input == "-" {
- abi, err = io.ReadAll(os.Stdin)
- } else {
- abi, err = os.ReadFile(input)
- }
- if err != nil {
- utils.Fatalf("Failed to read input ABI: %v", err)
- }
- abis = append(abis, string(abi))
-
- var bin []byte
- if binFile := c.GlobalString(binFlag.Name); binFile != "" {
- if bin, err = os.ReadFile(binFile); err != nil {
- utils.Fatalf("Failed to read input bytecode: %v", err)
- }
- if strings.Contains(string(bin), "//") {
- utils.Fatalf("Contract has additional library references, please use other mode(e.g. --combined-json) to catch library infos")
- }
- }
- bins = append(bins, string(bin))
-
- kind := c.GlobalString(typeFlag.Name)
- if kind == "" {
- kind = c.GlobalString(pkgFlag.Name)
- }
- types = append(types, kind)
+ // Load up the ABI, optional bytecode and type name from the parameters
+ if input := c.GlobalString(abiFlag.Name); input == "-" {
+ abi, err = io.ReadAll(os.Stdin)
} else {
- // Generate the list of types to exclude from binding
- exclude := make(map[string]bool)
- for _, kind := range strings.Split(c.GlobalString(excFlag.Name), ",") {
- exclude[strings.ToLower(kind)] = true
- }
- var err error
- var contracts map[string]*compiler.Contract
-
- switch {
- case c.GlobalIsSet(solFlag.Name):
- contracts, err = compiler.CompileSolidity(c.GlobalString(solcFlag.Name), c.GlobalString(solFlag.Name))
- if err != nil {
- utils.Fatalf("Failed to build Solidity contract: %v", err)
- }
- case c.GlobalIsSet(vyFlag.Name):
- output, err := compiler.CompileVyper(c.GlobalString(vyperFlag.Name), c.GlobalString(vyFlag.Name))
- if err != nil {
- utils.Fatalf("Failed to build Vyper contract: %v", err)
- }
- contracts = make(map[string]*compiler.Contract)
- for n, contract := range output {
- name := n
- // Sanitize the combined json names to match the
- // format expected by solidity.
- if !strings.Contains(n, ":") {
- // Remove extra path components
- name = abi.ToCamelCase(strings.TrimSuffix(filepath.Base(name), ".vy"))
- }
- contracts[name] = contract
- }
+ abi, err = os.ReadFile(input)
+ }
+ if err != nil {
+ utils.Fatalf("Failed to read input ABI: %v", err)
+ }
+ abis = append(abis, string(abi))
- case c.GlobalIsSet(jsonFlag.Name):
- jsonOutput, err := os.ReadFile(c.GlobalString(jsonFlag.Name))
- if err != nil {
- utils.Fatalf("Failed to read combined-json from compiler: %v", err)
- }
- contracts, err = compiler.ParseCombinedJSON(jsonOutput, "", "", "", "")
- if err != nil {
- utils.Fatalf("Failed to read contract information from json output: %v", err)
- }
+ var bin []byte
+ if binFile := c.GlobalString(binFlag.Name); binFile != "" {
+ if bin, err = os.ReadFile(binFile); err != nil {
+ utils.Fatalf("Failed to read input bytecode: %v", err)
}
- // Gather all non-excluded contract for binding
- for name, contract := range contracts {
- if exclude[strings.ToLower(name)] {
- continue
- }
- abi, err := json.Marshal(contract.Info.AbiDefinition) // Flatten the compiler parse
- if err != nil {
- utils.Fatalf("Failed to parse ABIs from compiler output: %v", err)
- }
- abis = append(abis, string(abi))
- bins = append(bins, contract.Code)
- sigs = append(sigs, contract.Hashes)
- nameParts := strings.Split(name, ":")
- types = append(types, nameParts[len(nameParts)-1])
-
- libPattern := crypto.Keccak256Hash([]byte(name)).String()[2:36]
- libs[libPattern] = nameParts[len(nameParts)-1]
+ if strings.Contains(string(bin), "//") {
+ utils.Fatalf("Contract has additional library references, please use other mode(e.g. --combined-json) to catch library infos")
}
}
+ bins = append(bins, string(bin))
+
+ kind := c.GlobalString(typeFlag.Name)
+ if kind == "" {
+ kind = c.GlobalString(pkgFlag.Name)
+ }
+ types = append(types, kind)
+
// Extract all aliases from the flags
if c.GlobalIsSet(aliasFlag.Name) {
// We support multi-versions for aliasing
diff --git a/common/compiler/helpers.go b/common/compiler/helpers.go
deleted file mode 100644
index 59d242af3df6..000000000000
--- a/common/compiler/helpers.go
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2019 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-// Package compiler wraps the Solidity and Vyper compiler executables (solc; vyper).
-package compiler
-
-import (
- "bytes"
- "os"
- "regexp"
-)
-
-var versionRegexp = regexp.MustCompile(`([0-9]+)\.([0-9]+)\.([0-9]+)`)
-
-// Contract contains information about a compiled contract, alongside its code and runtime code.
-type Contract struct {
- Code string `json:"code"`
- RuntimeCode string `json:"runtime-code"`
- Info ContractInfo `json:"info"`
- Hashes map[string]string `json:"hashes"`
-}
-
-// ContractInfo contains information about a compiled contract, including access
-// to the ABI definition, source mapping, user and developer docs, and metadata.
-//
-// Depending on the source, language version, compiler version, and compiler
-// options will provide information about how the contract was compiled.
-type ContractInfo struct {
- Source string `json:"source"`
- Language string `json:"language"`
- LanguageVersion string `json:"languageVersion"`
- CompilerVersion string `json:"compilerVersion"`
- CompilerOptions string `json:"compilerOptions"`
- SrcMap interface{} `json:"srcMap"`
- SrcMapRuntime string `json:"srcMapRuntime"`
- AbiDefinition interface{} `json:"abiDefinition"`
- UserDoc interface{} `json:"userDoc"`
- DeveloperDoc interface{} `json:"developerDoc"`
- Metadata string `json:"metadata"`
-}
-
-func slurpFiles(files []string) (string, error) {
- var concat bytes.Buffer
- for _, file := range files {
- content, err := os.ReadFile(file)
- if err != nil {
- return "", err
- }
- concat.Write(content)
- }
- return concat.String(), nil
-}
diff --git a/common/compiler/solidity.go b/common/compiler/solidity.go
deleted file mode 100644
index ffda0193c853..000000000000
--- a/common/compiler/solidity.go
+++ /dev/null
@@ -1,244 +0,0 @@
-// Copyright 2015 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-// Package compiler wraps the Solidity and Vyper compiler executables (solc; vyper).
-package compiler
-
-import (
- "bytes"
- "encoding/json"
- "errors"
- "fmt"
- "os/exec"
- "strconv"
- "strings"
-)
-
-// Solidity contains information about the solidity compiler.
-type Solidity struct {
- Path, Version, FullVersion string
- Major, Minor, Patch int
- ExtraAllowedPath []string
-}
-
-// --combined-output format
-type solcOutput struct {
- Contracts map[string]struct {
- BinRuntime string `json:"bin-runtime"`
- SrcMapRuntime string `json:"srcmap-runtime"`
- Bin, SrcMap, Abi, Devdoc, Userdoc, Metadata string
- Hashes map[string]string
- }
- Version string
-}
-
-// solidity v.0.8 changes the way ABI, Devdoc and Userdoc are serialized
-type solcOutputV8 struct {
- Contracts map[string]struct {
- BinRuntime string `json:"bin-runtime"`
- SrcMapRuntime string `json:"srcmap-runtime"`
- Bin, SrcMap, Metadata string
- Abi interface{}
- Devdoc interface{}
- Userdoc interface{}
- Hashes map[string]string
- }
- Version string
-}
-
-func (s *Solidity) allowedPaths() string {
- paths := []string{".", "./", "../"} // default to support relative paths
- if len(s.ExtraAllowedPath) > 0 {
- paths = append(paths, s.ExtraAllowedPath...)
- }
- return strings.Join(paths, ", ")
-}
-
-func (s *Solidity) makeArgs() []string {
- p := []string{
- "--combined-json", "bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc",
- "--optimize", // code optimizer switched on
- "--allow-paths", s.allowedPaths(),
- }
- if s.Major > 0 || s.Minor > 4 || s.Patch > 6 {
- p[1] += ",metadata,hashes"
- }
- return p
-}
-
-// SolidityVersion runs solc and parses its version output.
-func SolidityVersion(solc string) (*Solidity, error) {
- if solc == "" {
- solc = "solc"
- }
- var out bytes.Buffer
- cmd := exec.Command(solc, "--version")
- cmd.Stdout = &out
- err := cmd.Run()
- if err != nil {
- return nil, err
- }
- matches := versionRegexp.FindStringSubmatch(out.String())
- if len(matches) != 4 {
- return nil, fmt.Errorf("can't parse solc version %q", out.String())
- }
- s := &Solidity{Path: cmd.Path, FullVersion: out.String(), Version: matches[0]}
- if s.Major, err = strconv.Atoi(matches[1]); err != nil {
- return nil, err
- }
- if s.Minor, err = strconv.Atoi(matches[2]); err != nil {
- return nil, err
- }
- if s.Patch, err = strconv.Atoi(matches[3]); err != nil {
- return nil, err
- }
- return s, nil
-}
-
-// CompileSolidityString builds and returns all the contracts contained within a source string.
-func CompileSolidityString(solc, source string) (map[string]*Contract, error) {
- if len(source) == 0 {
- return nil, errors.New("solc: empty source string")
- }
- s, err := SolidityVersion(solc)
- if err != nil {
- return nil, err
- }
- return s.CompileSource(source)
-}
-
-// CompileSolidity compiles all given Solidity source files.
-func CompileSolidity(solc string, sourcefiles ...string) (map[string]*Contract, error) {
- if len(sourcefiles) == 0 {
- return nil, errors.New("solc: no source files")
- }
- s, err := SolidityVersion(solc)
- if err != nil {
- return nil, err
- }
-
- return s.CompileFiles(sourcefiles...)
-}
-
-// CompileSource builds and returns all the contracts contained within a source string.
-func (s *Solidity) CompileSource(source string) (map[string]*Contract, error) {
- args := append(s.makeArgs(), "--")
- cmd := exec.Command(s.Path, append(args, "-")...)
- cmd.Stdin = strings.NewReader(source)
- return s.run(cmd, source)
-}
-
-// CompileFiles compiles all given Solidity source files.
-func (s *Solidity) CompileFiles(sourcefiles ...string) (map[string]*Contract, error) {
- source, err := slurpFiles(sourcefiles)
- if err != nil {
- return nil, err
- }
- args := append(s.makeArgs(), "--")
- cmd := exec.Command(s.Path, append(args, sourcefiles...)...)
- return s.run(cmd, source)
-}
-
-func (s *Solidity) run(cmd *exec.Cmd, source string) (map[string]*Contract, error) {
- var stderr, stdout bytes.Buffer
- cmd.Stderr = &stderr
- cmd.Stdout = &stdout
- if err := cmd.Run(); err != nil {
- return nil, fmt.Errorf("solc: %v\n%s", err, stderr.Bytes())
- }
- return ParseCombinedJSON(stdout.Bytes(), source, s.Version, s.Version, strings.Join(s.makeArgs(), " "))
-}
-
-// ParseCombinedJSON takes the direct output of a solc --combined-output run and
-// parses it into a map of string contract name to Contract structs. The
-// provided source, language and compiler version, and compiler options are all
-// passed through into the Contract structs.
-//
-// The solc output is expected to contain ABI, source mapping, user docs, and dev docs.
-//
-// Returns an error if the JSON is malformed or missing data, or if the JSON
-// embedded within the JSON is malformed.
-func ParseCombinedJSON(combinedJSON []byte, source string, languageVersion string, compilerVersion string, compilerOptions string) (map[string]*Contract, error) {
- var output solcOutput
- if err := json.Unmarshal(combinedJSON, &output); err != nil {
- // Try to parse the output with the new solidity v.0.8.0 rules
- return parseCombinedJSONV8(combinedJSON, source, languageVersion, compilerVersion, compilerOptions)
- }
- // Compilation succeeded, assemble and return the contracts.
- contracts := make(map[string]*Contract)
- for name, info := range output.Contracts {
- // Parse the individual compilation results.
- var abi interface{}
- if err := json.Unmarshal([]byte(info.Abi), &abi); err != nil {
- return nil, fmt.Errorf("solc: error reading abi definition (%v)", err)
- }
- var userdoc, devdoc interface{}
- json.Unmarshal([]byte(info.Userdoc), &userdoc)
- json.Unmarshal([]byte(info.Devdoc), &devdoc)
-
- contracts[name] = &Contract{
- Code: "0x" + info.Bin,
- RuntimeCode: "0x" + info.BinRuntime,
- Hashes: info.Hashes,
- Info: ContractInfo{
- Source: source,
- Language: "Solidity",
- LanguageVersion: languageVersion,
- CompilerVersion: compilerVersion,
- CompilerOptions: compilerOptions,
- SrcMap: info.SrcMap,
- SrcMapRuntime: info.SrcMapRuntime,
- AbiDefinition: abi,
- UserDoc: userdoc,
- DeveloperDoc: devdoc,
- Metadata: info.Metadata,
- },
- }
- }
- return contracts, nil
-}
-
-// parseCombinedJSONV8 parses the direct output of solc --combined-output
-// and parses it using the rules from solidity v.0.8.0 and later.
-func parseCombinedJSONV8(combinedJSON []byte, source string, languageVersion string, compilerVersion string, compilerOptions string) (map[string]*Contract, error) {
- var output solcOutputV8
- if err := json.Unmarshal(combinedJSON, &output); err != nil {
- return nil, err
- }
- // Compilation succeeded, assemble and return the contracts.
- contracts := make(map[string]*Contract)
- for name, info := range output.Contracts {
- contracts[name] = &Contract{
- Code: "0x" + info.Bin,
- RuntimeCode: "0x" + info.BinRuntime,
- Hashes: info.Hashes,
- Info: ContractInfo{
- Source: source,
- Language: "Solidity",
- LanguageVersion: languageVersion,
- CompilerVersion: compilerVersion,
- CompilerOptions: compilerOptions,
- SrcMap: info.SrcMap,
- SrcMapRuntime: info.SrcMapRuntime,
- AbiDefinition: info.Abi,
- UserDoc: info.Userdoc,
- DeveloperDoc: info.Devdoc,
- Metadata: info.Metadata,
- },
- }
- }
- return contracts, nil
-}
diff --git a/common/compiler/solidity_test.go b/common/compiler/solidity_test.go
deleted file mode 100644
index 491e3665e2c0..000000000000
--- a/common/compiler/solidity_test.go
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2015 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package compiler
-
-import (
- "os/exec"
- "testing"
-)
-
-const (
- testSource = `
-pragma solidity >0.0.0;
-contract test {
- /// @notice Will multiply ` + "`a`" + ` by 7.
- function multiply(uint a) public returns(uint d) {
- return a * 7;
- }
-}
-`
-)
-
-func skipWithoutSolc(t *testing.T) {
- if _, err := exec.LookPath("solc"); err != nil {
- t.Skip(err)
- }
-}
-
-func TestSolidityCompiler(t *testing.T) {
- skipWithoutSolc(t)
-
- contracts, err := CompileSolidityString("", testSource)
- if err != nil {
- t.Fatalf("error compiling source. result %v: %v", contracts, err)
- }
- if len(contracts) != 1 {
- t.Errorf("one contract expected, got %d", len(contracts))
- }
- c, ok := contracts["test"]
- if !ok {
- c, ok = contracts[":test"]
- if !ok {
- t.Fatal("info for contract 'test' not present in result")
- }
- }
- if c.Code == "" {
- t.Error("empty code")
- }
- if c.Info.Source != testSource {
- t.Error("wrong source")
- }
- if c.Info.CompilerVersion == "" {
- t.Error("empty version")
- }
-}
-
-func TestSolidityCompileError(t *testing.T) {
- skipWithoutSolc(t)
-
- contracts, err := CompileSolidityString("", testSource[4:])
- if err == nil {
- t.Errorf("error expected compiling source. got none. result %v", contracts)
- }
- t.Logf("error: %v", err)
-}
diff --git a/common/compiler/test.v.py b/common/compiler/test.v.py
deleted file mode 100644
index 35af56c8f6ef..000000000000
--- a/common/compiler/test.v.py
+++ /dev/null
@@ -1,3 +0,0 @@
-@public
-def test():
- hello: int128
diff --git a/common/compiler/test_bad.v.py b/common/compiler/test_bad.v.py
deleted file mode 100644
index 443ef7826325..000000000000
--- a/common/compiler/test_bad.v.py
+++ /dev/null
@@ -1,3 +0,0 @@
-lic
-def test():
- hello: int128
diff --git a/common/compiler/vyper.go b/common/compiler/vyper.go
deleted file mode 100644
index a9bca95e5901..000000000000
--- a/common/compiler/vyper.go
+++ /dev/null
@@ -1,144 +0,0 @@
-// Copyright 2019 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-// Package compiler wraps the Solidity and Vyper compiler executables (solc; vyper).
-package compiler
-
-import (
- "bytes"
- "encoding/json"
- "errors"
- "fmt"
- "os/exec"
- "strconv"
- "strings"
-)
-
-// Vyper contains information about the vyper compiler.
-type Vyper struct {
- Path, Version, FullVersion string
- Major, Minor, Patch int
-}
-
-func (s *Vyper) makeArgs() []string {
- p := []string{
- "-f", "combined_json",
- }
- return p
-}
-
-// VyperVersion runs vyper and parses its version output.
-func VyperVersion(vyper string) (*Vyper, error) {
- if vyper == "" {
- vyper = "vyper"
- }
- var out bytes.Buffer
- cmd := exec.Command(vyper, "--version")
- cmd.Stdout = &out
- err := cmd.Run()
- if err != nil {
- return nil, err
- }
- matches := versionRegexp.FindStringSubmatch(out.String())
- if len(matches) != 4 {
- return nil, fmt.Errorf("can't parse vyper version %q", out.String())
- }
- s := &Vyper{Path: cmd.Path, FullVersion: out.String(), Version: matches[0]}
- if s.Major, err = strconv.Atoi(matches[1]); err != nil {
- return nil, err
- }
- if s.Minor, err = strconv.Atoi(matches[2]); err != nil {
- return nil, err
- }
- if s.Patch, err = strconv.Atoi(matches[3]); err != nil {
- return nil, err
- }
- return s, nil
-}
-
-// CompileVyper compiles all given Vyper source files.
-func CompileVyper(vyper string, sourcefiles ...string) (map[string]*Contract, error) {
- if len(sourcefiles) == 0 {
- return nil, errors.New("vyper: no source files")
- }
- source, err := slurpFiles(sourcefiles)
- if err != nil {
- return nil, err
- }
- s, err := VyperVersion(vyper)
- if err != nil {
- return nil, err
- }
- args := s.makeArgs()
- cmd := exec.Command(s.Path, append(args, sourcefiles...)...)
- return s.run(cmd, source)
-}
-
-func (s *Vyper) run(cmd *exec.Cmd, source string) (map[string]*Contract, error) {
- var stderr, stdout bytes.Buffer
- cmd.Stderr = &stderr
- cmd.Stdout = &stdout
- if err := cmd.Run(); err != nil {
- return nil, fmt.Errorf("vyper: %v\n%s", err, stderr.Bytes())
- }
-
- return ParseVyperJSON(stdout.Bytes(), source, s.Version, s.Version, strings.Join(s.makeArgs(), " "))
-}
-
-// ParseVyperJSON takes the direct output of a vyper --f combined_json run and
-// parses it into a map of string contract name to Contract structs. The
-// provided source, language and compiler version, and compiler options are all
-// passed through into the Contract structs.
-//
-// The vyper output is expected to contain ABI and source mapping.
-//
-// Returns an error if the JSON is malformed or missing data, or if the JSON
-// embedded within the JSON is malformed.
-func ParseVyperJSON(combinedJSON []byte, source string, languageVersion string, compilerVersion string, compilerOptions string) (map[string]*Contract, error) {
- var output map[string]interface{}
- if err := json.Unmarshal(combinedJSON, &output); err != nil {
- return nil, err
- }
-
- // Compilation succeeded, assemble and return the contracts.
- contracts := make(map[string]*Contract)
- for name, info := range output {
- // Parse the individual compilation results.
- if name == "version" {
- continue
- }
- c := info.(map[string]interface{})
-
- contracts[name] = &Contract{
- Code: c["bytecode"].(string),
- RuntimeCode: c["bytecode_runtime"].(string),
- Info: ContractInfo{
- Source: source,
- Language: "Vyper",
- LanguageVersion: languageVersion,
- CompilerVersion: compilerVersion,
- CompilerOptions: compilerOptions,
- SrcMap: c["source_map"],
- SrcMapRuntime: "",
- AbiDefinition: c["abi"],
- UserDoc: "",
- DeveloperDoc: "",
- Metadata: "",
- },
- }
- }
- return contracts, nil
-}
diff --git a/common/compiler/vyper_test.go b/common/compiler/vyper_test.go
deleted file mode 100644
index 7761c92affc5..000000000000
--- a/common/compiler/vyper_test.go
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright 2019 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see .
-
-package compiler
-
-import (
- "os/exec"
- "testing"
-)
-
-func skipWithoutVyper(t *testing.T) {
- if _, err := exec.LookPath("vyper"); err != nil {
- t.Skip(err)
- }
-}
-
-func TestVyperCompiler(t *testing.T) {
- skipWithoutVyper(t)
-
- testSource := []string{"test.v.py"}
- source, err := slurpFiles(testSource)
- if err != nil {
- t.Error("couldn't read test files")
- }
- contracts, err := CompileVyper("", testSource...)
- if err != nil {
- t.Fatalf("error compiling test.v.py. result %v: %v", contracts, err)
- }
- if len(contracts) != 1 {
- t.Errorf("one contract expected, got %d", len(contracts))
- }
- c, ok := contracts["test.v.py"]
- if !ok {
- c, ok = contracts[":test"]
- if !ok {
- t.Fatal("info for contract 'test.v.py' not present in result")
- }
- }
- if c.Code == "" {
- t.Error("empty code")
- }
- if c.Info.Source != source {
- t.Error("wrong source")
- }
- if c.Info.CompilerVersion == "" {
- t.Error("empty version")
- }
-}
-
-func TestVyperCompileError(t *testing.T) {
- skipWithoutVyper(t)
-
- contracts, err := CompileVyper("", "test_bad.v.py")
- if err == nil {
- t.Errorf("error expected compiling test_bad.v.py. got none. result %v", contracts)
- }
- t.Logf("error: %v", err)
-}