// Simple go routine function that updates the list of peers in the GUI func (ui *Gui) update() { txChan := make(chan ethchain.TxMsg, 1) ui.eth.TxPool().Subscribe(txChan) account := ui.eth.StateManager().GetAddrState(ui.addr).Account unconfirmedFunds := new(big.Int) ui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(account.Amount))) for { select { case txMsg := <-txChan: tx := txMsg.Tx if txMsg.Type == ethchain.TxPre { if bytes.Compare(tx.Sender(), ui.addr) == 0 { ui.win.Root().Call("addTx", NewTxFromTransaction(tx)) ui.txDb.Put(tx.Hash(), tx.RlpEncode()) ui.eth.StateManager().GetAddrState(ui.addr).Nonce += 1 unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) } else if bytes.Compare(tx.Recipient, ui.addr) == 0 { ui.win.Root().Call("addTx", NewTxFromTransaction(tx)) ui.txDb.Put(tx.Hash(), tx.RlpEncode()) unconfirmedFunds.Add(unconfirmedFunds, tx.Value) } pos := "+" if unconfirmedFunds.Cmp(big.NewInt(0)) >= 0 { pos = "-" } val := ethutil.CurrencyToString(new(big.Int).Abs(ethutil.BigCopy(unconfirmedFunds))) str := fmt.Sprintf("%v (%s %v)", ethutil.CurrencyToString(account.Amount), pos, val) ui.win.Root().Call("setWalletValue", str) } else { amount := account.Amount if bytes.Compare(tx.Sender(), ui.addr) == 0 { amount.Sub(account.Amount, tx.Value) } else if bytes.Compare(tx.Recipient, ui.addr) == 0 { amount.Add(account.Amount, tx.Value) } ui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(amount))) } } /* accountAmount := ui.eth.BlockManager.GetAddrState(ui.addr).Account.Amount ui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", accountAmount)) ui.win.Root().Call("setPeers", fmt.Sprintf("%d / %d", ui.eth.Peers().Len(), ui.eth.MaxPeers)) time.Sleep(1 * time.Second) */ } }
func (gui *Gui) setWalletValue(amount, unconfirmedFunds *big.Int) { var str string if unconfirmedFunds != nil { pos := "+" if unconfirmedFunds.Cmp(big.NewInt(0)) < 0 { pos = "-" } val := ethutil.CurrencyToString(new(big.Int).Abs(ethutil.BigCopy(unconfirmedFunds))) str = fmt.Sprintf("%v (%s %v)", ethutil.CurrencyToString(amount), pos, val) } else { str = fmt.Sprintf("%v", ethutil.CurrencyToString(amount)) } gui.win.Root().Call("setWalletValue", str) }