-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtypes.go
151 lines (128 loc) · 4.38 KB
/
types.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package solc
import (
"encoding/hex"
"encoding/json"
"fmt"
"strings"
)
// Contract represents a compiled contract.
type Contract struct {
Runtime []byte // The runtime bytecode of the contract.
Constructor []byte // The constructor bytecode of the contract.
Code []byte // Deprecated: The bytecode of the contract after deployment.
DeployCode []byte // Deprecated: The bytecode to deploy the contract.
}
// lang represents the language of the source code.
type lang string
const (
langSolidity lang = "Solidity"
langYul lang = "Yul"
)
// EVMVersion represents the EVM version to compile for.
type EVMVersion string
const (
EVMVersionPrague EVMVersion = "prague"
EVMVersionCancun EVMVersion = "cancun"
EVMVersionShanghai EVMVersion = "shanghai"
EVMVersionParis EVMVersion = "paris"
EVMVersionLondon EVMVersion = "london"
EVMVersionBerlin EVMVersion = "berlin"
EVMVersionIstanbul EVMVersion = "istanbul"
EVMVersionPetersburg EVMVersion = "petersburg"
EVMVersionByzantium EVMVersion = "byzantium"
)
type input struct {
Lang lang `json:"language"`
Sources map[string]src `json:"sources"`
Settings *Settings `json:"settings"`
}
type src struct {
Keccak256 string `json:"keccak256,omitempty"`
Content string `json:"content,omitempty"`
URLS []string `json:"urls,omitempty"`
}
// Settings for the compilation.
type Settings struct {
lang lang `json:"-"`
Remappings []string `json:"remappings,omitempty"`
Optimizer *Optimizer `json:"optimizer"`
ViaIR bool `json:"viaIR,omitempty"`
EVMVersion EVMVersion `json:"evmVersion"`
OutputSelection map[string]map[string][]string `json:"outputSelection"`
}
type Optimizer struct {
Enabled bool `json:"enabled"`
Runs uint64 `json:"runs"`
}
type output struct {
Errors []error_ `json:"errors"`
Sources map[string]srcOut `json:"sources"`
Contracts map[string]map[string]contract `json:"contracts"`
}
func (o *output) Err() error {
var fmtMsgs []string
for _, err := range o.Errors {
if strings.EqualFold(err.Severity, "error") {
fmtMsgs = append(fmtMsgs, err.FormattedMessage)
}
}
if len(fmtMsgs) == 0 {
return nil
}
return fmt.Errorf("solc: compilation failed\n%s", strings.Join(fmtMsgs, "\n"))
}
type error_ struct {
SourceLocation sourceLocation `json:"sourceLocation"`
Type string `json:"type"`
Component string `json:"component"`
Severity string `json:"severity"`
Message string `json:"message"`
FormattedMessage string `json:"formattedMessage"`
}
type sourceLocation struct {
File string `json:"file"`
Start int `json:"start"`
End int `json:"end"`
}
type srcOut struct {
ID int `json:"id"`
AST json.RawMessage `json:"ast"`
LegacyAST json.RawMessage `json:"legacyAST"`
}
type contract struct {
ABI []json.RawMessage `json:"abi"`
Metadata string `json:"metadata"`
UserDoc json.RawMessage `json:"userdoc"`
DevDoc json.RawMessage `json:"devdoc"`
IR string `json:"ir"`
EVM evm `json:"evm"`
}
type evm struct {
Assembly string `json:"assembly"`
LegacyAssembly json.RawMessage `json:"legacyAssembly"`
Bytecode bytecode `json:"bytecode"`
DeployedBytecode bytecode `json:"deployedBytecode"`
MethodIdentifiers map[string]string `json:"methodIdentifiers"`
GasEstimates map[string]map[string]string `json:"gasEstimates"`
}
type bytecode struct {
Object hexBytes `json:"object"`
Opcodes string `json:"opcodes"`
SourceMap string `json:"sourceMap"`
LinkReferences map[string]map[string][]linkReference `json:"linkReferences"`
}
type linkReference struct {
Start int `json:"start"`
End int `json:"end"`
}
// hexBytes is a byte slice that is unmarshalled from a hexstring.
type hexBytes []byte
func (b *hexBytes) UnmarshalText(text []byte) error {
*b = make([]byte, hex.DecodedLen(len(text)))
_, err := hex.Decode(*b, text)
return err
}
type solcVersion struct {
Path string
Sha256 [32]byte
}