From a1b6a9ac29d0aa8d29a2c0535bafdb5fe4d4830b Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 18 Nov 2014 16:58:22 +0100 Subject: Begin of moving objects to types package * Block(s) * Transaction(s) --- miner/miner.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'miner') diff --git a/miner/miner.go b/miner/miner.go index a678a6895..b25e25357 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -31,6 +31,7 @@ import ( "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/chain" + "github.com/ethereum/go-ethereum/chain/types" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/wire" @@ -44,7 +45,7 @@ type LocalTx struct { Value string `json:"value"` } -func (self *LocalTx) Sign(key []byte) *chain.Transaction { +func (self *LocalTx) Sign(key []byte) *types.Transaction { return nil } @@ -54,7 +55,7 @@ type Miner struct { eth *eth.Ethereum events event.Subscription - uncles chain.Blocks + uncles types.Blocks localTxs map[int]*LocalTx localTxId int @@ -212,7 +213,7 @@ func (self *Miner) mine() { nonce := self.pow.Search(block, self.powQuitCh) if nonce != nil { block.Nonce = nonce - lchain := chain.NewChain(chain.Blocks{block}) + lchain := chain.NewChain(types.Blocks{block}) _, err := chainMan.TestChain(lchain) if err != nil { minerlogger.Infoln(err) @@ -229,15 +230,15 @@ func (self *Miner) mine() { } } -func (self *Miner) finiliseTxs() chain.Transactions { +func (self *Miner) finiliseTxs() types.Transactions { // Sort the transactions by nonce in case of odd network propagation - var txs chain.Transactions + var txs types.Transactions state := self.eth.BlockManager().TransState() // XXX This has to change. Coinbase is, for new, same as key. key := self.eth.KeyManager() for _, ltx := range self.localTxs { - tx := chain.NewTransactionMessage(ltx.To, ethutil.Big(ltx.Value), ethutil.Big(ltx.Gas), ethutil.Big(ltx.GasPrice), ltx.Data) + tx := types.NewTransactionMessage(ltx.To, ethutil.Big(ltx.Value), ethutil.Big(ltx.Gas), ethutil.Big(ltx.GasPrice), ltx.Data) tx.Nonce = state.GetNonce(self.Coinbase) state.SetNonce(self.Coinbase, tx.Nonce+1) @@ -247,7 +248,7 @@ func (self *Miner) finiliseTxs() chain.Transactions { } txs = append(txs, self.eth.TxPool().CurrentTransactions()...) - sort.Sort(chain.TxByNonce{txs}) + sort.Sort(types.TxByNonce{txs}) return txs } -- cgit v1.2.3 From f8d0cd9906a1ec4a4a1e95868a279312363f8b49 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 18 Nov 2014 19:44:17 +0100 Subject: Added a callback mechanism to chain adding. Not sure if this is the right approach. Why? BlockChain shouldn't need the "Ethereum" object. BlockChain shouldn't need to worry about notifying listeners or message propagation. --- miner/miner.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'miner') diff --git a/miner/miner.go b/miner/miner.go index b25e25357..795385424 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -29,6 +29,7 @@ import ( "github.com/ethereum/go-ethereum" "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/chain" "github.com/ethereum/go-ethereum/chain/types" @@ -218,8 +219,10 @@ func (self *Miner) mine() { if err != nil { minerlogger.Infoln(err) } else { - chainMan.InsertChain(lchain) - //self.eth.EventMux().Post(chain.NewBlockEvent{block}) + chainMan.InsertChain(lchain, func(block *types.Block, _ state.Messages) { + self.eth.EventMux().Post(chain.NewBlockEvent{block}) + }) + self.eth.Broadcast(wire.MsgBlockTy, []interface{}{block.Value().Val}) minerlogger.Infof("🔨 Mined block %x\n", block.Hash()) -- cgit v1.2.3