github.com/aigarnetwork/aigar@v0.0.0-20191115204914-d59a6eb70f8e/common/compiler/helpers.go (about) 1 // Copyright 2018 The go-ethereum Authors 2 // Copyright 2019 The go-aigar Authors 3 // This file is part of the go-aigar library. 4 // 5 // The go-aigar library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // The go-aigar library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with the go-aigar library. If not, see <http://www.gnu.org/licenses/>. 17 18 // Package compiler wraps the Solidity and Vyper compiler executables (solc; vyper). 19 package compiler 20 21 import ( 22 "bytes" 23 "io/ioutil" 24 "regexp" 25 ) 26 27 var versionRegexp = regexp.MustCompile(`([0-9]+)\.([0-9]+)\.([0-9]+)`) 28 29 // Contract contains information about a compiled contract, alongside its code and runtime code. 30 type Contract struct { 31 Code string `json:"code"` 32 RuntimeCode string `json:"runtime-code"` 33 Info ContractInfo `json:"info"` 34 Hashes map[string]string `json:"hashes"` 35 } 36 37 // ContractInfo contains information about a compiled contract, including access 38 // to the ABI definition, source mapping, user and developer docs, and metadata. 39 // 40 // Depending on the source, language version, compiler version, and compiler 41 // options will provide information about how the contract was compiled. 42 type ContractInfo struct { 43 Source string `json:"source"` 44 Language string `json:"language"` 45 LanguageVersion string `json:"languageVersion"` 46 CompilerVersion string `json:"compilerVersion"` 47 CompilerOptions string `json:"compilerOptions"` 48 SrcMap interface{} `json:"srcMap"` 49 SrcMapRuntime string `json:"srcMapRuntime"` 50 AbiDefinition interface{} `json:"abiDefinition"` 51 UserDoc interface{} `json:"userDoc"` 52 DeveloperDoc interface{} `json:"developerDoc"` 53 Metadata string `json:"metadata"` 54 } 55 56 func slurpFiles(files []string) (string, error) { 57 var concat bytes.Buffer 58 for _, file := range files { 59 content, err := ioutil.ReadFile(file) 60 if err != nil { 61 return "", err 62 } 63 concat.Write(content) 64 } 65 return concat.String(), nil 66 }