Reimplement new miner creation
This commit is contained in:
parent
6724d27c0c
commit
a30f5730b3
@ -4,8 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/ethereum/eth-go"
|
"github.com/ethereum/eth-go"
|
||||||
"github.com/ethereum/eth-go/ethchain"
|
"github.com/ethereum/eth-go/ethchain"
|
||||||
|
"github.com/ethereum/eth-go/ethminer"
|
||||||
"github.com/ethereum/eth-go/ethutil"
|
"github.com/ethereum/eth-go/ethutil"
|
||||||
"github.com/ethereum/eth-go/ethwire"
|
|
||||||
"github.com/ethereum/go-ethereum/utils"
|
"github.com/ethereum/go-ethereum/utils"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
@ -121,36 +121,22 @@ func main() {
|
|||||||
|
|
||||||
// Fake block mining. It broadcasts a new block every 5 seconds
|
// Fake block mining. It broadcasts a new block every 5 seconds
|
||||||
go func() {
|
go func() {
|
||||||
pow := ðchain.EasyPow{}
|
|
||||||
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
|
|
||||||
keyRing := ethutil.NewValueFromBytes(data)
|
|
||||||
addr := keyRing.Get(1).Bytes()
|
|
||||||
|
|
||||||
for {
|
if StartMining {
|
||||||
txs := ethereum.TxPool().Flush()
|
log.Printf("Miner started\n")
|
||||||
// Create a new block which we're going to mine
|
|
||||||
block := ethereum.BlockChain().NewBlock(addr, txs)
|
|
||||||
log.Println("Mining on new block. Includes", len(block.Transactions()), "transactions")
|
|
||||||
// Apply all transactions to the block
|
|
||||||
ethereum.StateManager().ApplyTransactions(block, block.Transactions())
|
|
||||||
|
|
||||||
ethereum.StateManager().Prepare(block.State(), block.State())
|
go func() {
|
||||||
ethereum.StateManager().AccumelateRewards(block)
|
data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
|
||||||
|
keyRing := ethutil.NewValueFromBytes(data)
|
||||||
|
addr := keyRing.Get(1).Bytes()
|
||||||
|
|
||||||
// Search the nonce
|
miner := ethminer.NewDefaultMiner(addr, ethereum)
|
||||||
block.Nonce = pow.Search(block)
|
miner.Start()
|
||||||
ethereum.Broadcast(ethwire.MsgBlockTy, []interface{}{block.Value().Val})
|
|
||||||
|
|
||||||
ethereum.StateManager().PrepareDefault(block)
|
}()
|
||||||
err := ethereum.StateManager().ProcessBlock(block)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
} else {
|
|
||||||
log.Println("\n+++++++ MINED BLK +++++++\n", ethereum.BlockChain().CurrentBlock)
|
|
||||||
log.Printf("🔨 Mined block %x\n", block.Hash())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for shutdown
|
// Wait for shutdown
|
||||||
|
Loading…
Reference in New Issue
Block a user