github.com/theQRL/go-zond@v0.2.1/common/compiler/hyperion.go (about) 1 // Copyright 2015 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 // Package compiler wraps the ABI compilation outputs. 18 package compiler 19 20 import ( 21 "encoding/json" 22 ) 23 24 // --combined-output format 25 type hypcOutput struct { 26 Contracts map[string]struct { 27 BinRuntime string `json:"bin-runtime"` 28 SrcMapRuntime string `json:"srcmap-runtime"` 29 Bin, SrcMap, Metadata string 30 Abi interface{} 31 Devdoc interface{} 32 Userdoc interface{} 33 Hashes map[string]string 34 } 35 Version string 36 } 37 38 // ParseCombinedJSON takes the direct output of a hypc --combined-output run and 39 // parses it into a map of string contract name to Contract structs. The 40 // provided source, language and compiler version, and compiler options are all 41 // passed through into the Contract structs. 42 // 43 // The hypc output is expected to contain ABI, source mapping, user docs, and dev docs. 44 // 45 // Returns an error if the JSON is malformed or missing data, or if the JSON 46 // embedded within the JSON is malformed. 47 func ParseCombinedJSON(combinedJSON []byte, source string, languageVersion string, compilerVersion string, compilerOptions string) (map[string]*Contract, error) { 48 var output hypcOutput 49 if err := json.Unmarshal(combinedJSON, &output); err != nil { 50 return nil, err 51 } 52 // Compilation succeeded, assemble and return the contracts. 53 contracts := make(map[string]*Contract) 54 for name, info := range output.Contracts { 55 contracts[name] = &Contract{ 56 Code: "0x" + info.Bin, 57 RuntimeCode: "0x" + info.BinRuntime, 58 Hashes: info.Hashes, 59 Info: ContractInfo{ 60 Source: source, 61 Language: "Hyperion", 62 LanguageVersion: languageVersion, 63 CompilerVersion: compilerVersion, 64 CompilerOptions: compilerOptions, 65 SrcMap: info.SrcMap, 66 SrcMapRuntime: info.SrcMapRuntime, 67 AbiDefinition: info.Abi, 68 UserDoc: info.Userdoc, 69 DeveloperDoc: info.Devdoc, 70 Metadata: info.Metadata, 71 }, 72 } 73 } 74 return contracts, nil 75 }