diff options
Diffstat (limited to 'ethereal')
-rw-r--r-- | ethereal/assets/samplecoin/samplecoin.html | 2 | ||||
-rw-r--r-- | ethereal/config.go | 2 | ||||
-rw-r--r-- | ethereal/ethereum.go | 2 | ||||
-rw-r--r-- | ethereal/ui/ext_app.go | 12 | ||||
-rw-r--r-- | ethereal/ui/gui.go | 23 | ||||
-rw-r--r-- | ethereal/ui/html_container.go | 60 |
6 files changed, 85 insertions, 16 deletions
diff --git a/ethereal/assets/samplecoin/samplecoin.html b/ethereal/assets/samplecoin/samplecoin.html index 3f8eacc00..d47c6323c 100644 --- a/ethereal/assets/samplecoin/samplecoin.html +++ b/ethereal/assets/samplecoin/samplecoin.html @@ -9,7 +9,7 @@ <script type="text/javascript"> -var jefcoinAddr = "681fd48ffa236549fbcd16bdf9f98bb541a7f742" +var jefcoinAddr = "739105c31705038744d190332e3a07c8fea8a9eb" var mAddr = "" function createTransaction() { diff --git a/ethereal/config.go b/ethereal/config.go index e4bdb0a00..817befc2c 100644 --- a/ethereal/config.go +++ b/ethereal/config.go @@ -33,7 +33,7 @@ func Init() { flag.StringVar(&OutboundPort, "p", "30303", "listening port") flag.StringVar(&DataDir, "dir", ".ethereal", "ethereum data directory") flag.StringVar(&ImportKey, "import", "", "imports the given private key (hex)") - flag.IntVar(&MaxPeer, "x", 5, "maximum desired peers") + flag.IntVar(&MaxPeer, "x", 10, "maximum desired peers") flag.StringVar(&AssetPath, "asset_path", "", "absolute path to GUI assets directory") flag.Parse() diff --git a/ethereal/ethereum.go b/ethereal/ethereum.go index 98fab18e3..206971b41 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.ReadConfig(DataDir, ethutil.LogFile|ethutil.LogStd) // Instantiated a eth stack ethereum, err := eth.New(eth.CapDefault, UseUPnP) diff --git a/ethereal/ui/ext_app.go b/ethereal/ui/ext_app.go index de5f15db6..d1a256cdb 100644 --- a/ethereal/ui/ext_app.go +++ b/ethereal/ui/ext_app.go @@ -18,14 +18,16 @@ type AppContainer interface { NewBlock(*ethchain.Block) ObjectChanged(*ethchain.StateObject) StorageChanged(*ethchain.StorageState) + NewWatcher(chan bool) } type ExtApplication struct { *ethpub.PEthereum - blockChan chan ethutil.React - changeChan chan ethutil.React - quitChan chan bool + blockChan chan ethutil.React + changeChan chan ethutil.React + quitChan chan bool + watcherQuitChan chan bool container AppContainer lib *UiLib @@ -38,6 +40,7 @@ func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication { make(chan ethutil.React, 1), make(chan ethutil.React, 1), make(chan bool), + make(chan bool), container, lib, nil, @@ -66,6 +69,8 @@ func (app *ExtApplication) run() { reactor := app.lib.eth.Reactor() reactor.Subscribe("newBlock", app.blockChan) + app.container.NewWatcher(app.watcherQuitChan) + win := app.container.Window() win.Show() win.Wait() @@ -83,6 +88,7 @@ func (app *ExtApplication) stop() { // Kill the main loop app.quitChan <- true + app.watcherQuitChan <- true close(app.blockChan) close(app.quitChan) diff --git a/ethereal/ui/gui.go b/ethereal/ui/gui.go index aa0364998..e267dabfd 100644 --- a/ethereal/ui/gui.go +++ b/ethereal/ui/gui.go @@ -55,7 +55,7 @@ func New(ethereum *eth.Ethereum) *Gui { } func (gui *Gui) Start(assetPath string) { - const version = "0.5.0 RC6" + const version = "0.5.0 RC7" defer gui.txDb.Close() @@ -178,13 +178,14 @@ func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) { // Simple go routine function that updates the list of peers in the GUI func (gui *Gui) update() { - blockChan := make(chan ethutil.React, 1) reactor := gui.eth.Reactor() - reactor.Subscribe("newBlock", blockChan) + blockChan := make(chan ethutil.React, 1) + txChan := make(chan ethutil.React, 1) - txChan := make(chan ethchain.TxMsg, 1) - gui.eth.TxPool().Subscribe(txChan) + reactor.Subscribe("newBlock", blockChan) + reactor.Subscribe("newTx:pre", txChan) + reactor.Subscribe("newTx:post", txChan) state := gui.eth.StateManager().TransState() @@ -196,21 +197,23 @@ func (gui *Gui) update() { case b := <-blockChan: block := b.Resource.(*ethchain.Block) if bytes.Compare(block.Coinbase, gui.addr) == 0 { - gui.setWalletValue(gui.eth.StateManager().ProcState().GetAccount(gui.addr).Amount, nil) + gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.addr).Amount, nil) } case txMsg := <-txChan: - tx := txMsg.Tx + tx := txMsg.Resource.(*ethchain.Transaction) - if txMsg.Type == ethchain.TxPre { + if txMsg.Event == "newTx:pre" { object := state.GetAccount(gui.addr) if bytes.Compare(tx.Sender(), gui.addr) == 0 && object.Nonce <= tx.Nonce { gui.win.Root().Call("addTx", ethpub.NewPTx(tx)) gui.txDb.Put(tx.Hash(), tx.RlpEncode()) - object.Nonce += 1 - state.SetStateObject(object) + /* + object.Nonce += 1 + state.SetStateObject(object) + */ unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) } else if bytes.Compare(tx.Recipient, gui.addr) == 0 { diff --git a/ethereal/ui/html_container.go b/ethereal/ui/html_container.go index 4f12aaaf6..3867c0353 100644 --- a/ethereal/ui/html_container.go +++ b/ethereal/ui/html_container.go @@ -6,6 +6,12 @@ import ( "github.com/ethereum/eth-go/ethpub" "github.com/ethereum/eth-go/ethutil" "github.com/go-qml/qml" + "github.com/howeyc/fsnotify" + "io/ioutil" + "log" + "net/url" + "os" + "path" "path/filepath" ) @@ -15,6 +21,7 @@ type HtmlApplication struct { engine *qml.Engine lib *UiLib path string + watcher *fsnotify.Watcher } func NewHtmlApplication(path string, lib *UiLib) *HtmlApplication { @@ -47,6 +54,59 @@ func (app *HtmlApplication) Create() error { return nil } +func (app *HtmlApplication) RootFolder() string { + folder, err := url.Parse(app.path) + if err != nil { + return "" + } + return path.Dir(folder.RequestURI()) +} +func (app *HtmlApplication) RecursiveFolders() []os.FileInfo { + files, _ := ioutil.ReadDir(app.RootFolder()) + var folders []os.FileInfo + for _, file := range files { + if file.IsDir() { + folders = append(folders, file) + } + } + return folders +} + +func (app *HtmlApplication) NewWatcher(quitChan chan bool) { + var err error + + app.watcher, err = fsnotify.NewWatcher() + if err != nil { + return + } + err = app.watcher.Watch(app.RootFolder()) + if err != nil { + log.Fatal(err) + } + for _, folder := range app.RecursiveFolders() { + fullPath := app.RootFolder() + "/" + folder.Name() + app.watcher.Watch(fullPath) + } + + go func() { + out: + for { + select { + case <-quitChan: + app.watcher.Close() + break out + case <-app.watcher.Event: + //ethutil.Config.Log.Debugln("Got event:", ev) + app.webView.Call("reload") + case err := <-app.watcher.Error: + // TODO: Do something here + ethutil.Config.Log.Infoln("Watcher error:", err) + } + } + }() + +} + func (app *HtmlApplication) Engine() *qml.Engine { return app.engine } |