-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstandard_json.go
More file actions
83 lines (68 loc) · 1.98 KB
/
standard_json.go
File metadata and controls
83 lines (68 loc) · 1.98 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"encoding/json"
"io/ioutil"
"os"
"strings"
"github.com/ethereum/go-ethereum/crypto"
"github.com/pkg/errors"
)
func collectPathsToStandardJSON(
paths []string,
optimizer bool,
optimizerRuns int,
evmVersion EVMVersion,
) ([]byte, error) {
cwd, err := os.Getwd()
if err != nil {
err = errors.Wrap(err, "unable to get current workdir")
return nil, err
}
result := StandardJSONInput{
Language: "Solidity",
Sources: make(map[string]ContractContent, len(paths)),
}
result.Settings.Remappings = make([]string, 0)
result.Settings.Optimizer.Enabled = optimizer
result.Settings.Optimizer.Runs = optimizerRuns
result.Settings.EvmVersion = evmVersion
for _, srcPath := range paths {
solContent, err := ioutil.ReadFile(srcPath)
if err != nil {
err = errors.Wrapf(err, "failed to collect Solidity file %s", srcPath)
return nil, err
}
srcPath = strings.Replace(srcPath, cwd, ".", 1)
result.Sources[srcPath] = ContractContent{
Keccak256: crypto.Keccak256Hash(solContent).Hex(),
Content: string(solContent),
}
}
return json.MarshalIndent(result, "", "\t")
}
type EVMVersion string
const (
EVMVersionTangerineWhistle EVMVersion = "tangerineWhistle"
EVMVersionSpuriousDragon EVMVersion = "spuriousDragon"
EVMVersionByzantium EVMVersion = "byzantium"
EVMVersionConstantinople EVMVersion = "constantinople"
EVMVersionPetersburg EVMVersion = "petersburg"
EVMVersionIstanbul EVMVersion = "istanbul"
EVMVersionBerlin EVMVersion = "berlin"
)
type ContractContent struct {
Keccak256 string `json:"keccak256"`
Content string `json:"content"`
}
type StandardJSONInput struct {
Language string `json:"language"`
Sources map[string]ContractContent `json:"sources"`
Settings struct {
Remappings []string `json:"remappings"`
Optimizer struct {
Enabled bool `json:"enabled"`
Runs int `json:"runs"`
} `json:"optimizer"`
EvmVersion EVMVersion `json:"evmVersion"`
} `json:"settings"`
}