Changed to ChainEvent and fixed a nil pointer in transact

This commit is contained in:
obscuren 2015-02-17 22:20:47 +01:00
parent 11e12680eb
commit 7fc9b5b3f9
8 changed files with 47 additions and 14 deletions

@ -71,6 +71,10 @@
document.querySelector("#gas_price").innerHTML = eth.gasPrice; document.querySelector("#gas_price").innerHTML = eth.gasPrice;
document.querySelector("#mining").innerHTML = eth.mining; document.querySelector("#mining").innerHTML = eth.mining;
document.querySelector("#listening").innerHTML = eth.listening; document.querySelector("#listening").innerHTML = eth.listening;
eth.watch('chain').changed(function() {
document.querySelector("#number").innerHTML = eth.number;
});
</script> </script>
</html> </html>

@ -394,7 +394,6 @@ func (gui *Gui) update() {
miningLabel := gui.getObjectByName("miningLabel") miningLabel := gui.getObjectByName("miningLabel")
events := gui.eth.EventMux().Subscribe( events := gui.eth.EventMux().Subscribe(
core.NewBlockEvent{},
core.TxPreEvent{}, core.TxPreEvent{},
core.TxPostEvent{}, core.TxPostEvent{},
) )
@ -407,11 +406,6 @@ func (gui *Gui) update() {
return return
} }
switch ev := ev.(type) { 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: case core.TxPreEvent:
tx := ev.Tx tx := ev.Tx

@ -393,8 +393,6 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
} }
} }
self.mu.Unlock() self.mu.Unlock()
self.eventMux.Post(NewBlockEvent{block})
} }
return nil return nil

@ -25,8 +25,8 @@ var (
jsonlogger = ethlogger.NewJsonLogger() jsonlogger = ethlogger.NewJsonLogger()
defaultBootNodes = []*discover.Node{ defaultBootNodes = []*discover.Node{
discover.MustParseNode("enode://6cdd090303f394a1cac34ecc9f7cda18127eafa2a3a06de39f6d920b0e583e062a7362097c7c65ee490a758b442acd5c80c6fce4b148c6a391e946b45131365b@54.169.166.226:30303"), //discover.MustParseNode("enode://6cdd090303f394a1cac34ecc9f7cda18127eafa2a3a06de39f6d920b0e583e062a7362097c7c65ee490a758b442acd5c80c6fce4b148c6a391e946b45131365b@54.169.166.226:30303"),
discover.MustParseNode("enode://d1760a33c2f25c3b419ee4f6787fb0ea148828f5e678f0450d4be978fef908b42fc47a4c0fbf19832754f17881d381e50364fa93be42f31801d60ac64933f0a5@127.0.0.1:30303"), discover.MustParseNode("enode://364d179a050fb3192ea25ee2c4836cb808f13bb1a98a058e5bf215a597080edd742a00d6fd4b5f348a08024097f0b8f567610902dddf8db573362d8b22cabef5@127.0.0.1:30303"),
} }
) )

@ -60,7 +60,10 @@ func (self *FilterManager) GetFilter(id int) *core.Filter {
func (self *FilterManager) filterLoop() { func (self *FilterManager) filterLoop() {
// Subscribe to events // 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: out:
for { for {
@ -69,7 +72,7 @@ out:
break out break out
case event := <-events.Chan(): case event := <-events.Chan():
switch event := event.(type) { switch event := event.(type) {
case core.NewBlockEvent: case core.ChainEvent:
self.filterMu.RLock() self.filterMu.RLock()
for _, filter := range self.filters { for _, filter := range self.filters {
if filter.BlockCallback != nil { if filter.BlockCallback != nil {

@ -38,6 +38,35 @@ type NewTxArgs struct {
Data string `json:"data"` 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 { type PushTxArgs struct {
Tx string `json:"tx"` Tx string `json:"tx"`
} }

@ -127,6 +127,9 @@ func (self *EthereumApi) NewFilterString(args string, reply *interface{}) error
filter := core.NewFilter(self.xeth.Backend()) filter := core.NewFilter(self.xeth.Backend())
callback := func(block *types.Block) { callback := func(block *types.Block) {
self.logMut.Lock()
defer self.logMut.Unlock()
self.logs[id] = append(self.logs[id], &state.StateLog{}) self.logs[id] = append(self.logs[id], &state.StateLog{})
} }
if args == "pending" { 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 { func (self *EthereumApi) Logs(id int, reply *interface{}) error {
self.logMut.Lock()
defer self.logMut.Unlock()
filter := self.filterManager.GetFilter(id) filter := self.filterManager.GetFilter(id)
*reply = toLogs(filter.Find()) *reply = toLogs(filter.Find())

@ -16,7 +16,6 @@ import (
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/whisper" "github.com/ethereum/go-ethereum/whisper"
) )
@ -220,7 +219,7 @@ func (self *XEth) Call(toStr, valueStr, gasStr, gasPriceStr, dataStr string) (st
var ( var (
statedb = self.chainManager.TransState() statedb = self.chainManager.TransState()
key = self.eth.KeyManager().KeyPair() key = self.eth.KeyManager().KeyPair()
from = state.NewStateObject(key.Address(), self.eth.Db()) from = statedb.GetOrNewStateObject(key.Address())
block = self.chainManager.CurrentBlock() block = self.chainManager.CurrentBlock()
to = statedb.GetOrNewStateObject(fromHex(toStr)) to = statedb.GetOrNewStateObject(fromHex(toStr))
data = fromHex(dataStr) data = fromHex(dataStr)