common/compiler: capture runtime code and source maps (#18020)
This commit is contained in:
parent
a5dc087845
commit
1064e3283d
|
@ -31,14 +31,15 @@ import (
|
||||||
|
|
||||||
var versionRegexp = regexp.MustCompile(`([0-9]+)\.([0-9]+)\.([0-9]+)`)
|
var versionRegexp = regexp.MustCompile(`([0-9]+)\.([0-9]+)\.([0-9]+)`)
|
||||||
|
|
||||||
// Contract contains information about a compiled contract, alongside its code.
|
// Contract contains information about a compiled contract, alongside its code and runtime code.
|
||||||
type Contract struct {
|
type Contract struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
|
RuntimeCode string `json:"runtime-code"`
|
||||||
Info ContractInfo `json:"info"`
|
Info ContractInfo `json:"info"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContractInfo contains information about a compiled contract, including access
|
// ContractInfo contains information about a compiled contract, including access
|
||||||
// to the ABI definition, user and developer docs, and metadata.
|
// to the ABI definition, source mapping, user and developer docs, and metadata.
|
||||||
//
|
//
|
||||||
// Depending on the source, language version, compiler version, and compiler
|
// Depending on the source, language version, compiler version, and compiler
|
||||||
// options will provide information about how the contract was compiled.
|
// options will provide information about how the contract was compiled.
|
||||||
|
@ -48,6 +49,8 @@ type ContractInfo struct {
|
||||||
LanguageVersion string `json:"languageVersion"`
|
LanguageVersion string `json:"languageVersion"`
|
||||||
CompilerVersion string `json:"compilerVersion"`
|
CompilerVersion string `json:"compilerVersion"`
|
||||||
CompilerOptions string `json:"compilerOptions"`
|
CompilerOptions string `json:"compilerOptions"`
|
||||||
|
SrcMap string `json:"srcMap"`
|
||||||
|
SrcMapRuntime string `json:"srcMapRuntime"`
|
||||||
AbiDefinition interface{} `json:"abiDefinition"`
|
AbiDefinition interface{} `json:"abiDefinition"`
|
||||||
UserDoc interface{} `json:"userDoc"`
|
UserDoc interface{} `json:"userDoc"`
|
||||||
DeveloperDoc interface{} `json:"developerDoc"`
|
DeveloperDoc interface{} `json:"developerDoc"`
|
||||||
|
@ -63,14 +66,16 @@ type Solidity struct {
|
||||||
// --combined-output format
|
// --combined-output format
|
||||||
type solcOutput struct {
|
type solcOutput struct {
|
||||||
Contracts map[string]struct {
|
Contracts map[string]struct {
|
||||||
Bin, Abi, Devdoc, Userdoc, Metadata string
|
BinRuntime string `json:"bin-runtime"`
|
||||||
|
SrcMapRuntime string `json:"srcmap-runtime"`
|
||||||
|
Bin, SrcMap, Abi, Devdoc, Userdoc, Metadata string
|
||||||
}
|
}
|
||||||
Version string
|
Version string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Solidity) makeArgs() []string {
|
func (s *Solidity) makeArgs() []string {
|
||||||
p := []string{
|
p := []string{
|
||||||
"--combined-json", "bin,abi,userdoc,devdoc",
|
"--combined-json", "bin,bin-runtime,srcmap,srcmap-runtime,abi,userdoc,devdoc",
|
||||||
"--optimize", // code optimizer switched on
|
"--optimize", // code optimizer switched on
|
||||||
}
|
}
|
||||||
if s.Major > 0 || s.Minor > 4 || s.Patch > 6 {
|
if s.Major > 0 || s.Minor > 4 || s.Patch > 6 {
|
||||||
|
@ -157,7 +162,7 @@ func (s *Solidity) run(cmd *exec.Cmd, source string) (map[string]*Contract, erro
|
||||||
// provided source, language and compiler version, and compiler options are all
|
// provided source, language and compiler version, and compiler options are all
|
||||||
// passed through into the Contract structs.
|
// passed through into the Contract structs.
|
||||||
//
|
//
|
||||||
// The solc output is expected to contain ABI, user docs, and dev docs.
|
// The solc output is expected to contain ABI, source mapping, user docs, and dev docs.
|
||||||
//
|
//
|
||||||
// Returns an error if the JSON is malformed or missing data, or if the JSON
|
// Returns an error if the JSON is malformed or missing data, or if the JSON
|
||||||
// embedded within the JSON is malformed.
|
// embedded within the JSON is malformed.
|
||||||
|
@ -185,12 +190,15 @@ func ParseCombinedJSON(combinedJSON []byte, source string, languageVersion strin
|
||||||
}
|
}
|
||||||
contracts[name] = &Contract{
|
contracts[name] = &Contract{
|
||||||
Code: "0x" + info.Bin,
|
Code: "0x" + info.Bin,
|
||||||
|
RuntimeCode: "0x" + info.BinRuntime,
|
||||||
Info: ContractInfo{
|
Info: ContractInfo{
|
||||||
Source: source,
|
Source: source,
|
||||||
Language: "Solidity",
|
Language: "Solidity",
|
||||||
LanguageVersion: languageVersion,
|
LanguageVersion: languageVersion,
|
||||||
CompilerVersion: compilerVersion,
|
CompilerVersion: compilerVersion,
|
||||||
CompilerOptions: compilerOptions,
|
CompilerOptions: compilerOptions,
|
||||||
|
SrcMap: info.SrcMap,
|
||||||
|
SrcMapRuntime: info.SrcMapRuntime,
|
||||||
AbiDefinition: abi,
|
AbiDefinition: abi,
|
||||||
UserDoc: userdoc,
|
UserDoc: userdoc,
|
||||||
DeveloperDoc: devdoc,
|
DeveloperDoc: devdoc,
|
||||||
|
|
Loading…
Reference in New Issue