From e32b1a1d975e1bd8dfc3211b400872ba42bf1498 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 25 Jan 2014 01:25:36 +0100 Subject: [PATCH] Fake block mining --- ethereum.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ethereum.go b/ethereum.go index 9d81880f2..2d79659b0 100644 --- a/ethereum.go +++ b/ethereum.go @@ -6,7 +6,7 @@ import ( "github.com/ethereum/eth-go" "github.com/ethereum/ethchain-go" "github.com/ethereum/ethutil-go" - "github.com/ethereum/ethwire-go" + _ "github.com/ethereum/ethwire-go" "log" "math/big" "os" @@ -84,12 +84,15 @@ func main() { ethereum.Start() if StartMining { - log.Println("Dev Test Mining started") + blockTime := time.Duration(15) + log.Printf("Dev Test Mining started. Blocks found each %d seconds\n", blockTime) // Fake block mining. It broadcasts a new block every 5 seconds go func() { for { - time.Sleep(5 * time.Second) + txs := ethereum.TxPool.Flush() + + time.Sleep(blockTime * time.Second) block := ethchain.CreateBlock( ethereum.BlockManager.BlockChain().LastBlock.State().Root, @@ -98,11 +101,13 @@ func main() { big.NewInt(1), big.NewInt(1), "", - ethereum.TxPool.Flush()) - - ethereum.BlockManager.ProcessBlockWithState(block, block.State()) - ethereum.Broadcast(ethwire.MsgBlockTy, block.RlpData()) - log.Println("\n", block.String()) + txs) + err := ethereum.BlockManager.ProcessBlockWithState(block, block.State()) + if err != nil { + log.Println(err) + } else { + log.Println("\n+++++++ MINED BLK +++++++\n", block.String()) + } } }() }