diff options
-rw-r--r-- | cmd/mist/assets/examples/coin.html | 2 | ||||
m--------- | cmd/mist/assets/ext/ethereum.js | 0 | ||||
-rw-r--r-- | jsre/pp_js.go | 29 | ||||
-rw-r--r-- | miner/worker.go | 38 |
4 files changed, 38 insertions, 31 deletions
diff --git a/cmd/mist/assets/examples/coin.html b/cmd/mist/assets/examples/coin.html index bcd4ad990..41362554d 100644 --- a/cmd/mist/assets/examples/coin.html +++ b/cmd/mist/assets/examples/coin.html @@ -3,7 +3,7 @@ <title>JevCoin</title> <head> <script type="text/javascript" src="../ext/bignumber.min.js"></script> -<script type="text/javascript" src="/Users/jeffrey/ethereum.js"></script> +<script type="text/javascript" src="../ext/ethereum.js/dist/ethereum.js"></script> </head> <body> diff --git a/cmd/mist/assets/ext/ethereum.js b/cmd/mist/assets/ext/ethereum.js -Subproject d5093606945fd871bc62f5d6adade3a903b0533 +Subproject 9f073d9091cd2d2b46dd46afea9dcf5d825ecd7 diff --git a/jsre/pp_js.go b/jsre/pp_js.go index fd80ae68b..f06a4bb51 100644 --- a/jsre/pp_js.go +++ b/jsre/pp_js.go @@ -1,30 +1,43 @@ package jsre const pp_js = ` -function pp(object) { +function pp(object, indent) { var str = ""; + /* + var o = object; + try { + object = JSON.stringify(object) + object = JSON.parse(object); + } catch(e) { + object = o; + } + */ if(object instanceof Array) { - str += "[ "; + str += "["; for(var i = 0, l = object.length; i < l; i++) { - str += pp(object[i]); + str += pp(object[i], indent); if(i < l-1) { str += ", "; } } str += " ]"; + } else if(object instanceof BigNumber) { + return pp(object.toString(), indent); } else if(typeof(object) === "object") { - str += "{ "; + str += "{\n"; + indent += " "; var last = Object.keys(object).pop() for(var k in object) { - str += k + ": " + pp(object[k]); + str += indent + k + ": " + pp(object[k], indent); if(k !== last) { - str += ", "; + str += ","; } + str += "\n"; } - str += " }"; + str += indent.substr(2, indent.length) + "}"; } else if(typeof(object) === "string") { str += "\033[32m'" + object + "'"; } else if(typeof(object) === "undefined") { @@ -46,7 +59,7 @@ function prettyPrint(/* */) { var args = arguments; var ret = ""; for(var i = 0, l = args.length; i < l; i++) { - ret += pp(args[i]) + "\n"; + ret += pp(args[i], "") + "\n"; } return ret; } diff --git a/miner/worker.go b/miner/worker.go index 1a6da505f..e0287ea8d 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -64,6 +64,7 @@ type worker struct { mux *event.TypeMux quit chan struct{} pow pow.PoW + atWork int eth core.Backend chain *core.ChainManager @@ -106,6 +107,7 @@ func (self *worker) start() { func (self *worker) stop() { self.mining = false + self.atWork = 0 close(self.quit) } @@ -116,7 +118,7 @@ func (self *worker) register(agent Agent) { } func (self *worker) update() { - events := self.mux.Subscribe(core.ChainHeadEvent{}, core.NewMinedBlockEvent{}, core.ChainSideEvent{}) + events := self.mux.Subscribe(core.ChainHeadEvent{}, core.ChainSideEvent{}) timer := time.NewTicker(2 * time.Second) @@ -127,13 +129,15 @@ out: switch ev := event.(type) { case core.ChainHeadEvent: self.commitNewWork() - case core.NewMinedBlockEvent: - //self.commitNewWork() case core.ChainSideEvent: self.uncleMu.Lock() self.possibleUncles[ev.Block.Hash()] = ev.Block self.uncleMu.Unlock() } + + if self.atWork == 0 { + self.commitNewWork() + } case <-self.quit: // stop all agents for _, agent := range self.agents { @@ -148,36 +152,25 @@ out: events.Unsubscribe() } -func (self *worker) addUncle(uncle *types.Block) { -} - func (self *worker) wait() { for { for block := range self.recv { - // Someone Successfully Mined! - //block := self.current.block - //if block.Number().Uint64() == work.Number && block.Nonce() == 0 { - //self.current.block.SetNonce(work.Nonce) - //self.current.block.Header().MixDigest = common.BytesToHash(work.MixDigest) - - jsonlogger.LogJson(&logger.EthMinerNewBlock{ - BlockHash: block.Hash().Hex(), - BlockNumber: block.Number(), - ChainHeadHash: block.ParentHeaderHash.Hex(), - BlockPrevHash: block.ParentHeaderHash.Hex(), - }) - if err := self.chain.InsertChain(types.Blocks{block}); err == nil { for _, uncle := range block.Uncles() { delete(self.possibleUncles, uncle.Hash()) } - self.mux.Post(core.NewMinedBlockEvent{block}) + + jsonlogger.LogJson(&logger.EthMinerNewBlock{ + BlockHash: block.Hash().Hex(), + BlockNumber: block.Number(), + ChainHeadHash: block.ParentHeaderHash.Hex(), + BlockPrevHash: block.ParentHeaderHash.Hex(), + }) } else { self.commitNewWork() } - //} - break + self.atWork-- } } } @@ -190,6 +183,7 @@ func (self *worker) push() { // push new work to agents for _, agent := range self.agents { agent.Work() <- self.current.block.Copy() + self.atWork++ } } } |