Encode metadata as JSON String, rather than as JSON object

Ensures that we can decode to a set of bytes that will be consistent with
the swarm hash embedded in the code, without worrying about ambiguities of
spacing, ordering, or escaping.
This commit is contained in:
Steve Waldman 2017-01-28 22:19:32 -08:00
parent 87a22c400f
commit c10f65a1a9

View file

@ -54,7 +54,7 @@ type ContractInfo struct {
AbiDefinition interface{} `json:"abiDefinition"` AbiDefinition interface{} `json:"abiDefinition"`
UserDoc interface{} `json:"userDoc"` UserDoc interface{} `json:"userDoc"`
DeveloperDoc interface{} `json:"developerDoc"` DeveloperDoc interface{} `json:"developerDoc"`
Metadata interface{} `json:"metadata"` Metadata string `json:"metadata"`
} }
// Solidity contains information about the solidity compiler. // Solidity contains information about the solidity compiler.
@ -201,9 +201,13 @@ func runsolc(cmd *exec.Cmd, solcParams []string, source string) (map[string]*Con
if err := json.Unmarshal([]byte(info.Devdoc), &devdoc); err != nil { if err := json.Unmarshal([]byte(info.Devdoc), &devdoc); err != nil {
return nil, fmt.Errorf("solc: error reading dev doc: %v", err) return nil, fmt.Errorf("solc: error reading dev doc: %v", err)
} }
var metadata interface{} var metadata string
if info.Metadata != "" { if info.Metadata != "" {
if err := json.Unmarshal([]byte(info.Metadata), &metadata); err != nil { jstring, err := json.Marshal( string(info.Metadata) )
if ( err != nil ) {
return nil, fmt.Errorf("solc: error coercing metadata to string: %v", err)
}
if err := json.Unmarshal(jstring, &metadata); err != nil {
return nil, fmt.Errorf("solc: error reading metadata: %v", err) return nil, fmt.Errorf("solc: error reading metadata: %v", err)
} }
} }