forked from cerc-io/plugeth
Merge branch 'ethersphere-feature/ethutil-refactor' into develop
This commit is contained in:
commit
3c319f93f2
@ -1,9 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"github.com/ethereum/eth-go/ethchain"
|
"github.com/ethereum/eth-go/ethchain"
|
||||||
"github.com/ethereum/eth-go/ethpub"
|
"github.com/ethereum/eth-go/ethpub"
|
||||||
|
"github.com/ethereum/eth-go/ethreact"
|
||||||
"github.com/ethereum/eth-go/ethstate"
|
"github.com/ethereum/eth-go/ethstate"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"github.com/go-qml/qml"
|
"github.com/go-qml/qml"
|
||||||
@ -25,8 +25,8 @@ type AppContainer interface {
|
|||||||
type ExtApplication struct {
|
type ExtApplication struct {
|
||||||
*ethpub.PEthereum
|
*ethpub.PEthereum
|
||||||
|
|
||||||
blockChan chan ethutil.React
|
blockChan chan ethreact.Event
|
||||||
changeChan chan ethutil.React
|
changeChan chan ethreact.Event
|
||||||
quitChan chan bool
|
quitChan chan bool
|
||||||
watcherQuitChan chan bool
|
watcherQuitChan chan bool
|
||||||
|
|
||||||
@ -38,8 +38,8 @@ type ExtApplication struct {
|
|||||||
func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication {
|
func NewExtApplication(container AppContainer, lib *UiLib) *ExtApplication {
|
||||||
app := &ExtApplication{
|
app := &ExtApplication{
|
||||||
ethpub.NewPEthereum(lib.eth),
|
ethpub.NewPEthereum(lib.eth),
|
||||||
make(chan ethutil.React, 1),
|
make(chan ethreact.Event, 100),
|
||||||
make(chan ethutil.React, 1),
|
make(chan ethreact.Event, 100),
|
||||||
make(chan bool),
|
make(chan bool),
|
||||||
make(chan bool),
|
make(chan bool),
|
||||||
container,
|
container,
|
||||||
@ -58,8 +58,7 @@ func (app *ExtApplication) run() {
|
|||||||
|
|
||||||
err := app.container.Create()
|
err := app.container.Create()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
logger.Errorln(err)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/ethereum/eth-go/ethlog"
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
"github.com/ethereum/eth-go/ethminer"
|
"github.com/ethereum/eth-go/ethminer"
|
||||||
"github.com/ethereum/eth-go/ethpub"
|
"github.com/ethereum/eth-go/ethpub"
|
||||||
|
"github.com/ethereum/eth-go/ethreact"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"github.com/ethereum/eth-go/ethwire"
|
"github.com/ethereum/eth-go/ethwire"
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
@ -151,7 +152,7 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) {
|
|||||||
gui.readPreviousTransactions()
|
gui.readPreviousTransactions()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go gui.update()
|
gui.update()
|
||||||
|
|
||||||
return win, nil
|
return win, nil
|
||||||
}
|
}
|
||||||
@ -284,30 +285,16 @@ func (self *Gui) getObjectByName(objectName string) qml.Object {
|
|||||||
|
|
||||||
// Simple go routine function that updates the list of peers in the GUI
|
// Simple go routine function that updates the list of peers in the GUI
|
||||||
func (gui *Gui) update() {
|
func (gui *Gui) update() {
|
||||||
reactor := gui.eth.Reactor()
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
blockChan = make(chan ethutil.React, 1)
|
blockChan = make(chan ethreact.Event, 100)
|
||||||
txChan = make(chan ethutil.React, 1)
|
txChan = make(chan ethreact.Event, 100)
|
||||||
objectChan = make(chan ethutil.React, 1)
|
objectChan = make(chan ethreact.Event, 100)
|
||||||
peerChan = make(chan ethutil.React, 1)
|
peerChan = make(chan ethreact.Event, 100)
|
||||||
chainSyncChan = make(chan ethutil.React, 1)
|
chainSyncChan = make(chan ethreact.Event, 100)
|
||||||
miningChan = make(chan ethutil.React, 1)
|
miningChan = make(chan ethreact.Event, 100)
|
||||||
)
|
)
|
||||||
|
|
||||||
reactor.Subscribe("newBlock", blockChan)
|
|
||||||
reactor.Subscribe("newTx:pre", txChan)
|
|
||||||
reactor.Subscribe("newTx:post", txChan)
|
|
||||||
reactor.Subscribe("chainSync", chainSyncChan)
|
|
||||||
reactor.Subscribe("miner:start", miningChan)
|
|
||||||
reactor.Subscribe("miner:stop", miningChan)
|
|
||||||
|
|
||||||
nameReg := ethpub.EthereumConfig(gui.eth.StateManager()).NameReg()
|
|
||||||
if nameReg != nil {
|
|
||||||
reactor.Subscribe("object:"+string(nameReg.Address()), objectChan)
|
|
||||||
}
|
|
||||||
reactor.Subscribe("peerList", peerChan)
|
|
||||||
|
|
||||||
peerUpdateTicker := time.NewTicker(5 * time.Second)
|
peerUpdateTicker := time.NewTicker(5 * time.Second)
|
||||||
generalUpdateTicker := time.NewTicker(1 * time.Second)
|
generalUpdateTicker := time.NewTicker(1 * time.Second)
|
||||||
|
|
||||||
@ -319,6 +306,7 @@ func (gui *Gui) update() {
|
|||||||
|
|
||||||
lastBlockLabel := gui.getObjectByName("lastBlockLabel")
|
lastBlockLabel := gui.getObjectByName("lastBlockLabel")
|
||||||
|
|
||||||
|
go func() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case b := <-blockChan:
|
case b := <-blockChan:
|
||||||
@ -327,11 +315,10 @@ func (gui *Gui) update() {
|
|||||||
if bytes.Compare(block.Coinbase, gui.address()) == 0 {
|
if bytes.Compare(block.Coinbase, gui.address()) == 0 {
|
||||||
gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.address()).Balance, nil)
|
gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.address()).Balance, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
case txMsg := <-txChan:
|
case txMsg := <-txChan:
|
||||||
tx := txMsg.Resource.(*ethchain.Transaction)
|
tx := txMsg.Resource.(*ethchain.Transaction)
|
||||||
|
|
||||||
if txMsg.Event == "newTx:pre" {
|
if txMsg.Name == "newTx:pre" {
|
||||||
object := state.GetAccount(gui.address())
|
object := state.GetAccount(gui.address())
|
||||||
|
|
||||||
if bytes.Compare(tx.Sender(), gui.address()) == 0 {
|
if bytes.Compare(tx.Sender(), gui.address()) == 0 {
|
||||||
@ -370,12 +357,11 @@ func (gui *Gui) update() {
|
|||||||
case <-peerUpdateTicker.C:
|
case <-peerUpdateTicker.C:
|
||||||
gui.setPeerInfo()
|
gui.setPeerInfo()
|
||||||
case msg := <-miningChan:
|
case msg := <-miningChan:
|
||||||
if msg.Event == "miner:start" {
|
if msg.Name == "miner:start" {
|
||||||
gui.miner = msg.Resource.(*ethminer.Miner)
|
gui.miner = msg.Resource.(*ethminer.Miner)
|
||||||
} else {
|
} else {
|
||||||
gui.miner = nil
|
gui.miner = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-generalUpdateTicker.C:
|
case <-generalUpdateTicker.C:
|
||||||
statusText := "#" + gui.eth.BlockChain().CurrentBlock.Number.String()
|
statusText := "#" + gui.eth.BlockChain().CurrentBlock.Number.String()
|
||||||
if gui.miner != nil {
|
if gui.miner != nil {
|
||||||
@ -387,6 +373,22 @@ func (gui *Gui) update() {
|
|||||||
lastBlockLabel.Set("text", statusText)
|
lastBlockLabel.Set("text", statusText)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
reactor := gui.eth.Reactor()
|
||||||
|
|
||||||
|
reactor.Subscribe("newBlock", blockChan)
|
||||||
|
reactor.Subscribe("newTx:pre", txChan)
|
||||||
|
reactor.Subscribe("newTx:post", txChan)
|
||||||
|
reactor.Subscribe("chainSync", chainSyncChan)
|
||||||
|
reactor.Subscribe("miner:start", miningChan)
|
||||||
|
reactor.Subscribe("miner:stop", miningChan)
|
||||||
|
|
||||||
|
nameReg := ethpub.EthereumConfig(gui.eth.StateManager()).NameReg()
|
||||||
|
if nameReg != nil {
|
||||||
|
reactor.Subscribe("object:"+string(nameReg.Address()), objectChan)
|
||||||
|
}
|
||||||
|
reactor.Subscribe("peerList", peerChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) setPeerInfo() {
|
func (gui *Gui) setPeerInfo() {
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/ethereum/eth-go/ethchain"
|
"github.com/ethereum/eth-go/ethchain"
|
||||||
"github.com/ethereum/eth-go/ethlog"
|
"github.com/ethereum/eth-go/ethlog"
|
||||||
"github.com/ethereum/eth-go/ethpub"
|
"github.com/ethereum/eth-go/ethpub"
|
||||||
|
"github.com/ethereum/eth-go/ethreact"
|
||||||
"github.com/ethereum/eth-go/ethstate"
|
"github.com/ethereum/eth-go/ethstate"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
@ -23,8 +24,8 @@ type JSRE struct {
|
|||||||
vm *otto.Otto
|
vm *otto.Otto
|
||||||
lib *ethpub.PEthereum
|
lib *ethpub.PEthereum
|
||||||
|
|
||||||
blockChan chan ethutil.React
|
blockChan chan ethreact.Event
|
||||||
changeChan chan ethutil.React
|
changeChan chan ethreact.Event
|
||||||
quitChan chan bool
|
quitChan chan bool
|
||||||
|
|
||||||
objectCb map[string][]otto.Value
|
objectCb map[string][]otto.Value
|
||||||
@ -49,8 +50,8 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
|
|||||||
ethereum,
|
ethereum,
|
||||||
otto.New(),
|
otto.New(),
|
||||||
ethpub.NewPEthereum(ethereum),
|
ethpub.NewPEthereum(ethereum),
|
||||||
make(chan ethutil.React, 1),
|
make(chan ethreact.Event, 10),
|
||||||
make(chan ethutil.React, 1),
|
make(chan ethreact.Event, 10),
|
||||||
make(chan bool),
|
make(chan bool),
|
||||||
make(map[string][]otto.Value),
|
make(map[string][]otto.Value),
|
||||||
}
|
}
|
||||||
@ -65,6 +66,10 @@ func NewJSRE(ethereum *eth.Ethereum) *JSRE {
|
|||||||
// We have to make sure that, whoever calls this, calls "Stop"
|
// We have to make sure that, whoever calls this, calls "Stop"
|
||||||
go re.mainLoop()
|
go re.mainLoop()
|
||||||
|
|
||||||
|
// Subscribe to events
|
||||||
|
reactor := ethereum.Reactor()
|
||||||
|
reactor.Subscribe("newBlock", re.blockChan)
|
||||||
|
|
||||||
re.Bind("eth", &JSEthereum{re.lib, re.vm})
|
re.Bind("eth", &JSEthereum{re.lib, re.vm})
|
||||||
|
|
||||||
re.initStdFuncs()
|
re.initStdFuncs()
|
||||||
@ -109,10 +114,6 @@ func (self *JSRE) Stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *JSRE) mainLoop() {
|
func (self *JSRE) mainLoop() {
|
||||||
// Subscribe to events
|
|
||||||
reactor := self.ethereum.Reactor()
|
|
||||||
reactor.Subscribe("newBlock", self.blockChan)
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
10
utils/cmd.go
10
utils/cmd.go
@ -127,6 +127,7 @@ func NewDatabase() ethutil.Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewClientIdentity(clientIdentifier, version, customIdentifier string) *ethwire.SimpleClientIdentity {
|
func NewClientIdentity(clientIdentifier, version, customIdentifier string) *ethwire.SimpleClientIdentity {
|
||||||
|
logger.Infoln("identity created")
|
||||||
return ethwire.NewSimpleClientIdentity(clientIdentifier, version, customIdentifier)
|
return ethwire.NewSimpleClientIdentity(clientIdentifier, version, customIdentifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,21 +244,18 @@ func GetMiner() *ethminer.Miner {
|
|||||||
func StartMining(ethereum *eth.Ethereum) bool {
|
func StartMining(ethereum *eth.Ethereum) bool {
|
||||||
if !ethereum.Mining {
|
if !ethereum.Mining {
|
||||||
ethereum.Mining = true
|
ethereum.Mining = true
|
||||||
|
|
||||||
addr := ethereum.KeyManager().Address()
|
addr := ethereum.KeyManager().Address()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
logger.Infoln("Start mining")
|
||||||
if miner == nil {
|
if miner == nil {
|
||||||
miner = ethminer.NewDefaultMiner(addr, ethereum)
|
miner = ethminer.NewDefaultMiner(addr, ethereum)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give it some time to connect with peers
|
// Give it some time to connect with peers
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
for !ethereum.IsUpToDate() {
|
for !ethereum.IsUpToDate() {
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.Infoln("Miner started")
|
|
||||||
miner.Start()
|
miner.Start()
|
||||||
}()
|
}()
|
||||||
RegisterInterrupt(func(os.Signal) {
|
RegisterInterrupt(func(os.Signal) {
|
||||||
@ -271,9 +269,7 @@ func StartMining(ethereum *eth.Ethereum) bool {
|
|||||||
func StopMining(ethereum *eth.Ethereum) bool {
|
func StopMining(ethereum *eth.Ethereum) bool {
|
||||||
if ethereum.Mining && miner != nil {
|
if ethereum.Mining && miner != nil {
|
||||||
miner.Stop()
|
miner.Stop()
|
||||||
|
logger.Infoln("Stopped mining")
|
||||||
logger.Infoln("Miner stopped")
|
|
||||||
|
|
||||||
ethereum.Mining = false
|
ethereum.Mining = false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user