aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2014-10-29 10:50:20 +0800
committerFelix Lange <fjl@twurst.com>2014-10-29 10:50:20 +0800
commit6b3f5fb82b0304f477a1c36b68b0d07232405aff (patch)
treea0d52b610b2876fcbcce8bb00e84ba81799d568d
parent5920aa7be6fb973c7cbae34c9d4af03665933c51 (diff)
downloaddexon-6b3f5fb82b0304f477a1c36b68b0d07232405aff.tar
dexon-6b3f5fb82b0304f477a1c36b68b0d07232405aff.tar.gz
dexon-6b3f5fb82b0304f477a1c36b68b0d07232405aff.tar.bz2
dexon-6b3f5fb82b0304f477a1c36b68b0d07232405aff.tar.lz
dexon-6b3f5fb82b0304f477a1c36b68b0d07232405aff.tar.xz
dexon-6b3f5fb82b0304f477a1c36b68b0d07232405aff.tar.zst
dexon-6b3f5fb82b0304f477a1c36b68b0d07232405aff.zip
cmd/mist, ethchain, ethminer: split TxEvent (#165)
-rw-r--r--cmd/mist/gui.go51
-rw-r--r--ethchain/events.go14
-rw-r--r--ethchain/state_manager.go2
-rw-r--r--ethchain/transaction_pool.go9
-rw-r--r--ethminer/miner.go28
5 files changed, 48 insertions, 56 deletions
diff --git a/cmd/mist/gui.go b/cmd/mist/gui.go
index 45a99659b..e6da33475 100644
--- a/cmd/mist/gui.go
+++ b/cmd/mist/gui.go
@@ -408,7 +408,8 @@ func (gui *Gui) update() {
eth.ChainSyncEvent{},
eth.PeerListEvent{},
ethchain.NewBlockEvent{},
- ethchain.TxEvent{},
+ ethchain.TxPreEvent{},
+ ethchain.TxPostEvent{},
ethminer.Event{},
)
@@ -430,40 +431,38 @@ func (gui *Gui) update() {
gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.address()).Balance(), nil)
}
- case ethchain.TxEvent:
+ case ethchain.TxPreEvent:
tx := ev.Tx
- if ev.Type == ethchain.TxPre {
- object := state.GetAccount(gui.address())
+ 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)
- }
-
- gui.setWalletValue(object.Balance(), unconfirmedFunds)
-
- gui.insertTransaction("pre", tx)
+ 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)
+ }
- } else if ev.Type == ethchain.TxPost {
- object := state.GetAccount(gui.address())
- if bytes.Compare(tx.Sender(), gui.address()) == 0 {
- object.SubAmount(tx.Value)
+ gui.setWalletValue(object.Balance(), unconfirmedFunds)
+ gui.insertTransaction("pre", tx)
- //gui.getObjectByName("transactionView").Call("addTx", ethpipe.NewJSTx(tx), "send")
- gui.txDb.Put(tx.Hash(), tx.RlpEncode())
- } else if bytes.Compare(tx.Recipient, gui.address()) == 0 {
- object.AddAmount(tx.Value)
+ case ethchain.TxPostEvent:
+ tx := ev.Tx
+ object := state.GetAccount(gui.address())
- //gui.getObjectByName("transactionView").Call("addTx", ethpipe.NewJSTx(tx), "recv")
- gui.txDb.Put(tx.Hash(), tx.RlpEncode())
- }
+ if bytes.Compare(tx.Sender(), gui.address()) == 0 {
+ object.SubAmount(tx.Value)
- gui.setWalletValue(object.Balance(), nil)
+ //gui.getObjectByName("transactionView").Call("addTx", ethpipe.NewJSTx(tx), "send")
+ gui.txDb.Put(tx.Hash(), tx.RlpEncode())
+ } else if bytes.Compare(tx.Recipient, gui.address()) == 0 {
+ object.AddAmount(tx.Value)
- state.UpdateStateObject(object)
+ //gui.getObjectByName("transactionView").Call("addTx", ethpipe.NewJSTx(tx), "recv")
+ gui.txDb.Put(tx.Hash(), tx.RlpEncode())
}
+ gui.setWalletValue(object.Balance(), nil)
+ state.UpdateStateObject(object)
+
// case object:
// gui.loadAddressBook()
diff --git a/ethchain/events.go b/ethchain/events.go
index 05c21edfe..304e741b7 100644
--- a/ethchain/events.go
+++ b/ethchain/events.go
@@ -1,10 +1,10 @@
package ethchain
-type TxEvent struct {
- Type int // TxPre || TxPost
- Tx *Transaction
-}
+// TxPreEvent is posted when a transaction enters the transaction pool.
+type TxPreEvent struct{ Tx *Transaction }
-type NewBlockEvent struct {
- Block *Block
-}
+// TxPostEvent is posted when a transaction has been processed.
+type TxPostEvent struct{ Tx *Transaction }
+
+// NewBlockEvent is posted when a block has been imported.
+type NewBlockEvent struct{ Block *Block }
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go
index dba3ff202..b759ae94e 100644
--- a/ethchain/state_manager.go
+++ b/ethchain/state_manager.go
@@ -190,7 +190,7 @@ done:
}
// Notify all subscribers
- self.eth.EventMux().Post(TxEvent{TxPost, tx})
+ self.eth.EventMux().Post(TxPostEvent{tx})
receipts = append(receipts, receipt)
handled = append(handled, tx)
diff --git a/ethchain/transaction_pool.go b/ethchain/transaction_pool.go
index 7f8a5de42..7bd3e9ffd 100644
--- a/ethchain/transaction_pool.go
+++ b/ethchain/transaction_pool.go
@@ -14,17 +14,12 @@ import (
var txplogger = ethlog.NewLogger("TXP")
-const (
- txPoolQueueSize = 50
-)
+const txPoolQueueSize = 50
type TxPoolHook chan *Transaction
type TxMsgTy byte
const (
- TxPre = iota
- TxPost
-
minGasPrice = 1000000
)
@@ -169,7 +164,7 @@ out:
txplogger.Debugf("(t) %x => %x (%v) %x\n", tx.Sender()[:4], tmp, tx.Value, tx.Hash())
// Notify the subscribers
- pool.Ethereum.EventMux().Post(TxEvent{TxPre, tx})
+ pool.Ethereum.EventMux().Post(TxPreEvent{tx})
}
case <-pool.quit:
break out
diff --git a/ethminer/miner.go b/ethminer/miner.go
index e0bef078b..43a6f302d 100644
--- a/ethminer/miner.go
+++ b/ethminer/miner.go
@@ -64,7 +64,7 @@ func (miner *Miner) Start() {
miner.block = miner.ethereum.ChainManager().NewBlock(miner.coinbase)
mux := miner.ethereum.EventMux()
- miner.events = mux.Subscribe(ethchain.NewBlockEvent{}, ethchain.TxEvent{})
+ miner.events = mux.Subscribe(ethchain.NewBlockEvent{}, ethchain.TxPreEvent{})
// Prepare inital block
//miner.ethereum.StateManager().Prepare(miner.block.State(), miner.block.State())
@@ -125,23 +125,21 @@ func (miner *Miner) listener() {
}
}
- case ethchain.TxEvent:
- if event.Type == ethchain.TxPre {
- miner.stopMining()
+ case ethchain.TxPreEvent:
+ miner.stopMining()
- found := false
- for _, ctx := range miner.txs {
- if found = bytes.Compare(ctx.Hash(), event.Tx.Hash()) == 0; found {
- break
- }
- }
- if found == false {
- // Undo all previous commits
- miner.block.Undo()
- // Apply new transactions
- miner.txs = append(miner.txs, event.Tx)
+ found := false
+ for _, ctx := range miner.txs {
+ if found = bytes.Compare(ctx.Hash(), event.Tx.Hash()) == 0; found {
+ break
}
}
+ if found == false {
+ // Undo all previous commits
+ miner.block.Undo()
+ // Apply new transactions
+ miner.txs = append(miner.txs, event.Tx)
+ }
}
case <-miner.powDone: