diff options
Diffstat (limited to 'cmd/mist/ui_lib.go')
-rw-r--r-- | cmd/mist/ui_lib.go | 174 |
1 files changed, 70 insertions, 104 deletions
diff --git a/cmd/mist/ui_lib.go b/cmd/mist/ui_lib.go index 0aabb87d0..ab48386f4 100644 --- a/cmd/mist/ui_lib.go +++ b/cmd/mist/ui_lib.go @@ -1,41 +1,38 @@ -// 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 - +/* + This file is part of go-ethereum + + 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> + */ package main import ( - "bytes" "fmt" + "io/ioutil" "path" - "strconv" - "strings" - "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/event/filter" "github.com/ethereum/go-ethereum/javascript" "github.com/ethereum/go-ethereum/miner" - "github.com/ethereum/go-ethereum/state" - "github.com/ethereum/go-ethereum/ui/qt" "github.com/ethereum/go-ethereum/xeth" - "gopkg.in/qml.v1" + "github.com/obscuren/qml" ) type memAddr struct { @@ -45,7 +42,7 @@ type memAddr struct { // UI Library that has some basic functionality exposed type UiLib struct { - *xeth.JSXEth + *xeth.XEth engine *qml.Engine eth *eth.Ethereum connected bool @@ -64,9 +61,10 @@ type UiLib struct { } func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { - lib := &UiLib{JSXEth: xeth.NewJSXEth(eth), engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(eth), filterCallbacks: make(map[int][]int)} //, filters: make(map[int]*xeth.JSFilter)} + lib := &UiLib{XEth: xeth.New(eth), engine: engine, eth: eth, assetPath: assetPath, jsEngine: javascript.NewJSRE(eth), filterCallbacks: make(map[int][]int)} //, filters: make(map[int]*xeth.JSFilter)} lib.miner = miner.New(eth.KeyManager().Address(), eth) lib.filterManager = filter.NewFilterManager(eth.EventMux()) + go lib.filterManager.Start() return lib } @@ -75,56 +73,6 @@ func (self *UiLib) Notef(args []interface{}) { guilogger.Infoln(args...) } -func (self *UiLib) LookupDomain(domain string) string { - world := self.World() - - if len(domain) > 32 { - domain = string(crypto.Sha3([]byte(domain))) - } - data := world.Config().Get("DnsReg").StorageString(domain).Bytes() - - // Left padded = A record, Right padded = CNAME - if len(data) > 0 && data[0] == 0 { - data = bytes.TrimLeft(data, "\x00") - var ipSlice []string - for _, d := range data { - ipSlice = append(ipSlice, strconv.Itoa(int(d))) - } - - return strings.Join(ipSlice, ".") - } else { - data = bytes.TrimRight(data, "\x00") - - return string(data) - } -} - -func (self *UiLib) LookupName(addr string) string { - var ( - nameReg = self.World().Config().Get("NameReg") - lookup = nameReg.Storage(ethutil.Hex2Bytes(addr)) - ) - - if lookup.Len() != 0 { - return strings.Trim(lookup.Str(), "\x00") - } - - return addr -} - -func (self *UiLib) LookupAddress(name string) string { - var ( - nameReg = self.World().Config().Get("NameReg") - lookup = nameReg.Storage(ethutil.RightPadBytes([]byte(name), 32)) - ) - - if lookup.Len() != 0 { - return ethutil.Bytes2Hex(lookup.Bytes()) - } - - return "" -} - func (self *UiLib) PastPeers() *ethutil.List { return ethutil.NewList([]string{}) //return ethutil.NewList(eth.PastPeers()) @@ -188,15 +136,15 @@ func (ui *UiLib) Muted(content string) { func (ui *UiLib) Connect(button qml.Object) { if !ui.connected { - ui.eth.Start(true) + ui.eth.Start() ui.connected = true button.Set("enabled", false) } } -func (ui *UiLib) ConnectToPeer(addr string) { - if err := ui.eth.SuggestPeer(addr); err != nil { - guilogger.Infoln(err) +func (ui *UiLib) ConnectToPeer(nodeURL string) { + if err := ui.eth.SuggestPeer(nodeURL); err != nil { + guilogger.Infoln("SuggestPeer error: " + err.Error()) } } @@ -208,16 +156,16 @@ func (self *UiLib) StartDbWithContractAndData(contractHash, data string) { dbWindow := NewDebuggerWindow(self) object := self.eth.ChainManager().State().GetStateObject(ethutil.Hex2Bytes(contractHash)) if len(object.Code) > 0 { - dbWindow.SetCode("0x" + ethutil.Bytes2Hex(object.Code)) + dbWindow.SetCode(ethutil.Bytes2Hex(object.Code)) } - dbWindow.SetData("0x" + data) + dbWindow.SetData(data) dbWindow.Show() } func (self *UiLib) StartDbWithCode(code string) { dbWindow := NewDebuggerWindow(self) - dbWindow.SetCode("0x" + code) + dbWindow.SetCode(code) dbWindow.Show() } @@ -230,8 +178,7 @@ func (self *UiLib) StartDebugger() { func (self *UiLib) Transact(params map[string]interface{}) (string, error) { object := mapToTxParams(params) - return self.JSXEth.Transact( - object["from"], + return self.XEth.Transact( object["to"], object["value"], object["gas"], @@ -252,7 +199,7 @@ func (self *UiLib) Compile(code string) (string, error) { func (self *UiLib) Call(params map[string]interface{}) (string, error) { object := mapToTxParams(params) - return self.JSXEth.Execute( + return self.XEth.Execute( object["to"], object["value"], object["gas"], @@ -262,23 +209,30 @@ func (self *UiLib) Call(params map[string]interface{}) (string, error) { } func (self *UiLib) AddLocalTransaction(to, data, gas, gasPrice, value string) int { - return self.miner.AddLocalTx(&miner.LocalTx{ - To: ethutil.Hex2Bytes(to), - Data: ethutil.Hex2Bytes(data), - Gas: gas, - GasPrice: gasPrice, - Value: value, - }) - 1 + return 0 + /* + return self.miner.AddLocalTx(&miner.LocalTx{ + To: ethutil.Hex2Bytes(to), + Data: ethutil.Hex2Bytes(data), + Gas: gas, + GasPrice: gasPrice, + Value: value, + }) - 1 + */ } func (self *UiLib) RemoveLocalTransaction(id int) { - self.miner.RemoveLocalTx(id) + //self.miner.RemoveLocalTx(id) } func (self *UiLib) SetGasPrice(price string) { self.miner.MinAcceptedGasPrice = ethutil.Big(price) } +func (self *UiLib) SetExtra(extra string) { + self.miner.Extra = extra +} + func (self *UiLib) ToggleMining() bool { if !self.miner.Mining() { self.miner.Start() @@ -304,39 +258,51 @@ func (self *UiLib) ToAscii(data string) string { } /// Ethereum filter methods -func (self *UiLib) NewFilter(object map[string]interface{}) (id int) { +func (self *UiLib) NewFilter(object map[string]interface{}, view *qml.Common) (id int) { + /* TODO remove me filter := qt.NewFilterFromMap(object, self.eth) filter.MessageCallback = func(messages state.Messages) { - self.win.Root().Call("invokeFilterCallback", xeth.ToJSMessages(messages), id) + view.Call("messages", xeth.ToMessages(messages), id) } id = self.filterManager.InstallFilter(filter) return id + */ + return 0 } -func (self *UiLib) NewFilterString(typ string) (id int) { +func (self *UiLib) NewFilterString(typ string, view *qml.Common) (id int) { + /* TODO remove me filter := core.NewFilter(self.eth) filter.BlockCallback = func(block *types.Block) { - if self.win != nil && self.win.Root() != nil { - self.win.Root().Call("invokeFilterCallback", "{}", id) - } else { - fmt.Println("QML is lagging") - } + view.Call("messages", "{}", id) } id = self.filterManager.InstallFilter(filter) return id + */ + return 0 } func (self *UiLib) Messages(id int) *ethutil.List { + /* TODO remove me filter := self.filterManager.GetFilter(id) if filter != nil { - messages := xeth.ToJSMessages(filter.Find()) + messages := xeth.ToMessages(filter.Find()) return messages } + */ return ethutil.EmptyList() } +func (self *UiLib) ReadFile(p string) string { + content, err := ioutil.ReadFile(self.AssetPath(path.Join("ext", p))) + if err != nil { + guilogger.Infoln("error reading file", p, ":", err) + } + return string(content) +} + func (self *UiLib) UninstallFilter(id int) { self.filterManager.UninstallFilter(id) } |