diff options
Diffstat (limited to 'cmd/mist/ui_lib.go')
-rw-r--r-- | cmd/mist/ui_lib.go | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/cmd/mist/ui_lib.go b/cmd/mist/ui_lib.go index bb978707d..4e480144f 100644 --- a/cmd/mist/ui_lib.go +++ b/cmd/mist/ui_lib.go @@ -29,6 +29,7 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" "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" @@ -55,10 +56,15 @@ type UiLib struct { jsEngine *javascript.JSRE filterCallbacks map[int][]int + + miner *miner.Miner } func NewUiLib(engine *qml.Engine, eth *eth.Ethereum, assetPath string) *UiLib { - return &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{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.miner = miner.New(eth.KeyManager().Address(), eth) + + return lib } func (self *UiLib) Notef(args []interface{}) { @@ -223,7 +229,11 @@ func (self *UiLib) NewFilter(object map[string]interface{}) (id int) { func (self *UiLib) NewFilterString(typ string) (id int) { filter := chain.NewFilter(self.eth) filter.BlockCallback = func(block *chain.Block) { - self.win.Root().Call("invokeFilterCallback", "{}", id) + if self.win != nil && self.win.Root() != nil { + self.win.Root().Call("invokeFilterCallback", "{}", id) + } else { + fmt.Println("QML is lagging") + } } id = self.eth.InstallFilter(filter) return id @@ -328,3 +338,33 @@ func (self *UiLib) Call(params map[string]interface{}) (string, error) { object["data"], ) } + +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 +} + +func (self *UiLib) RemoveLocalTransaction(id int) { + self.miner.RemoveLocalTx(id) +} + +func (self *UiLib) SetGasPrice(price string) { + self.miner.MinAcceptedGasPrice = ethutil.Big(price) +} + +func (self *UiLib) ToggleMining() bool { + if !self.miner.Mining() { + self.miner.Start() + + return true + } else { + self.miner.Stop() + + return false + } +} |