helpers.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2019 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. // Package compiler wraps the Solidity and Vyper compiler executables (solc; vyper).
  17. package compiler
  18. import (
  19. "bytes"
  20. "io/ioutil"
  21. "regexp"
  22. )
  23. var versionRegexp = regexp.MustCompile(`([0-9]+)\.([0-9]+)\.([0-9]+)`)
  24. // Contract contains information about a compiled contract, alongside its code and runtime code.
  25. type Contract struct {
  26. Code string `json:"code"`
  27. RuntimeCode string `json:"runtime-code"`
  28. Info ContractInfo `json:"info"`
  29. }
  30. // ContractInfo contains information about a compiled contract, including access
  31. // to the ABI definition, source mapping, user and developer docs, and metadata.
  32. //
  33. // Depending on the source, language version, compiler version, and compiler
  34. // options will provide information about how the contract was compiled.
  35. type ContractInfo struct {
  36. Source string `json:"source"`
  37. Language string `json:"language"`
  38. LanguageVersion string `json:"languageVersion"`
  39. CompilerVersion string `json:"compilerVersion"`
  40. CompilerOptions string `json:"compilerOptions"`
  41. SrcMap interface{} `json:"srcMap"`
  42. SrcMapRuntime string `json:"srcMapRuntime"`
  43. AbiDefinition interface{} `json:"abiDefinition"`
  44. UserDoc interface{} `json:"userDoc"`
  45. DeveloperDoc interface{} `json:"developerDoc"`
  46. Metadata string `json:"metadata"`
  47. }
  48. func slurpFiles(files []string) (string, error) {
  49. var concat bytes.Buffer
  50. for _, file := range files {
  51. content, err := ioutil.ReadFile(file)
  52. if err != nil {
  53. return "", err
  54. }
  55. concat.Write(content)
  56. }
  57. return concat.String(), nil
  58. }