From c10f65a1a97e791d63a6ec24f22ea4a16eb3eefb Mon Sep 17 00:00:00 2001 From: Steve Waldman Date: Sat, 28 Jan 2017 22:19:32 -0800 Subject: [PATCH] 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. --- common/compiler/solidity.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/common/compiler/solidity.go b/common/compiler/solidity.go index 8d44c1a463..5e20c5b208 100644 --- a/common/compiler/solidity.go +++ b/common/compiler/solidity.go @@ -54,7 +54,7 @@ type ContractInfo struct { AbiDefinition interface{} `json:"abiDefinition"` UserDoc interface{} `json:"userDoc"` DeveloperDoc interface{} `json:"developerDoc"` - Metadata interface{} `json:"metadata"` + Metadata string `json:"metadata"` } // 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 { return nil, fmt.Errorf("solc: error reading dev doc: %v", err) } - var metadata interface{} + var metadata string 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) } }