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