cmd.go 1.41 KB
Newer Older
obscuren's avatar
obscuren committed
1 2
/*
	This file is part of go-ethereum
Felix Lange's avatar
Felix Lange committed
3

obscuren's avatar
obscuren committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
	go-ethereum is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	go-ethereum is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with go-ethereum.  If not, see <http://www.gnu.org/licenses/>.
*/
/**
 * @authors
 * 	Jeffrey Wilcke <i@jev.io>
 */
21 22 23
package main

import (
24 25 26
	"io/ioutil"
	"os"

27
	"github.com/ethereum/go-ethereum/cmd/ethereum/repl"
obscuren's avatar
obscuren committed
28
	"github.com/ethereum/go-ethereum/cmd/utils"
zelig's avatar
zelig committed
29
	"github.com/ethereum/go-ethereum/eth"
30
	"github.com/ethereum/go-ethereum/javascript"
31 32 33
)

func InitJsConsole(ethereum *eth.Ethereum) {
34
	repl := ethrepl.NewJSRepl(ethereum)
zelig's avatar
zelig committed
35 36 37 38
	go repl.Start()
	utils.RegisterInterrupt(func(os.Signal) {
		repl.Stop()
	})
39 40
}

zelig's avatar
zelig committed
41 42 43
func ExecJsFile(ethereum *eth.Ethereum, InputFile string) {
	file, err := os.Open(InputFile)
	if err != nil {
obscuren's avatar
obscuren committed
44
		clilogger.Fatalln(err)
zelig's avatar
zelig committed
45 46 47
	}
	content, err := ioutil.ReadAll(file)
	if err != nil {
obscuren's avatar
obscuren committed
48
		clilogger.Fatalln(err)
zelig's avatar
zelig committed
49
	}
50
	re := javascript.NewJSRE(ethereum)
zelig's avatar
zelig committed
51 52 53 54
	utils.RegisterInterrupt(func(os.Signal) {
		re.Stop()
	})
	re.Run(string(content))
55
}