cmd.go 1.49 KB
Newer Older
Felix Lange's avatar
Felix Lange committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Copyright (c) 2013-2014, Jeffrey Wilcke. All rights reserved.
//
// This library 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 2.1 of the License, or (at your option) any later version.
//
// This library 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 this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301  USA

18 19 20
package main

import (
21 22 23
	"io/ioutil"
	"os"

24 25
	"github.com/ethereum/go-ethereum"
	"github.com/ethereum/go-ethereum/cmd/ethereum/repl"
obscuren's avatar
obscuren committed
26
	"github.com/ethereum/go-ethereum/cmd/utils"
27
	"github.com/ethereum/go-ethereum/javascript"
28 29 30
)

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

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