diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2015-03-01 23:09:59 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2015-03-01 23:09:59 +0800 |
commit | 60a2704b049a2bc8de417c8f50155ec69b071a9e (patch) | |
tree | b429ae0535ad49980f39f7d8fe6e09c57402ad68 | |
parent | ad3a21f260a0b13048046f6c76fe5f47bdcc46de (diff) | |
download | dexon-60a2704b049a2bc8de417c8f50155ec69b071a9e.tar.gz dexon-60a2704b049a2bc8de417c8f50155ec69b071a9e.tar.zst dexon-60a2704b049a2bc8de417c8f50155ec69b071a9e.zip |
Implement eth.miner.new_block event
-rw-r--r-- | logger/types.go | 9 | ||||
-rw-r--r-- | miner/worker.go | 10 |
2 files changed, 14 insertions, 5 deletions
diff --git a/logger/types.go b/logger/types.go index 7ab4a2b8c..86408620e 100644 --- a/logger/types.go +++ b/logger/types.go @@ -1,6 +1,7 @@ package logger import ( + "math/big" "time" ) @@ -53,10 +54,10 @@ func (l *P2PDisconnected) EventName() string { } type EthMinerNewBlock struct { - BlockHash string `json:"block_hash"` - BlockNumber int `json:"block_number"` - ChainHeadHash string `json:"chain_head_hash"` - BlockPrevHash string `json:"block_prev_hash"` + BlockHash string `json:"block_hash"` + BlockNumber *big.Int `json:"block_number"` + ChainHeadHash string `json:"chain_head_hash"` + BlockPrevHash string `json:"block_prev_hash"` LogEvent } diff --git a/miner/worker.go b/miner/worker.go index 4f0909302..6f43a9c39 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -10,11 +10,14 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/event" + "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/pow" "github.com/ethereum/go-ethereum/state" "gopkg.in/fatih/set.v0" ) +var jsonlogger = logger.NewJsonLogger() + type environment struct { totalUsedGas *big.Int state *state.StateDB @@ -141,7 +144,12 @@ func (self *worker) wait() { block := self.current.block if block.Number().Uint64() == work.Number && block.Nonce() == nil { 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 { self.mux.Post(core.NewMinedBlockEvent{self.current.block}) } else { |