script.go 735 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package ethutil
  2. import (
  3. "fmt"
  4. "github.com/obscuren/mutan"
  5. "github.com/obscuren/mutan/backends"
  6. "github.com/obscuren/serpent-go"
  7. "strings"
  8. )
  9. // General compile function
  10. func Compile(script string) (ret []byte, err error) {
  11. c := strings.Split(script, "\n")[0]
  12. if c == "#!serpent" {
  13. byteCode, err := serpent.Compile(script)
  14. if err != nil {
  15. return nil, err
  16. }
  17. return byteCode, nil
  18. } else {
  19. compiler := mutan.NewCompiler(backend.NewEthereumBackend())
  20. byteCode, errors := compiler.Compile(strings.NewReader(script))
  21. if len(errors) > 0 {
  22. var errs string
  23. for _, er := range errors {
  24. if er != nil {
  25. errs += er.Error()
  26. }
  27. }
  28. return nil, fmt.Errorf("%v", errs)
  29. }
  30. return byteCode, nil
  31. }
  32. }