js.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
  2. //
  3. // This library is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public
  5. // License as published by the Free Software Foundation; either
  6. // version 2.1 of the License, or (at your option) any later version.
  7. //
  8. // This library is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. // General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this library; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. // MA 02110-1301 USA
  17. package main
  18. import (
  19. "io/ioutil"
  20. "os"
  21. "github.com/ethereum/go-ethereum/cmd/utils"
  22. "github.com/ethereum/go-ethereum/eth"
  23. "github.com/ethereum/go-ethereum/javascript"
  24. "github.com/ethereum/go-ethereum/xeth"
  25. )
  26. func execJsFile(ethereum *eth.Ethereum, filename string) {
  27. file, err := os.Open(filename)
  28. if err != nil {
  29. utils.Fatalf("%v", err)
  30. }
  31. content, err := ioutil.ReadAll(file)
  32. if err != nil {
  33. utils.Fatalf("%v", err)
  34. }
  35. re := javascript.NewJSRE(xeth.New(ethereum))
  36. if _, err := re.Run(string(content)); err != nil {
  37. utils.Fatalf("Javascript Error: %v", err)
  38. }
  39. }