From 0c132e4c9e88bc0e13ad424f4c3b51cd4f5e8354 Mon Sep 17 00:00:00 2001 From: Jeffrey Wilcke Date: Mon, 7 Jul 2014 10:58:42 +0200 Subject: [PATCH 01/12] Revert "ethreact - Feature/ethutil refactor" --- ethereal/ext_app.go | 9 ++- ethereal/gui.go | 123 ++++++++++++++++----------------- ethereum/javascript_runtime.go | 16 ++--- 3 files changed, 72 insertions(+), 76 deletions(-) diff --git a/ethereal/ext_app.go b/ethereal/ext_app.go index c02f5ccb3..17c342a1b 100644 --- a/ethereal/ext_app.go +++ b/ethereal/ext_app.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethpub" - "github.com/ethereum/eth-go/ethreact" "github.com/ethereum/eth-go/ethutil" "github.com/go-qml/qml" ) @@ -25,8 +24,8 @@ type AppContainer interface { type ExtApplication struct { *ethpub.PEthereum - blockChan chan ethreact.Event - changeChan chan ethreact.Event + blockChan chan ethutil.React + changeChan chan ethutil.React quitChan chan bool watcherQuitChan chan bool @@ -38,8 +37,8 @@ type ExtApplication struct { func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication { app := &ExtApplication{ ethpub.NewPEthereum(lib.eth), - make(chan ethreact.Event), - make(chan ethreact.Event), + make(chan ethutil.React, 1), + make(chan ethutil.React, 1), make(chan bool), make(chan bool), container, diff --git a/ethereal/gui.go b/ethereal/gui.go index 2bad90361..9f28045f8 100644 --- a/ethereal/gui.go +++ b/ethereal/gui.go @@ -8,7 +8,6 @@ import ( "github.com/ethereum/eth-go/ethdb" "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/eth-go/ethpub" - "github.com/ethereum/eth-go/ethreact" "github.com/ethereum/eth-go/ethutil" "github.com/ethereum/eth-go/ethwire" "github.com/ethereum/go-ethereum/utils" @@ -144,7 +143,7 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) { gui.readPreviousTransactions() gui.setPeerInfo() - gui.update() + go gui.update() return win, nil } @@ -267,68 +266,11 @@ func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) { func (gui *Gui) update() { reactor := gui.eth.Reactor() - blockChan := make(chan ethreact.Event) - txChan := make(chan ethreact.Event) - objectChan := make(chan ethreact.Event) - peerChan := make(chan ethreact.Event) + blockChan := make(chan ethutil.React, 1) + txChan := make(chan ethutil.React, 1) + objectChan := make(chan ethutil.React, 1) + peerChan := make(chan ethutil.React, 1) - ticker := time.NewTicker(5 * time.Second) - - state := gui.eth.StateManager().TransState() - - unconfirmedFunds := new(big.Int) - gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Amount))) - - go func() { - for { - select { - case b := <-blockChan: - block := b.Resource.(*ethchain.Block) - gui.processBlock(block, false) - if bytes.Compare(block.Coinbase, gui.address()) == 0 { - gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.address()).Amount, nil) - } - - case txMsg := <-txChan: - tx := txMsg.Resource.(*ethchain.Transaction) - - if txMsg.Name == "newTx:pre" { - object := state.GetAccount(gui.address()) - - if bytes.Compare(tx.Sender(), gui.address()) == 0 { - gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "send") - gui.txDb.Put(tx.Hash(), tx.RlpEncode()) - - unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) - } else if bytes.Compare(tx.Recipient, gui.address()) == 0 { - gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "recv") - gui.txDb.Put(tx.Hash(), tx.RlpEncode()) - - unconfirmedFunds.Add(unconfirmedFunds, tx.Value) - } - - gui.setWalletValue(object.Amount, unconfirmedFunds) - } else { - object := state.GetAccount(gui.address()) - if bytes.Compare(tx.Sender(), gui.address()) == 0 { - object.SubAmount(tx.Value) - } else if bytes.Compare(tx.Recipient, gui.address()) == 0 { - object.AddAmount(tx.Value) - } - - gui.setWalletValue(object.Amount, nil) - - state.UpdateStateObject(object) - } - case <-objectChan: - gui.loadAddressBook() - case <-peerChan: - gui.setPeerInfo() - case <-ticker.C: - gui.setPeerInfo() - } - } - }() reactor.Subscribe("newBlock", blockChan) reactor.Subscribe("newTx:pre", txChan) reactor.Subscribe("newTx:post", txChan) @@ -339,6 +281,61 @@ func (gui *Gui) update() { } reactor.Subscribe("peerList", peerChan) + ticker := time.NewTicker(5 * time.Second) + + state := gui.eth.StateManager().TransState() + + unconfirmedFunds := new(big.Int) + gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Amount))) + + for { + select { + case b := <-blockChan: + block := b.Resource.(*ethchain.Block) + gui.processBlock(block, false) + if bytes.Compare(block.Coinbase, gui.address()) == 0 { + gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.address()).Amount, nil) + } + + case txMsg := <-txChan: + tx := txMsg.Resource.(*ethchain.Transaction) + + if txMsg.Event == "newTx:pre" { + object := state.GetAccount(gui.address()) + + if bytes.Compare(tx.Sender(), gui.address()) == 0 { + gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "send") + gui.txDb.Put(tx.Hash(), tx.RlpEncode()) + + unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) + } else if bytes.Compare(tx.Recipient, gui.address()) == 0 { + gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "recv") + gui.txDb.Put(tx.Hash(), tx.RlpEncode()) + + unconfirmedFunds.Add(unconfirmedFunds, tx.Value) + } + + gui.setWalletValue(object.Amount, unconfirmedFunds) + } else { + object := state.GetAccount(gui.address()) + if bytes.Compare(tx.Sender(), gui.address()) == 0 { + object.SubAmount(tx.Value) + } else if bytes.Compare(tx.Recipient, gui.address()) == 0 { + object.AddAmount(tx.Value) + } + + gui.setWalletValue(object.Amount, nil) + + state.UpdateStateObject(object) + } + case <-objectChan: + gui.loadAddressBook() + case <-peerChan: + gui.setPeerInfo() + case <-ticker.C: + gui.setPeerInfo() + } + } } func (gui *Gui) setPeerInfo() { diff --git a/ethereum/javascript_runtime.go b/ethereum/javascript_runtime.go index 6e107e376..852a50487 100644 --- a/ethereum/javascript_runtime.go +++ b/ethereum/javascript_runtime.go @@ -6,7 +6,6 @@ import ( "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethlog" "github.com/ethereum/eth-go/ethpub" - "github.com/ethereum/eth-go/ethreact" "github.com/ethereum/eth-go/ethutil" "github.com/ethereum/go-ethereum/utils" "github.com/obscuren/otto" @@ -23,8 +22,8 @@ type JSRE struct { vm *otto.Otto lib *ethpub.PEthereum - blockChan chan ethreact.Event - changeChan chan ethreact.Event + blockChan chan ethutil.React + changeChan chan ethutil.React quitChan chan bool objectCb map[string][]otto.Value @@ -49,8 +48,8 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE { ethereum, otto.New(), ethpub.NewPEthereum(ethereum), - make(chan ethreact.Event), - make(chan ethreact.Event), + make(chan ethutil.React, 1), + make(chan ethutil.React, 1), make(chan bool), make(map[string][]otto.Value), } @@ -64,9 +63,6 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE { // We have to make sure that, whoever calls this, calls "Stop" go re.mainLoop() - // Subscribe to events - reactor := ethereum.Reactor() - reactor.Subscribe("newBlock", re.blockChan) re.Bind("eth", &JSEthereum{re.lib, re.vm}) @@ -112,6 +108,10 @@ func (self *JSRE) Stop() { } func (self *JSRE) mainLoop() { + // Subscribe to events + reactor := self.ethereum.Reactor() + reactor.Subscribe("newBlock", self.blockChan) + out: for { select { From 79259c916ddb7fb9bbd2515dabb84b4f9025b4e3 Mon Sep 17 00:00:00 2001 From: Maran Date: Tue, 8 Jul 2014 14:05:42 +0200 Subject: [PATCH 02/12] Use relative image paths to help with windows builds --- ethereal/assets/qml/wallet.qml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ethereal/assets/qml/wallet.qml b/ethereal/assets/qml/wallet.qml index 4b252f200..33e1cc24c 100644 --- a/ethereal/assets/qml/wallet.qml +++ b/ethereal/assets/qml/wallet.qml @@ -100,7 +100,7 @@ ApplicationWindow { anchors.right: parent.right height: 200 Image { - source: ui.assetPath("tx.png") + source: "../tx.png" anchors.horizontalCenter: parent.horizontalCenter MouseArea { anchors.fill: parent @@ -110,7 +110,7 @@ ApplicationWindow { } } Image { - source: ui.assetPath("new.png") + source: "../new.png" anchors.horizontalCenter: parent.horizontalCenter MouseArea { anchors.fill: parent @@ -120,7 +120,7 @@ ApplicationWindow { } } Image { - source: ui.assetPath("net.png") + source: "../net.png" anchors.horizontalCenter: parent.horizontalCenter MouseArea { anchors.fill: parent @@ -131,7 +131,7 @@ ApplicationWindow { } Image { - source: ui.assetPath("heart.png") + source: "../heart.png" anchors.horizontalCenter: parent.horizontalCenter MouseArea { anchors.fill: parent From 7f9e614b5da75b948a0ba474e37254cb3f27ef0b Mon Sep 17 00:00:00 2001 From: Maran Date: Tue, 8 Jul 2014 14:25:30 +0200 Subject: [PATCH 03/12] Forgot two images --- ethereal/assets/qml/wallet.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ethereal/assets/qml/wallet.qml b/ethereal/assets/qml/wallet.qml index 33e1cc24c..c783cde83 100644 --- a/ethereal/assets/qml/wallet.qml +++ b/ethereal/assets/qml/wallet.qml @@ -436,7 +436,7 @@ ApplicationWindow { onDoubleClicked: peerWindow.visible = true anchors.fill: parent } - source: ui.assetPath("network.png") + source: "../network.png" } } @@ -624,7 +624,7 @@ ApplicationWindow { width: 150 fillMode: Image.PreserveAspectFit smooth: true - source: ui.assetPath("facet.png") + source: "../facet.png" x: 10 y: 10 } From 61d5d107b6f274cb1bf4ba6fda015ae30d28d2a6 Mon Sep 17 00:00:00 2001 From: Maran Date: Tue, 8 Jul 2014 14:27:22 +0200 Subject: [PATCH 04/12] Make script inclusion via QML also relative to asset path --- ethereal/assets/qml/webapp.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereal/assets/qml/webapp.qml b/ethereal/assets/qml/webapp.qml index 63927f0eb..401267511 100644 --- a/ethereal/assets/qml/webapp.qml +++ b/ethereal/assets/qml/webapp.qml @@ -38,7 +38,7 @@ ApplicationWindow { experimental.preferences.javascriptEnabled: true experimental.preferences.navigatorQtObjectEnabled: true experimental.preferences.developerExtrasEnabled: true - experimental.userScripts: [ui.assetPath("ext/pre.js"), ui.assetPath("ext/big.js"), ui.assetPath("ext/string.js"), ui.assetPath("ext/ethereum.js")] + experimental.userScripts: ["../ext/pre.js", "../ext/big.js", "../ext/string.js", "../ext/ethereum.js"] experimental.onMessageReceived: { console.log("[onMessageReceived]: ", message.data) // TODO move to messaging.js From 7e88dd4e6b5431a6c7bb2187965fd019261e5f3c Mon Sep 17 00:00:00 2001 From: Maran Date: Tue, 8 Jul 2014 14:58:23 +0200 Subject: [PATCH 05/12] Setup default asset path for windows --- ethereal/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereal/flags.go b/ethereal/flags.go index 2c9b3af5f..9a4318855 100644 --- a/ethereal/flags.go +++ b/ethereal/flags.go @@ -53,7 +53,7 @@ func defaultAssetPath() string { case "linux": assetPath = "/usr/share/ethereal" case "window": - fallthrough + assetPath = "./assets" default: assetPath = "." } From 05c18998959b6fbc5da674489371a8d3e88e7db2 Mon Sep 17 00:00:00 2001 From: Maran Date: Tue, 8 Jul 2014 14:58:33 +0200 Subject: [PATCH 06/12] Windos case for assetPath had a typo --- ethereal/flags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereal/flags.go b/ethereal/flags.go index 9a4318855..d5ca9f336 100644 --- a/ethereal/flags.go +++ b/ethereal/flags.go @@ -52,7 +52,7 @@ func defaultAssetPath() string { assetPath = filepath.Join(exedir, "../Resources") case "linux": assetPath = "/usr/share/ethereal" - case "window": + case "windows": assetPath = "./assets" default: assetPath = "." From c2bca5939d1d78d1548fcd43c29390fb06a508c0 Mon Sep 17 00:00:00 2001 From: Maran Date: Wed, 9 Jul 2014 14:01:53 +0200 Subject: [PATCH 07/12] Added path check for Windows when loading external QML windows/components --- ethereal/qml_container.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ethereal/qml_container.go b/ethereal/qml_container.go index a8ce1cb75..cb43a99bd 100644 --- a/ethereal/qml_container.go +++ b/ethereal/qml_container.go @@ -5,6 +5,7 @@ import ( "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" "github.com/go-qml/qml" + "runtime" ) type QmlApplication struct { @@ -20,7 +21,14 @@ func NewQmlApplication(path string, lib *UiLib) *QmlApplication { } func (app *QmlApplication) Create() error { - component, err := app.engine.LoadFile(app.path) + path := string(app.path) + + // For some reason for windows we get /c:/path/to/something, windows doesn't like the first slash but is fine with the others so we are removing it + if string(app.path[0]) == "/" && runtime.GOOS == "windows" { + path = app.path[1:] + } + + component, err := app.engine.LoadFile(path) if err != nil { logger.Warnln(err) } From d3e31a4a6db6166b0639f0e9be5f70d5035baeeb Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 11 Jul 2014 16:04:27 +0200 Subject: [PATCH 08/12] Special diff output + debugger changes --- ethereal/assets/debugger/debugger.qml | 2 +- ethereal/debugger.go | 13 +++++++++++-- ethereum/flags.go | 2 ++ ethereum/main.go | 8 ++++++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ethereal/assets/debugger/debugger.qml b/ethereal/assets/debugger/debugger.qml index f204647c8..4d01ea183 100644 --- a/ethereal/assets/debugger/debugger.qml +++ b/ethereal/assets/debugger/debugger.qml @@ -116,7 +116,7 @@ ApplicationWindow { id: compileTimer interval: 500 ; running: true ; repeat: true onTriggered: { - dbg.compile(codeEditor.text) + dbg.autoComp(codeEditor.text) } } } diff --git a/ethereal/debugger.go b/ethereal/debugger.go index 64ca316f8..997c2e8dd 100644 --- a/ethereal/debugger.go +++ b/ethereal/debugger.go @@ -74,6 +74,13 @@ func (self *DebuggerWindow) Compile(code string) { } } +// Used by QML +func (self *DebuggerWindow) AutoComp(code string) { + if self.Db.done { + self.Compile(code) + } +} + func (self *DebuggerWindow) ClearLog() { self.win.Root().Call("clearLog") } @@ -110,8 +117,6 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data return } - self.SetAsm(script) - var ( gas = ethutil.Big(gasStr) gasPrice = ethutil.Big(gasPriceStr) @@ -257,6 +262,10 @@ func (self *Debugger) StepHook(pc int, op ethchain.OpCode, mem *ethchain.Memory, return self.halting(pc, op, mem, stack, stateObject) } +func (self *Debugger) SetCode(byteCode []byte) { + self.main.SetAsm(byteCode) +} + func (self *Debugger) BreakPoints() []int64 { return self.breakPoints } diff --git a/ethereum/flags.go b/ethereum/flags.go index d5a9c3a8a..af0fd9a69 100644 --- a/ethereum/flags.go +++ b/ethereum/flags.go @@ -11,6 +11,7 @@ import ( var Identifier string var KeyRing string +var DiffTool bool var KeyStore string var StartRpc bool var RpcPort int @@ -66,6 +67,7 @@ func Init() { flag.StringVar(&ConfigFile, "conf", defaultConfigFile, "config file") flag.StringVar(&DebugFile, "debug", "", "debug file (no debugging if not set)") flag.IntVar(&LogLevel, "loglevel", int(ethlog.InfoLevel), "loglevel: 0-5: silent,error,warn,info,debug,debug detail)") + flag.BoolVar(&DiffTool, "difftool", false, "creates output for diff'ing. Sets LogLevel=0") flag.BoolVar(&StartMining, "mine", false, "start dagger mining") flag.BoolVar(&StartJsConsole, "js", false, "launches javascript console") diff --git a/ethereum/main.go b/ethereum/main.go index e4d73d494..39226c1d2 100644 --- a/ethereum/main.go +++ b/ethereum/main.go @@ -2,6 +2,7 @@ package main import ( "github.com/ethereum/eth-go/ethlog" + "github.com/ethereum/eth-go/ethutil" "github.com/ethereum/go-ethereum/utils" "runtime" ) @@ -20,7 +21,14 @@ func main() { // precedence: code-internal flag default < config file < environment variables < command line Init() // parsing command line + + // If the difftool option is selected ignore all other log output + if DiffTool { + LogLevel = 0 + } + utils.InitConfig(ConfigFile, Datadir, "ETH") + ethutil.Config.Diff = DiffTool utils.InitDataDir(Datadir) From 288f1c5387c1a0a8863499389e8a7ca7e3068208 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 12 Jul 2014 11:02:50 +0200 Subject: [PATCH 09/12] Removed timer --- ethereal/assets/debugger/debugger.qml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ethereal/assets/debugger/debugger.qml b/ethereal/assets/debugger/debugger.qml index 4d01ea183..fa56737a2 100644 --- a/ethereal/assets/debugger/debugger.qml +++ b/ethereal/assets/debugger/debugger.qml @@ -19,7 +19,7 @@ ApplicationWindow { property alias dataText: rawDataField.text onClosing: { - compileTimer.stop() + //compileTimer.stop() } MenuBar { @@ -112,6 +112,7 @@ ApplicationWindow { anchors.right: settings.left focus: true + /* Timer { id: compileTimer interval: 500 ; running: true ; repeat: true @@ -119,6 +120,7 @@ ApplicationWindow { dbg.autoComp(codeEditor.text) } } + */ } Column { From e6a428f85f0d1c7e50dc8262a7687ec2f1ce2d7b Mon Sep 17 00:00:00 2001 From: Maran Date: Mon, 14 Jul 2014 15:25:01 +0200 Subject: [PATCH 10/12] Make the reload watcher use windows-safe paths --- ethereal/html_container.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethereal/html_container.go b/ethereal/html_container.go index 1e835eebc..2ad06ffb5 100644 --- a/ethereal/html_container.go +++ b/ethereal/html_container.go @@ -59,7 +59,7 @@ func (app *HtmlApplication) RootFolder() string { if err != nil { return "" } - return path.Dir(folder.RequestURI()) + return path.Dir(ethutil.WindonizePath(folder.RequestURI())) } func (app *HtmlApplication) RecursiveFolders() []os.FileInfo { files, _ := ioutil.ReadDir(app.RootFolder()) From dce0ccf4902def623f33af3ce3878d1c1512101e Mon Sep 17 00:00:00 2001 From: Maran Date: Mon, 14 Jul 2014 15:29:02 +0200 Subject: [PATCH 11/12] Don't silently fail on watcher creation --- ethereal/html_container.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ethereal/html_container.go b/ethereal/html_container.go index 2ad06ffb5..04136f801 100644 --- a/ethereal/html_container.go +++ b/ethereal/html_container.go @@ -8,7 +8,6 @@ import ( "github.com/go-qml/qml" "github.com/howeyc/fsnotify" "io/ioutil" - "log" "net/url" "os" "path" @@ -77,11 +76,13 @@ func (app *HtmlApplication) NewWatcher(quitChan chan bool) { app.watcher, err = fsnotify.NewWatcher() if err != nil { + logger.Infoln("Could not create new auto-reload watcher:", err) return } err = app.watcher.Watch(app.RootFolder()) if err != nil { - log.Fatal(err) + logger.Infoln("Could not start auto-reload watcher:", err) + return } for _, folder := range app.RecursiveFolders() { fullPath := app.RootFolder() + "/" + folder.Name() From e53acdc2ac45fa8953afc3392ed81653d6f26326 Mon Sep 17 00:00:00 2001 From: Maran Date: Mon, 14 Jul 2014 16:46:00 +0200 Subject: [PATCH 12/12] Work around race condition with qt webinspector for windows builds --- ethereal/assets/qml/webapp.qml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ethereal/assets/qml/webapp.qml b/ethereal/assets/qml/webapp.qml index 401267511..5e4c035d8 100644 --- a/ethereal/assets/qml/webapp.qml +++ b/ethereal/assets/qml/webapp.qml @@ -191,6 +191,7 @@ ApplicationWindow { inspector.visible = false }else{ inspector.visible = true + inspector.url = webview.experimental.remoteInspectorUrl } } onDoubleClicked: { @@ -224,7 +225,6 @@ ApplicationWindow { WebView { id: inspector visible: false - url: webview.experimental.remoteInspectorUrl anchors { left: root.left right: root.right @@ -238,7 +238,6 @@ ApplicationWindow { name: "inspectorShown" PropertyChanges { target: inspector - url: webview.experimental.remoteInspectorUrl } } ]