Implement eth.miner.new_block event

This commit is contained in:
Taylor Gerring 2015-03-01 16:09:59 +01:00
parent ad3a21f260
commit 60a2704b04
2 changed files with 14 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package logger package logger
import ( import (
"math/big"
"time" "time"
) )
@ -54,7 +55,7 @@ func (l *P2PDisconnected) EventName() string {
type EthMinerNewBlock struct { type EthMinerNewBlock struct {
BlockHash string `json:"block_hash"` BlockHash string `json:"block_hash"`
BlockNumber int `json:"block_number"` BlockNumber *big.Int `json:"block_number"`
ChainHeadHash string `json:"chain_head_hash"` ChainHeadHash string `json:"chain_head_hash"`
BlockPrevHash string `json:"block_prev_hash"` BlockPrevHash string `json:"block_prev_hash"`
LogEvent LogEvent

View File

@ -10,11 +10,14 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/pow" "github.com/ethereum/go-ethereum/pow"
"github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/state"
"gopkg.in/fatih/set.v0" "gopkg.in/fatih/set.v0"
) )
var jsonlogger = logger.NewJsonLogger()
type environment struct { type environment struct {
totalUsedGas *big.Int totalUsedGas *big.Int
state *state.StateDB state *state.StateDB
@ -141,7 +144,12 @@ func (self *worker) wait() {
block := self.current.block block := self.current.block
if block.Number().Uint64() == work.Number && block.Nonce() == nil { if block.Number().Uint64() == work.Number && block.Nonce() == nil {
self.current.block.Header().Nonce = work.Nonce self.current.block.Header().Nonce = work.Nonce
jsonlogger.LogJson(&logger.EthMinerNewBlock{
BlockHash: ethutil.Bytes2Hex(block.Hash()),
BlockNumber: block.Number(),
ChainHeadHash: ethutil.Bytes2Hex(block.ParentHeaderHash),
BlockPrevHash: ethutil.Bytes2Hex(block.ParentHeaderHash),
})
if err := self.chain.InsertChain(types.Blocks{self.current.block}); err == nil { if err := self.chain.InsertChain(types.Blocks{self.current.block}); err == nil {
self.mux.Post(core.NewMinedBlockEvent{self.current.block}) self.mux.Post(core.NewMinedBlockEvent{self.current.block})
} else { } else {