cmd.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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"
  22. "github.com/ethereum/go-ethereum/cmd/ethereum/repl"
  23. "github.com/ethereum/go-ethereum/cmd/utils"
  24. "github.com/ethereum/go-ethereum/javascript"
  25. )
  26. func InitJsConsole(ethereum *eth.Ethereum) {
  27. repl := ethrepl.NewJSRepl(ethereum)
  28. go repl.Start()
  29. utils.RegisterInterrupt(func(os.Signal) {
  30. repl.Stop()
  31. })
  32. }
  33. func ExecJsFile(ethereum *eth.Ethereum, InputFile string) {
  34. file, err := os.Open(InputFile)
  35. if err != nil {
  36. clilogger.Fatalln(err)
  37. }
  38. content, err := ioutil.ReadAll(file)
  39. if err != nil {
  40. clilogger.Fatalln(err)
  41. }
  42. re := javascript.NewJSRE(ethereum)
  43. utils.RegisterInterrupt(func(os.Signal) {
  44. re.Stop()
  45. })
  46. re.Run(string(content))
  47. }