diff options
author | obscuren <geffobscura@gmail.com> | 2015-02-18 05:20:47 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-02-18 05:20:47 +0800 |
commit | 7fc9b5b3f9ca0111cc4bc1b2a6b4bb2eccd3e048 (patch) | |
tree | 764d7ebd57cafbae0a12d046aeafd1b823a0f0bb | |
parent | 11e12680ebe4f4679083317ee0f2c27b219d44b3 (diff) | |
download | go-tangerine-7fc9b5b3f9ca0111cc4bc1b2a6b4bb2eccd3e048.tar.gz go-tangerine-7fc9b5b3f9ca0111cc4bc1b2a6b4bb2eccd3e048.tar.zst go-tangerine-7fc9b5b3f9ca0111cc4bc1b2a6b4bb2eccd3e048.zip |
Changed to ChainEvent and fixed a nil pointer in transact
-rw-r--r-- | cmd/mist/assets/examples/info.html | 4 | ||||
-rw-r--r-- | cmd/mist/gui.go | 6 | ||||
-rw-r--r-- | core/chain_manager.go | 2 | ||||
-rw-r--r-- | eth/backend.go | 4 | ||||
-rw-r--r-- | event/filter/eth_filter.go | 7 | ||||
-rw-r--r-- | rpc/args.go | 29 | ||||
-rw-r--r-- | rpc/packages.go | 6 | ||||
-rw-r--r-- | xeth/xeth.go | 3 |
8 files changed, 47 insertions, 14 deletions
diff --git a/cmd/mist/assets/examples/info.html b/cmd/mist/assets/examples/info.html index d8816b19f..2a405c280 100644 --- a/cmd/mist/assets/examples/info.html +++ b/cmd/mist/assets/examples/info.html @@ -71,6 +71,10 @@ document.querySelector("#gas_price").innerHTML = eth.gasPrice; document.querySelector("#mining").innerHTML = eth.mining; document.querySelector("#listening").innerHTML = eth.listening; + eth.watch('chain').changed(function() { + document.querySelector("#number").innerHTML = eth.number; + }); + </script> </html> diff --git a/cmd/mist/gui.go b/cmd/mist/gui.go index 886a5811b..c12538f4a 100644 --- a/cmd/mist/gui.go +++ b/cmd/mist/gui.go @@ -394,7 +394,6 @@ func (gui *Gui) update() { miningLabel := gui.getObjectByName("miningLabel") events := gui.eth.EventMux().Subscribe( - core.NewBlockEvent{}, core.TxPreEvent{}, core.TxPostEvent{}, ) @@ -407,11 +406,6 @@ func (gui *Gui) update() { return } switch ev := ev.(type) { - case core.NewBlockEvent: - gui.processBlock(ev.Block, false) - balance := ethutil.CurrencyToString(gui.eth.ChainManager().State().GetBalance(gui.address())) - gui.getObjectByName("balanceLabel").Set("text", fmt.Sprintf("%v", balance)) - case core.TxPreEvent: tx := ev.Tx diff --git a/core/chain_manager.go b/core/chain_manager.go index 025615676..22d54be03 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -393,8 +393,6 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error { } } self.mu.Unlock() - - self.eventMux.Post(NewBlockEvent{block}) } return nil diff --git a/eth/backend.go b/eth/backend.go index 7685f3568..9749cef9a 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -25,8 +25,8 @@ var ( jsonlogger = ethlogger.NewJsonLogger() defaultBootNodes = []*discover.Node{ - discover.MustParseNode("enode://6cdd090303f394a1cac34ecc9f7cda18127eafa2a3a06de39f6d920b0e583e062a7362097c7c65ee490a758b442acd5c80c6fce4b148c6a391e946b45131365b@54.169.166.226:30303"), - discover.MustParseNode("enode://d1760a33c2f25c3b419ee4f6787fb0ea148828f5e678f0450d4be978fef908b42fc47a4c0fbf19832754f17881d381e50364fa93be42f31801d60ac64933f0a5@127.0.0.1:30303"), + //discover.MustParseNode("enode://6cdd090303f394a1cac34ecc9f7cda18127eafa2a3a06de39f6d920b0e583e062a7362097c7c65ee490a758b442acd5c80c6fce4b148c6a391e946b45131365b@54.169.166.226:30303"), + discover.MustParseNode("enode://364d179a050fb3192ea25ee2c4836cb808f13bb1a98a058e5bf215a597080edd742a00d6fd4b5f348a08024097f0b8f567610902dddf8db573362d8b22cabef5@127.0.0.1:30303"), } ) diff --git a/event/filter/eth_filter.go b/event/filter/eth_filter.go index 295fcfbbf..d298d914d 100644 --- a/event/filter/eth_filter.go +++ b/event/filter/eth_filter.go @@ -60,7 +60,10 @@ func (self *FilterManager) GetFilter(id int) *core.Filter { func (self *FilterManager) filterLoop() { // Subscribe to events - events := self.eventMux.Subscribe(core.PendingBlockEvent{}, core.NewBlockEvent{}, state.Logs(nil)) + events := self.eventMux.Subscribe( + core.PendingBlockEvent{}, + core.ChainEvent{}, + state.Logs(nil)) out: for { @@ -69,7 +72,7 @@ out: break out case event := <-events.Chan(): switch event := event.(type) { - case core.NewBlockEvent: + case core.ChainEvent: self.filterMu.RLock() for _, filter := range self.filters { if filter.BlockCallback != nil { diff --git a/rpc/args.go b/rpc/args.go index 9c2c7d7a6..429b385d5 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -38,6 +38,35 @@ type NewTxArgs struct { Data string `json:"data"` } +func (obj *NewTxArgs) UnmarshalJSON(b []byte) (err error) { + // Data can be either specified as "data" or "code" :-/ + var ext struct { + From string + To string + Value string + Gas string + GasPrice string + Data string + Code string + } + + if err = json.Unmarshal(b, &ext); err == nil { + if len(ext.Data) == 0 { + ext.Data = ext.Code + } + obj.From = ext.From + obj.To = ext.To + obj.Value = ext.Value + obj.Gas = ext.Gas + obj.GasPrice = ext.GasPrice + obj.Data = ext.Data + + return + } + + return NewErrorResponse(ErrorDecodeArgs) +} + type PushTxArgs struct { Tx string `json:"tx"` } diff --git a/rpc/packages.go b/rpc/packages.go index 0b73d48a7..4d2194571 100644 --- a/rpc/packages.go +++ b/rpc/packages.go @@ -127,6 +127,9 @@ func (self *EthereumApi) NewFilterString(args string, reply *interface{}) error filter := core.NewFilter(self.xeth.Backend()) callback := func(block *types.Block) { + self.logMut.Lock() + defer self.logMut.Unlock() + self.logs[id] = append(self.logs[id], &state.StateLog{}) } if args == "pending" { @@ -153,6 +156,9 @@ func (self *EthereumApi) FilterChanged(id int, reply *interface{}) error { } func (self *EthereumApi) Logs(id int, reply *interface{}) error { + self.logMut.Lock() + defer self.logMut.Unlock() + filter := self.filterManager.GetFilter(id) *reply = toLogs(filter.Find()) diff --git a/xeth/xeth.go b/xeth/xeth.go index 27435b956..f005105bb 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -16,7 +16,6 @@ import ( "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/p2p" - "github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/whisper" ) @@ -220,7 +219,7 @@ func (self *XEth) Call(toStr, valueStr, gasStr, gasPriceStr, dataStr string) (st var ( statedb = self.chainManager.TransState() key = self.eth.KeyManager().KeyPair() - from = state.NewStateObject(key.Address(), self.eth.Db()) + from = statedb.GetOrNewStateObject(key.Address()) block = self.chainManager.CurrentBlock() to = statedb.GetOrNewStateObject(fromHex(toStr)) data = fromHex(dataStr) |