github.com/Tri-stone/burrow@v0.25.0/deploy/compile/solgo/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"path"
     7  
     8  	"github.com/hyperledger/burrow/deploy/compile"
     9  	"github.com/hyperledger/burrow/logging"
    10  )
    11  
    12  func main() {
    13  	for _, solfile := range os.Args[1:] {
    14  		resp, err := compile.Compile(solfile, false, "", nil, logging.NewNoopLogger())
    15  		if err != nil {
    16  			fmt.Printf("failed compile solidity: %v\n", err)
    17  			os.Exit(1)
    18  		}
    19  
    20  		if resp.Error != "" {
    21  			fmt.Print(resp.Error)
    22  			os.Exit(1)
    23  		}
    24  
    25  		if resp.Warning != "" {
    26  			fmt.Print(resp.Warning)
    27  			os.Exit(1)
    28  		}
    29  
    30  		f, err := os.Create(solfile + ".go")
    31  		if err != nil {
    32  			fmt.Printf("failed to create go file: %v\n", err)
    33  			os.Exit(1)
    34  		}
    35  
    36  		f.WriteString(fmt.Sprintf("package %s\n\n", path.Base(path.Dir(solfile))))
    37  		f.WriteString("import hex \"github.com/tmthrgd/go-hex\"\n\n")
    38  
    39  		for _, c := range resp.Objects {
    40  			f.WriteString(fmt.Sprintf("var Bytecode_%s = hex.MustDecodeString(\"%s\")\n",
    41  				c.Objectname, c.Contract.Evm.Bytecode.Object))
    42  			f.WriteString(fmt.Sprintf("var Abi_%s = []byte(`%s`)\n",
    43  				c.Objectname, c.Contract.Abi))
    44  		}
    45  	}
    46  }