From a5b27bbc10d6a145152fc2629043c46ef4a9ca71 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 4 Dec 2014 16:44:43 +0100 Subject: [PATCH] Improved and simplified wallet functions and behaviour --- cmd/mist/assets/qml/views/wallet.qml | 17 ++++++++++++---- cmd/mist/gui.go | 29 +++++++--------------------- core/block_manager.go | 10 ++++++---- core/transaction_pool.go | 2 +- miner/miner.go | 2 +- 5 files changed, 28 insertions(+), 32 deletions(-) diff --git a/cmd/mist/assets/qml/views/wallet.qml b/cmd/mist/assets/qml/views/wallet.qml index 9ffb1024db..ad7a110471 100644 --- a/cmd/mist/assets/qml/views/wallet.qml +++ b/cmd/mist/assets/qml/views/wallet.qml @@ -155,10 +155,14 @@ Rectangle { model: ListModel { id: txModel Component.onCompleted: { - var filter = ethx.watch({latest: -1, from: eth.key().address}); - filter.changed(addTxs) + var me = eth.key().address; + var filterTo = ethx.watch({latest: -1, to: me}); + var filterFrom = ethx.watch({latest: -1, from: me}); + filterTo.changed(addTxs) + filterFrom.changed(addTxs) - addTxs(filter.messages()) + addTxs(filterTo.messages()) + addTxs(filterFrom.messages()) } function addTxs(messages) { @@ -167,7 +171,12 @@ Rectangle { for(var i = 0; i < messages.length; i++) { var message = messages.get(i); var to = eth.lookupName(message.to); - var from = eth.lookupName(message.from); + var from; + if(message.from.length == 0) { + from = "- MINED -"; + } else { + from = eth.lookupName(message.from); + } txModel.insert(0, {num: txModel.count, from: from, to: to, value: eth.numberToHuman(message.value)}) } } diff --git a/cmd/mist/gui.go b/cmd/mist/gui.go index e58e349d17..6a28b48f9e 100644 --- a/cmd/mist/gui.go +++ b/cmd/mist/gui.go @@ -404,7 +404,6 @@ func (gui *Gui) update() { state := gui.eth.BlockManager().TransState() - unconfirmedFunds := new(big.Int) gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Balance()))) lastBlockLabel := gui.getObjectByName("lastBlockLabel") @@ -438,15 +437,15 @@ func (gui *Gui) update() { case core.TxPreEvent: tx := ev.Tx - object := state.GetAccount(gui.address()) - if bytes.Compare(tx.Sender(), gui.address()) == 0 { - unconfirmedFunds.Sub(unconfirmedFunds, tx.Value) - } else if bytes.Compare(tx.Recipient, gui.address()) == 0 { - unconfirmedFunds.Add(unconfirmedFunds, tx.Value) - } + tstate := gui.eth.BlockManager().TransState() + cstate := gui.eth.BlockManager().CurrentState() - gui.setWalletValue(object.Balance(), unconfirmedFunds) + taccount := tstate.GetAccount(gui.address()) + caccount := cstate.GetAccount(gui.address()) + unconfirmedFunds := new(big.Int).Sub(taccount.Balance(), caccount.Balance()) + + gui.setWalletValue(taccount.Balance(), unconfirmedFunds) gui.insertTransaction("pre", tx) case core.TxPostEvent: @@ -456,32 +455,18 @@ func (gui *Gui) update() { if bytes.Compare(tx.Sender(), gui.address()) == 0 { object.SubAmount(tx.Value) - //gui.getObjectByName("transactionView").Call("addTx", xeth.NewJSTx(tx), "send") gui.txDb.Put(tx.Hash(), tx.RlpEncode()) } else if bytes.Compare(tx.Recipient, gui.address()) == 0 { object.AddAmount(tx.Value) - //gui.getObjectByName("transactionView").Call("addTx", xeth.NewJSTx(tx), "recv") gui.txDb.Put(tx.Hash(), tx.RlpEncode()) } gui.setWalletValue(object.Balance(), nil) state.UpdateStateObject(object) - // case object: - // gui.loadAddressBook() - case eth.PeerListEvent: gui.setPeerInfo() - - /* - case miner.Event: - if ev.Type == miner.Started { - gui.miner = ev.Miner - } else { - gui.miner = nil - } - */ } case <-peerUpdateTicker.C: diff --git a/core/block_manager.go b/core/block_manager.go index c2ffc7ae0b..b648166ec2 100644 --- a/core/block_manager.go +++ b/core/block_manager.go @@ -123,7 +123,7 @@ func (sm *BlockManager) TransitionState(statedb *state.StateDB, parent, block *t coinbase.SetGasPool(block.CalcGasLimit(parent)) // Process the transactions on to current block - receipts, _, _, _, err = sm.ProcessTransactions(coinbase, statedb, block, parent, block.Transactions()) + receipts, _, _, _, err = sm.ApplyTransactions(coinbase, statedb, block, block.Transactions(), false) if err != nil { return nil, err } @@ -131,7 +131,7 @@ func (sm *BlockManager) TransitionState(statedb *state.StateDB, parent, block *t return receipts, nil } -func (self *BlockManager) ProcessTransactions(coinbase *state.StateObject, state *state.StateDB, block, parent *types.Block, txs types.Transactions) (types.Receipts, types.Transactions, types.Transactions, types.Transactions, error) { +func (self *BlockManager) ApplyTransactions(coinbase *state.StateObject, state *state.StateDB, block *types.Block, txs types.Transactions, transientProcess bool) (types.Receipts, types.Transactions, types.Transactions, types.Transactions, error) { var ( receipts types.Receipts handled, unhandled types.Transactions @@ -180,7 +180,9 @@ done: receipt.Bloom = types.CreateBloom(types.Receipts{receipt}) // Notify all subscribers - go self.eth.EventMux().Post(TxPostEvent{tx}) + if !transientProcess { + go self.eth.EventMux().Post(TxPostEvent{tx}) + } receipts = append(receipts, receipt) handled = append(handled, tx) @@ -378,7 +380,7 @@ func (sm *BlockManager) AccumelateRewards(statedb *state.StateDB, block, parent account.AddAmount(reward) statedb.Manifest().AddMessage(&state.Message{ - To: block.Coinbase, From: block.Coinbase, + To: block.Coinbase, Input: nil, Origin: nil, Block: block.Hash(), Timestamp: block.Time, Coinbase: block.Coinbase, Number: block.Number, diff --git a/core/transaction_pool.go b/core/transaction_pool.go index abacb14f14..c48d3d8a47 100644 --- a/core/transaction_pool.go +++ b/core/transaction_pool.go @@ -164,7 +164,7 @@ func (self *TxPool) Add(tx *types.Transaction) error { txplogger.Debugf("(t) %x => %x (%v) %x\n", tx.Sender()[:4], tmp, tx.Value, tx.Hash()) // Notify the subscribers - self.Ethereum.EventMux().Post(TxPreEvent{tx}) + go self.Ethereum.EventMux().Post(TxPreEvent{tx}) return nil } diff --git a/miner/miner.go b/miner/miner.go index 589144c0c7..f9b8a9c227 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -192,7 +192,7 @@ func (self *Miner) mine() { // Accumulate all valid transactions and apply them to the new state // Error may be ignored. It's not important during mining - receipts, txs, _, erroneous, err := blockManager.ProcessTransactions(coinbase, block.State(), block, block, transactions) + receipts, txs, _, erroneous, err := blockManager.ApplyTransactions(coinbase, block.State(), block, transactions, true) if err != nil { minerlogger.Debugln(err) }