Dev test mining

This commit is contained in:
obscuren
2014-01-24 20:16:48 +01:00
parent c636f8e3e6
commit 97882a65bb
2 changed files with 56 additions and 28 deletions

View File

@@ -6,11 +6,14 @@ import (
"github.com/ethereum/eth-go"
"github.com/ethereum/ethchain-go"
"github.com/ethereum/ethutil-go"
"github.com/ethereum/ethwire-go"
"log"
"math/big"
"os"
"os/signal"
"path"
"runtime"
"time"
)
const Debug = true
@@ -78,21 +81,32 @@ func main() {
RegisterInterupts(ethereum)
if StartMining {
log.Println("Mining started")
dagger := &ethchain.Dagger{}
ethereum.Start()
if StartMining {
log.Println("Dev Test Mining started")
// Fake block mining. It broadcasts a new block every 5 seconds
go func() {
for {
res := dagger.Search(ethutil.Big("01001"), ethutil.BigPow(2, 36))
log.Println("Res dagger", res)
//ethereum.Broadcast("blockmine", ethutil.Encode(res.String()))
time.Sleep(5 * time.Second)
block := ethchain.CreateBlock(
ethereum.BlockManager.BlockChain().LastBlock.State().Root,
ethereum.BlockManager.LastBlockHash,
"123",
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())
}
}()
}
ethereum.Start()
// Wait for shutdown
ethereum.WaitForShutdown()
}