diff --git a/ethereal/config.go b/ethereal/config.go index 817befc2c..3864126db 100644 --- a/ethereal/config.go +++ b/ethereal/config.go @@ -4,6 +4,7 @@ import ( "flag" ) +var Identifier string var StartConsole bool var StartMining bool var StartRpc bool @@ -21,6 +22,7 @@ var DataDir string var AssetPath string func Init() { + flag.StringVar(&Identifier, "i", "", "Custom client identifier") flag.BoolVar(&StartConsole, "c", false, "debug and testing console") flag.BoolVar(&StartMining, "m", false, "start dagger mining") flag.BoolVar(&StartRpc, "r", false, "start rpc server") diff --git a/ethereal/ethereum.go b/ethereal/ethereum.go index 206971b41..30187d956 100644 --- a/ethereal/ethereum.go +++ b/ethereal/ethereum.go @@ -39,7 +39,7 @@ func main() { runtime.GOMAXPROCS(runtime.NumCPU()) ethchain.InitFees() - ethutil.ReadConfig(DataDir, ethutil.LogFile|ethutil.LogStd) + ethutil.ReadConfig(DataDir, ethutil.LogFile|ethutil.LogStd, Identifier) // Instantiated a eth stack ethereum, err := eth.New(eth.CapDefault, UseUPnP) diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index 7290bd6ec..022f192bf 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -9,7 +9,6 @@ import ( "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" "github.com/go-qml/qml" - "github.com/obscuren/mutan" "math/big" "strings" ) @@ -262,7 +261,7 @@ func (gui *Gui) Transact(recipient, value, gas, gasPrice, data string) (*ethpub. func (gui *Gui) Create(recipient, value, gas, gasPrice, data string) (*ethpub.PReceipt, error) { keyPair := ethutil.GetKeyRing().Get(0) - mainInput, initInput := mutan.PreParse(data) + //mainInput, initInput := mutan.PreParse(data) - return gui.pub.Create(ethutil.Hex(keyPair.PrivateKey), value, gas, gasPrice, initInput, mainInput) + return gui.pub.Create(ethutil.Hex(keyPair.PrivateKey), value, gas, gasPrice, data) } diff --git a/ethereal/ui/ui_lib.go b/ethereal/ui/ui_lib.go index 0c43f1675..1c88b0181 100644 --- a/ethereal/ui/ui_lib.go +++ b/ethereal/ui/ui_lib.go @@ -135,7 +135,7 @@ func (ui *UiLib) DebugTx(recipient, valueStr, gasStr, gasPriceStr, data string) for _, str := range dis { ui.win.Root().Call("setAsm", str) } - callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), callerScript, nil) + callerTx := ethchain.NewContractCreationTx(ethutil.Big(valueStr), ethutil.Big(gasStr), ethutil.Big(gasPriceStr), nil) // Contract addr as test address keyPair := ethutil.GetKeyRing().Get(0) diff --git a/ethereum/config.go b/ethereum/config.go index f25f2fb66..5da910f2b 100644 --- a/ethereum/config.go +++ b/ethereum/config.go @@ -6,6 +6,7 @@ import ( "os" ) +var Identifier string var StartMining bool var StartRpc bool var RpcPort int @@ -30,6 +31,7 @@ func Init() { flag.PrintDefaults() } + flag.StringVar(&Identifier, "i", "", "custom client identifier") flag.BoolVar(&StartMining, "m", false, "start dagger mining") flag.BoolVar(&ShowGenesis, "g", false, "prints genesis header and exits") flag.BoolVar(&StartRpc, "r", false, "start rpc server") @@ -45,7 +47,6 @@ func Init() { flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)") flag.IntVar(&MaxPeer, "x", 10, "maximum desired peers") flag.BoolVar(&StartJsConsole, "js", false, "exp") - //flag.StringVar(&InputFile, "e", "", "Run javascript file") flag.Parse() diff --git a/ethereum/ethereum.go b/ethereum/ethereum.go index 2fdfd5caf..34bacb7b9 100644 --- a/ethereum/ethereum.go +++ b/ethereum/ethereum.go @@ -52,12 +52,15 @@ func main() { var logSys *log.Logger flags := log.LstdFlags + var lt ethutil.LoggerType if StartJsConsole || len(InputFile) > 0 { - ethutil.ReadConfig(DataDir, ethutil.LogFile) + lt = ethutil.LogFile } else { - ethutil.ReadConfig(DataDir, ethutil.LogFile|ethutil.LogStd) + lt = ethutil.LogFile | ethutil.LogStd } + ethutil.ReadConfig(DataDir, lt, Identifier) + logger := ethutil.Config.Log if LogFile != "" { diff --git a/ethereum/javascript_runtime.go b/ethereum/javascript_runtime.go index fa01c7005..93297f604 100644 --- a/ethereum/javascript_runtime.go +++ b/ethereum/javascript_runtime.go @@ -6,6 +6,7 @@ import ( "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" + "github.com/ethereum/go-ethereum/utils" "github.com/obscuren/otto" "io/ioutil" "os" @@ -116,14 +117,26 @@ func (self *JSRE) initStdFuncs() { eth.Set("watch", self.watch) eth.Set("addPeer", self.addPeer) eth.Set("require", self.require) + eth.Set("stopMining", self.stopMining) + eth.Set("startMining", self.startMining) } /* * The following methods are natively implemented javascript functions */ +func (self *JSRE) stopMining(call otto.FunctionCall) otto.Value { + v, _ := self.vm.ToValue(utils.StopMining(self.ethereum)) + return v +} + +func (self *JSRE) startMining(call otto.FunctionCall) otto.Value { + v, _ := self.vm.ToValue(utils.StartMining(self.ethereum)) + return v +} + // eth.watch -func (self JSRE) watch(call otto.FunctionCall) otto.Value { +func (self *JSRE) watch(call otto.FunctionCall) otto.Value { addr, _ := call.Argument(0).ToString() var storageAddr string var cb otto.Value diff --git a/ethereum/repl.go b/ethereum/repl.go index d1243d19c..10f51675e 100644 --- a/ethereum/repl.go +++ b/ethereum/repl.go @@ -48,13 +48,22 @@ func (self *JSRepl) parseInput(code string) { // The JSEthereum object attempts to wrap the PEthereum object and returns // meaningful javascript objects +type JSBlock struct { + *ethpub.PBlock + eth *JSEthereum +} + +func (self *JSBlock) GetTransaction(hash string) otto.Value { + return self.eth.toVal(self.PBlock.GetTransaction(hash)) +} + type JSEthereum struct { *ethpub.PEthereum vm *otto.Otto } func (self *JSEthereum) GetBlock(hash string) otto.Value { - return self.toVal(self.PEthereum.GetBlock(hash)) + return self.toVal(&JSBlock{self.PEthereum.GetBlock(hash), self}) } func (self *JSEthereum) GetKey() otto.Value { @@ -76,8 +85,8 @@ func (self *JSEthereum) Transact(key, recipient, valueStr, gasStr, gasPriceStr, return self.toVal(r) } -func (self *JSEthereum) Create(key, valueStr, gasStr, gasPriceStr, initStr, bodyStr string) otto.Value { - r, err := self.PEthereum.Create(key, valueStr, gasStr, gasPriceStr, initStr, bodyStr) +func (self *JSEthereum) Create(key, valueStr, gasStr, gasPriceStr, scriptStr string) otto.Value { + r, err := self.PEthereum.Create(key, valueStr, gasStr, gasPriceStr, scriptStr) if err != nil { fmt.Println(err) diff --git a/ethereum/repl_darwin.go b/ethereum/repl_darwin.go index 1b98c2150..b61d4edd7 100644 --- a/ethereum/repl_darwin.go +++ b/ethereum/repl_darwin.go @@ -1,17 +1,42 @@ package main +// #cgo darwin CFLAGS: -I/usr/local/opt/readline/include +// #cgo darwin LDFLAGS: -L/usr/local/opt/readline/lib // #cgo LDFLAGS: -lreadline // #include // #include // #include // #include import "C" - import ( + "os" + "os/signal" "strings" + "syscall" "unsafe" ) +func initReadLine() { + C.rl_catch_sigwinch = 0 + C.rl_catch_signals = 0 + c := make(chan os.Signal, 1) + signal.Notify(c, syscall.SIGWINCH) + signal.Notify(c, os.Interrupt) + go func() { + for sig := range c { + switch sig { + case syscall.SIGWINCH: + C.rl_resize_terminal() + + case os.Interrupt: + C.rl_cleanup_after_signal() + default: + + } + } + }() +} + func readLine(prompt *string) *string { var p *C.char @@ -59,6 +84,7 @@ func (self *JSRepl) setIndent() { } func (self *JSRepl) read() { + initReadLine() L: for { switch result := readLine(&self.prompt); true { @@ -76,7 +102,7 @@ L: break L } - addHistory(str) //allow user to recall this line + addHistory(str[:len(str)-1]) //allow user to recall this line self.parseInput(str) diff --git a/utils/cmd.go b/utils/cmd.go index f163575da..98005d7de 100644 --- a/utils/cmd.go +++ b/utils/cmd.go @@ -19,6 +19,8 @@ func DoRpc(ethereum *eth.Ethereum, RpcPort int) { } } +var miner ethminer.Miner + func DoMining(ethereum *eth.Ethereum) { // Set Mining status ethereum.Mining = true @@ -31,17 +33,37 @@ func DoMining(ethereum *eth.Ethereum) { addr := keyPair.Address() go func() { + ethutil.Config.Log.Infoln("Miner started") + + miner = ethminer.NewDefaultMiner(addr, ethereum) + // Give it some time to connect with peers time.Sleep(3 * time.Second) - /* - for ethereum.IsUpToDate() == false { - time.Sleep(5 * time.Second) - } - */ - ethutil.Config.Log.Infoln("Miner started") - - miner := ethminer.NewDefaultMiner(addr, ethereum) miner.Start() }() } + +func StopMining(ethereum *eth.Ethereum) bool { + if ethereum.Mining { + miner.Stop() + + ethutil.Config.Log.Infoln("Miner stopped") + + ethereum.Mining = false + + return true + } + + return false +} + +func StartMining(ethereum *eth.Ethereum) bool { + if !ethereum.Mining { + DoMining(ethereum) + + return true + } + + return false +}