88 "github.com/ethereum/eth-go/ethdb"
99 "github.com/ethereum/eth-go/ethlog"
1010 "github.com/ethereum/eth-go/ethpub"
11+ "github.com/ethereum/eth-go/ethreact"
1112 "github.com/ethereum/eth-go/ethutil"
1213 "github.com/ethereum/eth-go/ethwire"
1314 "github.com/ethereum/go-ethereum/utils"
@@ -143,7 +144,7 @@ func (gui *Gui) showWallet(context *qml.Context) (*qml.Window, error) {
143144 gui .readPreviousTransactions ()
144145 gui .setPeerInfo ()
145146
146- go gui .update ()
147+ gui .update ()
147148
148149 return win , nil
149150}
@@ -266,20 +267,10 @@ func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) {
266267func (gui * Gui ) update () {
267268 reactor := gui .eth .Reactor ()
268269
269- blockChan := make (chan ethutil.React , 1 )
270- txChan := make (chan ethutil.React , 1 )
271- objectChan := make (chan ethutil.React , 1 )
272- peerChan := make (chan ethutil.React , 1 )
273-
274- reactor .Subscribe ("newBlock" , blockChan )
275- reactor .Subscribe ("newTx:pre" , txChan )
276- reactor .Subscribe ("newTx:post" , txChan )
277-
278- nameReg := ethpub .EthereumConfig (gui .eth .StateManager ()).NameReg ()
279- if nameReg != nil {
280- reactor .Subscribe ("object:" + string (nameReg .Address ()), objectChan )
281- }
282- reactor .Subscribe ("peerList" , peerChan )
270+ blockChan := make (chan ethreact.Event )
271+ txChan := make (chan ethreact.Event )
272+ objectChan := make (chan ethreact.Event )
273+ peerChan := make (chan ethreact.Event )
283274
284275 ticker := time .NewTicker (5 * time .Second )
285276
@@ -288,54 +279,66 @@ func (gui *Gui) update() {
288279 unconfirmedFunds := new (big.Int )
289280 gui .win .Root ().Call ("setWalletValue" , fmt .Sprintf ("%v" , ethutil .CurrencyToString (state .GetAccount (gui .address ()).Amount )))
290281
291- for {
292- select {
293- case b := <- blockChan :
294- block := b .Resource .(* ethchain.Block )
295- gui .processBlock (block , false )
296- if bytes .Compare (block .Coinbase , gui .address ()) == 0 {
297- gui .setWalletValue (gui .eth .StateManager ().CurrentState ().GetAccount (gui .address ()).Amount , nil )
298- }
282+ go func () {
283+ for {
284+ select {
285+ case b := <- blockChan :
286+ block := b .Resource .(* ethchain.Block )
287+ gui .processBlock (block , false )
288+ if bytes .Compare (block .Coinbase , gui .address ()) == 0 {
289+ gui .setWalletValue (gui .eth .StateManager ().CurrentState ().GetAccount (gui .address ()).Amount , nil )
290+ }
299291
300- case txMsg := <- txChan :
301- tx := txMsg .Resource .(* ethchain.Transaction )
292+ case txMsg := <- txChan :
293+ tx := txMsg .Resource .(* ethchain.Transaction )
302294
303- if txMsg .Event == "newTx:pre" {
304- object := state .GetAccount (gui .address ())
295+ if txMsg .Name == "newTx:pre" {
296+ object := state .GetAccount (gui .address ())
305297
306- if bytes .Compare (tx .Sender (), gui .address ()) == 0 {
307- gui .win .Root ().Call ("addTx" , ethpub .NewPTx (tx ), "send" )
308- gui .txDb .Put (tx .Hash (), tx .RlpEncode ())
298+ if bytes .Compare (tx .Sender (), gui .address ()) == 0 {
299+ gui .win .Root ().Call ("addTx" , ethpub .NewPTx (tx ), "send" )
300+ gui .txDb .Put (tx .Hash (), tx .RlpEncode ())
309301
310- unconfirmedFunds .Sub (unconfirmedFunds , tx .Value )
311- } else if bytes .Compare (tx .Recipient , gui .address ()) == 0 {
312- gui .win .Root ().Call ("addTx" , ethpub .NewPTx (tx ), "recv" )
313- gui .txDb .Put (tx .Hash (), tx .RlpEncode ())
302+ unconfirmedFunds .Sub (unconfirmedFunds , tx .Value )
303+ } else if bytes .Compare (tx .Recipient , gui .address ()) == 0 {
304+ gui .win .Root ().Call ("addTx" , ethpub .NewPTx (tx ), "recv" )
305+ gui .txDb .Put (tx .Hash (), tx .RlpEncode ())
314306
315- unconfirmedFunds .Add (unconfirmedFunds , tx .Value )
316- }
307+ unconfirmedFunds .Add (unconfirmedFunds , tx .Value )
308+ }
317309
318- gui .setWalletValue (object .Amount , unconfirmedFunds )
319- } else {
320- object := state .GetAccount (gui .address ())
321- if bytes .Compare (tx .Sender (), gui .address ()) == 0 {
322- object .SubAmount (tx .Value )
323- } else if bytes .Compare (tx .Recipient , gui .address ()) == 0 {
324- object .AddAmount (tx .Value )
325- }
310+ gui .setWalletValue (object .Amount , unconfirmedFunds )
311+ } else {
312+ object := state .GetAccount (gui .address ())
313+ if bytes .Compare (tx .Sender (), gui .address ()) == 0 {
314+ object .SubAmount (tx .Value )
315+ } else if bytes .Compare (tx .Recipient , gui .address ()) == 0 {
316+ object .AddAmount (tx .Value )
317+ }
326318
327- gui .setWalletValue (object .Amount , nil )
319+ gui .setWalletValue (object .Amount , nil )
328320
329- state .UpdateStateObject (object )
321+ state .UpdateStateObject (object )
322+ }
323+ case <- objectChan :
324+ gui .loadAddressBook ()
325+ case <- peerChan :
326+ gui .setPeerInfo ()
327+ case <- ticker .C :
328+ gui .setPeerInfo ()
330329 }
331- case <- objectChan :
332- gui .loadAddressBook ()
333- case <- peerChan :
334- gui .setPeerInfo ()
335- case <- ticker .C :
336- gui .setPeerInfo ()
337330 }
331+ }()
332+ reactor .Subscribe ("newBlock" , blockChan )
333+ reactor .Subscribe ("newTx:pre" , txChan )
334+ reactor .Subscribe ("newTx:post" , txChan )
335+
336+ nameReg := ethpub .EthereumConfig (gui .eth .StateManager ()).NameReg ()
337+ if nameReg != nil {
338+ reactor .Subscribe ("object:" + string (nameReg .Address ()), objectChan )
338339 }
340+ reactor .Subscribe ("peerList" , peerChan )
341+
339342}
340343
341344func (gui * Gui ) setPeerInfo () {
0 commit comments