-
Notifications
You must be signed in to change notification settings - Fork 2
/
solc.go
59 lines (50 loc) · 1.14 KB
/
solc.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
47
48
49
50
51
52
53
54
55
56
57
58
59
package solc
import (
"bytes"
"encoding/json"
"fmt"
"os/exec"
"github.com/spf13/viper"
)
type CombinedJSON struct {
Contracts map[string]runtimeArtifacts
SourceList []string
Sources map[string]topASTNode
}
type runtimeArtifacts struct {
SrcmapRuntime string `json:"srcmap-runtime"`
BinRuntime string `json:"bin-runtime"`
}
type topASTNode struct {
AST JSONAST
}
type JSONAST struct {
ID uint
Src string
Children []*JSONAST
// name string
// attributes, which is a rich collection of information we're not using
}
func GetCombinedJSON(artifactList string, contracts []string) (CombinedJSON, error) {
var outputJSON CombinedJSON
solcArgs := append(
append(
viper.GetStringSlice("solc_args"),
"--combined-json="+artifactList,
),
contracts...,
)
cmd := exec.Command("solc", solcArgs...)
cmd.Dir = viper.GetString("contracts_dir")
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
err := cmd.Run()
if err != nil {
fmt.Println(fmt.Sprint(err) + ": " + stderr.String())
return CombinedJSON{}, err
}
err = json.Unmarshal(out.Bytes(), &outputJSON)
return outputJSON, err
}