Skip to content

Commit

Permalink
Update wallet value for coinbase rewards. Implements #44 & #43
Browse files Browse the repository at this point in the history
  • Loading branch information
obscuren committed May 14, 2014
1 parent f18ec51 commit 9a05702
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
38 changes: 29 additions & 9 deletions ethereal/ui/gui.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,29 @@ func (gui *Gui) processBlock(block *ethchain.Block) {
gui.win.Root().Call("addBlock", ethpub.NewPBlock(block))
}

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)
}

// Simple go routine function that updates the list of peers in the GUI
func (gui *Gui) update() {
blockChan := make(chan ethutil.React, 1)
reactor := gui.eth.Reactor()

reactor.Subscribe("newBlock", blockChan)

txChan := make(chan ethchain.TxMsg, 1)
gui.eth.TxPool().Subscribe(txChan)

Expand All @@ -170,6 +191,12 @@ func (gui *Gui) update() {

for {
select {
case b := <-blockChan:
block := b.Resource.(*ethchain.Block)
if bytes.Compare(block.Coinbase, gui.addr) == 0 {
gui.setWalletValue(gui.eth.StateManager().ProcState().GetAccount(gui.addr).Amount, nil)
}

case txMsg := <-txChan:
tx := txMsg.Tx

Expand All @@ -191,14 +218,7 @@ func (gui *Gui) update() {
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(object.Amount), pos, val)

gui.win.Root().Call("setWalletValue", str)
gui.setWalletValue(object.Amount, unconfirmedFunds)
} else {
object := state.GetAccount(gui.addr)
if bytes.Compare(tx.Sender(), gui.addr) == 0 {
Expand All @@ -207,7 +227,7 @@ func (gui *Gui) update() {
object.AddAmount(tx.Value)
}

gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(object.Amount)))
gui.setWalletValue(object.Amount, nil)

state.SetStateObject(object)
}
Expand Down
5 changes: 2 additions & 3 deletions ethereum/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ func main() {
log.SetOutput(logfile)
logSys = log.New(logfile, "", flags)
logger.AddLogSystem(logSys)
}
/*else {
} else {
logSys = log.New(os.Stdout, "", flags)
}*/
}

ethchain.InitFees()

Expand Down

0 comments on commit 9a05702

Please sign in to comment.