|
|
@ -8,6 +8,7 @@ import ( |
|
|
|
"github.com/ethereum/eth-go/ethdb" |
|
|
|
"github.com/ethereum/eth-go/ethdb" |
|
|
|
"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/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" |
|
|
@ -143,7 +144,7 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) { |
|
|
|
gui.readPreviousTransactions() |
|
|
|
gui.readPreviousTransactions() |
|
|
|
gui.setPeerInfo() |
|
|
|
gui.setPeerInfo() |
|
|
|
|
|
|
|
|
|
|
|
go gui.update() |
|
|
|
gui.update() |
|
|
|
|
|
|
|
|
|
|
|
return win, nil |
|
|
|
return win, nil |
|
|
|
} |
|
|
|
} |
|
|
@ -266,20 +267,10 @@ func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) { |
|
|
|
func (gui *Gui) update() { |
|
|
|
func (gui *Gui) update() { |
|
|
|
reactor := gui.eth.Reactor() |
|
|
|
reactor := gui.eth.Reactor() |
|
|
|
|
|
|
|
|
|
|
|
blockChan := make(chan ethutil.React, 1) |
|
|
|
blockChan := make(chan ethreact.Event) |
|
|
|
txChan := make(chan ethutil.React, 1) |
|
|
|
txChan := make(chan ethreact.Event) |
|
|
|
objectChan := make(chan ethutil.React, 1) |
|
|
|
objectChan := make(chan ethreact.Event) |
|
|
|
peerChan := make(chan ethutil.React, 1) |
|
|
|
peerChan := make(chan ethreact.Event) |
|
|
|
|
|
|
|
|
|
|
|
reactor.Subscribe("newBlock", blockChan) |
|
|
|
|
|
|
|
reactor.Subscribe("newTx:pre", txChan) |
|
|
|
|
|
|
|
reactor.Subscribe("newTx:post", txChan) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nameReg := ethpub.EthereumConfig(gui.eth.StateManager()).NameReg() |
|
|
|
|
|
|
|
if nameReg != nil { |
|
|
|
|
|
|
|
reactor.Subscribe("object:"+string(nameReg.Address()), objectChan) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
reactor.Subscribe("peerList", peerChan) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ticker := time.NewTicker(5 * time.Second) |
|
|
|
ticker := time.NewTicker(5 * time.Second) |
|
|
|
|
|
|
|
|
|
|
@ -288,54 +279,66 @@ func (gui *Gui) update() { |
|
|
|
unconfirmedFunds := new(big.Int) |
|
|
|
unconfirmedFunds := new(big.Int) |
|
|
|
gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Amount))) |
|
|
|
gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Amount))) |
|
|
|
|
|
|
|
|
|
|
|
for { |
|
|
|
go func() { |
|
|
|
select { |
|
|
|
for { |
|
|
|
case b := <-blockChan: |
|
|
|
select { |
|
|
|
block := b.Resource.(*ethchain.Block) |
|
|
|
case b := <-blockChan: |
|
|
|
gui.processBlock(block, false) |
|
|
|
block := b.Resource.(*ethchain.Block) |
|
|
|
if bytes.Compare(block.Coinbase, gui.address()) == 0 { |
|
|
|
gui.processBlock(block, false) |
|
|
|
gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.address()).Amount, nil) |
|
|
|
if bytes.Compare(block.Coinbase, gui.address()) == 0 { |
|
|
|
} |
|
|
|
gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.address()).Amount, 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 { |
|
|
|
gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "send") |
|
|
|
gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "send") |
|
|
|
gui.txDb.Put(tx.Hash(), tx.RlpEncode()) |
|
|
|
gui.txDb.Put(tx.Hash(), tx.RlpEncode()) |
|
|
|
|
|
|
|
|
|
|
|
unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) |
|
|
|
unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) |
|
|
|
} else if bytes.Compare(tx.Recipient, gui.address()) == 0 { |
|
|
|
} else if bytes.Compare(tx.Recipient, gui.address()) == 0 { |
|
|
|
gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "recv") |
|
|
|
gui.win.Root().Call("addTx", ethpub.NewPTx(tx), "recv") |
|
|
|
gui.txDb.Put(tx.Hash(), tx.RlpEncode()) |
|
|
|
gui.txDb.Put(tx.Hash(), tx.RlpEncode()) |
|
|
|
|
|
|
|
|
|
|
|
unconfirmedFunds.Add(unconfirmedFunds, tx.Value) |
|
|
|
unconfirmedFunds.Add(unconfirmedFunds, tx.Value) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
gui.setWalletValue(object.Amount, unconfirmedFunds) |
|
|
|
gui.setWalletValue(object.Amount, unconfirmedFunds) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
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 { |
|
|
|
object.SubAmount(tx.Value) |
|
|
|
object.SubAmount(tx.Value) |
|
|
|
} else if bytes.Compare(tx.Recipient, gui.address()) == 0 { |
|
|
|
} else if bytes.Compare(tx.Recipient, gui.address()) == 0 { |
|
|
|
object.AddAmount(tx.Value) |
|
|
|
object.AddAmount(tx.Value) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
gui.setWalletValue(object.Amount, nil) |
|
|
|
gui.setWalletValue(object.Amount, nil) |
|
|
|
|
|
|
|
|
|
|
|
state.UpdateStateObject(object) |
|
|
|
state.UpdateStateObject(object) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case <-objectChan: |
|
|
|
|
|
|
|
gui.loadAddressBook() |
|
|
|
|
|
|
|
case <-peerChan: |
|
|
|
|
|
|
|
gui.setPeerInfo() |
|
|
|
|
|
|
|
case <-ticker.C: |
|
|
|
|
|
|
|
gui.setPeerInfo() |
|
|
|
} |
|
|
|
} |
|
|
|
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) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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() { |
|
|
|