Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/gochain/web3
Browse files Browse the repository at this point in the history
  • Loading branch information
treeder committed Jul 29, 2020
2 parents 899dd76 + 4bff642 commit 71b3bc9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 8 additions & 3 deletions cmd/web3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,14 @@ func main() {
Name: "output, o",
Usage: "Output directory.",
},
cli.StringFlag{
Name: "evm-version",
Usage: "Solidity EVM version",
Value: "petersburg",
},
},
Action: func(c *cli.Context) {
BuildSol(ctx, c.Args().First(), c.String("compiler"), c.String("output"))
BuildSol(ctx, c.Args().First(), c.String("compiler"), c.String("evm-version"), c.String("output"))
},
},
{
Expand Down Expand Up @@ -1364,7 +1369,7 @@ func GetID(ctx context.Context, rpcURL string) {
}

// BuildSol builds a contract. Generated files will be under output, or the current directory.
func BuildSol(ctx context.Context, filename, compiler, output string) {
func BuildSol(ctx context.Context, filename, compiler, evmVersion, output string) {
if filename == "" {
fatalExit(errors.New("Missing file name arg"))
}
Expand All @@ -1390,7 +1395,7 @@ func BuildSol(ctx context.Context, filename, compiler, output string) {
if verbose {
log.Println("Building Sol:", str)
}
compileData, err := web3.CompileSolidityString(ctx, str, compiler)
compileData, err := web3.CompileSolidityString(ctx, str, compiler, evmVersion)
if err != nil {
fatalExit(fmt.Errorf("Failed to compile %q: %v", sourceFile, err))
}
Expand Down
8 changes: 5 additions & 3 deletions solc.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ type ContractInfo struct {

// Solidity contains information about the solidity compiler.
type Solidity struct {
Path, Version string
Major, Minor, Patch int
Path, Version, EVMVersion string
Major, Minor, Patch int
}

// --combined-output format
Expand All @@ -66,6 +66,7 @@ func (s *Solidity) makeArgs() ([]string, error) {
"run", "-i", "--rm", "-v", dir + ":/workdir", "-w", "/workdir", "ethereum/solc:" + s.Version,
"--combined-json",
"bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc,metadata",
"--evm-version", s.EVMVersion,
"--optimize", // code optimizer switched on
}, nil
}
Expand All @@ -92,7 +93,7 @@ func SolidityVersion(source string) (*Solidity, error) {
}

// CompileSolidityString builds and returns all the contracts contained within a source string.
func CompileSolidityString(ctx context.Context, source, version string) (map[string]*Contract, error) {
func CompileSolidityString(ctx context.Context, source, version, evmVersion string) (map[string]*Contract, error) {
var s *Solidity
var err error
if len(source) == 0 {
Expand All @@ -107,6 +108,7 @@ func CompileSolidityString(ctx context.Context, source, version string) (map[str
}
}
// fmt.Printf("Building with solidity version %v\n", s.Version)
s.EVMVersion = evmVersion
args, err := s.makeArgs()
if err != nil {
return nil, err
Expand Down

0 comments on commit 71b3bc9

Please sign in to comment.