diff options
-rw-r--r-- | cmd/ethereum/flags.go | 3 | ||||
-rw-r--r-- | cmd/ethereum/main.go | 4 | ||||
-rw-r--r-- | cmd/mist/flags.go | 4 | ||||
-rw-r--r-- | cmd/mist/main.go | 4 | ||||
-rw-r--r-- | cmd/utils/cmd.go | 13 | ||||
-rw-r--r-- | core/filter.go | 35 | ||||
-rw-r--r-- | eth/backend.go | 29 | ||||
-rw-r--r-- | eth/block_pool.go | 4 | ||||
-rw-r--r-- | eth/block_pool_test.go | 6 | ||||
-rw-r--r-- | eth/protocol.go | 7 | ||||
-rw-r--r-- | eth/protocol_test.go | 4 | ||||
-rw-r--r-- | javascript/types.go | 15 | ||||
-rw-r--r-- | logger/types.go | 9 | ||||
-rw-r--r-- | miner/worker.go | 10 | ||||
-rw-r--r-- | rpc/args.go | 18 | ||||
-rw-r--r-- | rpc/ws/server.go | 121 | ||||
-rw-r--r-- | state/statedb.go | 18 | ||||
-rw-r--r-- | ui/filter.go | 76 | ||||
-rw-r--r-- | xeth/xeth.go | 8 |
19 files changed, 90 insertions, 298 deletions
diff --git a/cmd/ethereum/flags.go b/cmd/ethereum/flags.go index d7a6427eb..fe848397c 100644 --- a/cmd/ethereum/flags.go +++ b/cmd/ethereum/flags.go @@ -46,7 +46,6 @@ var ( StartWebSockets bool RpcListenAddress string RpcPort int - WsPort int OutboundPort string ShowGenesis bool AddPeer string @@ -98,9 +97,7 @@ func Init() { flag.StringVar(&RpcListenAddress, "rpcaddr", "127.0.0.1", "address for json-rpc server to listen on") flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on") - flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on") flag.BoolVar(&StartRpc, "rpc", false, "start rpc server") - flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server") flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)") flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key") flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)") diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go index f79f948d1..ff306b10f 100644 --- a/cmd/ethereum/main.go +++ b/cmd/ethereum/main.go @@ -128,10 +128,6 @@ func main() { utils.StartRpc(ethereum, RpcListenAddress, RpcPort) } - if StartWebSockets { - utils.StartWebSockets(ethereum, WsPort) - } - utils.StartEthereum(ethereum) fmt.Printf("Welcome to the FRONTIER\n") diff --git a/cmd/mist/flags.go b/cmd/mist/flags.go index 2bbd1f416..139af5923 100644 --- a/cmd/mist/flags.go +++ b/cmd/mist/flags.go @@ -41,10 +41,8 @@ var ( KeyRing string KeyStore string StartRpc bool - StartWebSockets bool RpcListenAddress string RpcPort int - WsPort int OutboundPort string ShowGenesis bool AddPeer string @@ -82,9 +80,7 @@ func Init() { flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file") flag.StringVar(&RpcListenAddress, "rpcaddr", "127.0.0.1", "address for json-rpc server to listen on") flag.IntVar(&RpcPort, "rpcport", 8545, "port to start json-rpc server on") - flag.IntVar(&WsPort, "wsport", 40404, "port to start websocket rpc server on") flag.BoolVar(&StartRpc, "rpc", true, "start rpc server") - flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server") flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)") flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key") flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)") diff --git a/cmd/mist/main.go b/cmd/mist/main.go index c9a07bfde..1d4403848 100644 --- a/cmd/mist/main.go +++ b/cmd/mist/main.go @@ -76,10 +76,6 @@ func run() error { utils.StartRpc(ethereum, RpcListenAddress, RpcPort) } - if StartWebSockets { - utils.StartWebSockets(ethereum, WsPort) - } - gui := NewWindow(ethereum, config, KeyRing, LogLevel) utils.RegisterInterrupt(func(os.Signal) { diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go index 5c7ec3221..723cfa887 100644 --- a/cmd/utils/cmd.go +++ b/cmd/utils/cmd.go @@ -35,7 +35,6 @@ import ( "github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/rlp" rpchttp "github.com/ethereum/go-ethereum/rpc/http" - rpcws "github.com/ethereum/go-ethereum/rpc/ws" "github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/xeth" ) @@ -170,18 +169,6 @@ func StartRpc(ethereum *eth.Ethereum, RpcListenAddress string, RpcPort int) { } } -func StartWebSockets(eth *eth.Ethereum, wsPort int) { - clilogger.Infoln("Starting WebSockets") - - var err error - eth.WsServer, err = rpcws.NewWebSocketServer(xeth.New(eth), wsPort) - if err != nil { - clilogger.Errorf("Could not start RPC interface (port %v): %v", wsPort, err) - } else { - go eth.WsServer.Start() - } -} - var gminer *miner.Miner func GetMiner() *miner.Miner { diff --git a/core/filter.go b/core/filter.go index cdf7b282d..c61c9e998 100644 --- a/core/filter.go +++ b/core/filter.go @@ -17,7 +17,7 @@ type FilterOptions struct { Latest int64 Address [][]byte - Topics [][]byte + Topics [][][]byte Skip int Max int @@ -31,7 +31,7 @@ type Filter struct { skip int address [][]byte max int - topics [][]byte + topics [][][]byte BlockCallback func(*types.Block) PendingCallback func(*types.Block) @@ -44,6 +44,8 @@ func NewFilter(eth Backend) *Filter { return &Filter{eth: eth} } +// SetOptions copies the filter options to the filter it self. The reason for this "silly" copy +// is simply because named arguments in this case is extremely nice and readable. func (self *Filter) SetOptions(options FilterOptions) { self.earliest = options.Earliest self.latest = options.Latest @@ -69,7 +71,7 @@ func (self *Filter) SetAddress(addr [][]byte) { self.address = addr } -func (self *Filter) SetTopics(topics [][]byte) { +func (self *Filter) SetTopics(topics [][][]byte) { self.topics = topics } @@ -149,10 +151,18 @@ Logs: continue } - max := int(math.Min(float64(len(self.topics)), float64(len(log.Topics())))) - for i := 0; i < max; i++ { - if !bytes.Equal(log.Topics()[i], self.topics[i]) { - continue Logs + logTopics := make([][]byte, len(self.topics)) + copy(logTopics, log.Topics()) + + for i, topics := range self.topics { + for _, topic := range topics { + var match bool + if bytes.Equal(log.Topics()[i], topic) { + match = true + } + if !match { + continue Logs + } } } @@ -177,8 +187,15 @@ func (self *Filter) bloomFilter(block *types.Block) bool { } } - for _, topic := range self.topics { - if !types.BloomLookup(block.Bloom(), topic) { + for _, sub := range self.topics { + var included bool + for _, topic := range sub { + if types.BloomLookup(block.Bloom(), topic) { + included = true + break + } + } + if !included { return false } } diff --git a/eth/backend.go b/eth/backend.go index b79f6fc30..efdd43bf5 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -12,7 +12,7 @@ import ( "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/event" - ethlogger "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/discover" @@ -23,8 +23,8 @@ import ( ) var ( - logger = ethlogger.NewLogger("SERV") - jsonlogger = ethlogger.NewJsonLogger() + ethlogger = logger.NewLogger("SERV") + jsonlogger = logger.NewJsonLogger() defaultBootNodes = []*discover.Node{ // ETH/DEV cmd/bootnode @@ -74,7 +74,7 @@ func (cfg *Config) parseBootNodes() []*discover.Node { } n, err := discover.ParseNode(url) if err != nil { - logger.Errorf("Bootstrap URL %s: %v\n", url, err) + ethlogger.Errorf("Bootstrap URL %s: %v\n", url, err) continue } ns = append(ns, n) @@ -98,7 +98,7 @@ func (cfg *Config) nodeKey() (*ecdsa.PrivateKey, error) { return nil, fmt.Errorf("could not generate server key: %v", err) } if err := ioutil.WriteFile(keyfile, crypto.FromECDSA(key), 0600); err != nil { - logger.Errorln("could not persist nodekey: ", err) + ethlogger.Errorln("could not persist nodekey: ", err) } return key, nil } @@ -127,17 +127,16 @@ type Ethereum struct { miner *miner.Miner RpcServer rpc.RpcServer - WsServer rpc.RpcServer keyManager *crypto.KeyManager - logger ethlogger.LogSystem + logger logger.LogSystem Mining bool } func New(config *Config) (*Ethereum, error) { // Boostrap database - logger := ethlogger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat) + ethlogger := logger.New(config.DataDir, config.LogFile, config.LogLevel, config.LogFormat) db, err := ethdb.NewLDBDatabase("blockchain") if err != nil { return nil, err @@ -174,7 +173,7 @@ func New(config *Config) (*Ethereum, error) { keyManager: keyManager, blacklist: p2p.NewBlacklist(), eventMux: &event.TypeMux{}, - logger: logger, + logger: ethlogger, } eth.chainManager = core.NewChainManager(db, eth.EventMux()) @@ -216,7 +215,7 @@ func New(config *Config) (*Ethereum, error) { } func (s *Ethereum) KeyManager() *crypto.KeyManager { return s.keyManager } -func (s *Ethereum) Logger() ethlogger.LogSystem { return s.logger } +func (s *Ethereum) Logger() logger.LogSystem { return s.logger } func (s *Ethereum) Name() string { return s.net.Name } func (s *Ethereum) ChainManager() *core.ChainManager { return s.chainManager } func (s *Ethereum) BlockProcessor() *core.BlockProcessor { return s.blockProcessor } @@ -234,7 +233,7 @@ func (s *Ethereum) Coinbase() []byte { return nil } // TODO // Start the ethereum func (s *Ethereum) Start() error { - jsonlogger.LogJson(ðlogger.LogStarting{ + jsonlogger.LogJson(&logger.LogStarting{ ClientString: s.net.Name, ProtocolVersion: ProtocolVersion, }) @@ -260,7 +259,7 @@ func (s *Ethereum) Start() error { s.blockSub = s.eventMux.Subscribe(core.NewMinedBlockEvent{}) go s.blockBroadcastLoop() - logger.Infoln("Server started") + ethlogger.Infoln("Server started") return nil } @@ -285,9 +284,7 @@ func (s *Ethereum) Stop() { if s.RpcServer != nil { s.RpcServer.Stop() } - if s.WsServer != nil { - s.WsServer.Stop() - } + s.txPool.Stop() s.eventMux.Stop() s.blockPool.Stop() @@ -295,7 +292,7 @@ func (s *Ethereum) Stop() { s.whisper.Stop() } - logger.Infoln("Server stopped") + ethlogger.Infoln("Server stopped") close(s.shutdownChan) } diff --git a/eth/block_pool.go b/eth/block_pool.go index 13016c694..124a9e8c0 100644 --- a/eth/block_pool.go +++ b/eth/block_pool.go @@ -12,11 +12,11 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethutil" - ethlogger "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/pow" ) -var poolLogger = ethlogger.NewLogger("Blockpool") +var poolLogger = logger.NewLogger("Blockpool") const ( blockHashesBatchSize = 256 diff --git a/eth/block_pool_test.go b/eth/block_pool_test.go index 331dbe504..3d1b28315 100644 --- a/eth/block_pool_test.go +++ b/eth/block_pool_test.go @@ -12,19 +12,19 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" - ethlogger "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/pow" ) const waitTimeout = 60 // seconds -var logsys = ethlogger.NewStdLogSystem(os.Stdout, log.LstdFlags, ethlogger.LogLevel(ethlogger.DebugDetailLevel)) +var logsys = logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.LogLevel(logger.DebugDetailLevel)) var ini = false func logInit() { if !ini { - ethlogger.AddLogSystem(logsys) + logger.AddLogSystem(logsys) ini = true } } diff --git a/eth/protocol.go b/eth/protocol.go index 8221c1b29..a5cc8ee1a 100644 --- a/eth/protocol.go +++ b/eth/protocol.go @@ -8,6 +8,7 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethutil" + "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/rlp" ) @@ -137,6 +138,12 @@ func (self *ethProtocol) handle() error { if err := msg.Decode(&txs); err != nil { return self.protoError(ErrDecode, "msg %v: %v", msg, err) } + for _, tx := range txs { + jsonlogger.LogJson(&logger.EthTxReceived{ + TxHash: ethutil.Bytes2Hex(tx.Hash()), + RemoteId: self.peer.ID().String(), + }) + } self.txPool.AddTransactions(txs) case GetBlockHashesMsg: diff --git a/eth/protocol_test.go b/eth/protocol_test.go index a91806a1c..87d8974d5 100644 --- a/eth/protocol_test.go +++ b/eth/protocol_test.go @@ -12,12 +12,12 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethutil" - ethlogger "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/discover" ) -var sys = ethlogger.NewStdLogSystem(os.Stdout, log.LstdFlags, ethlogger.LogLevel(ethlogger.DebugDetailLevel)) +var sys = logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.LogLevel(logger.DebugDetailLevel)) type testMsgReadWriter struct { in chan p2p.Msg diff --git a/javascript/types.go b/javascript/types.go index 17f1b739e..b4da160fc 100644 --- a/javascript/types.go +++ b/javascript/types.go @@ -6,7 +6,6 @@ import ( "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/state" - "github.com/ethereum/go-ethereum/ui" "github.com/ethereum/go-ethereum/xeth" "github.com/obscuren/otto" ) @@ -96,17 +95,3 @@ func (self *JSEthereum) toVal(v interface{}) otto.Value { return result } - -func (self *JSEthereum) Messages(object map[string]interface{}) otto.Value { - filter := ui.NewFilterFromMap(object, self.ethereum) - - logs := filter.Find() - var jslogs []JSLog - for _, m := range logs { - jslogs = append(jslogs, NewJSLog(m)) - } - - v, _ := self.vm.ToValue(jslogs) - - return v -} 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 afce68c35..bc1c8e194 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -11,11 +11,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 @@ -146,7 +149,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 { diff --git a/rpc/args.go b/rpc/args.go index e839da8bf..ea8489585 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -197,7 +197,7 @@ type FilterOptions struct { Earliest int64 Latest int64 Address interface{} - Topic []string + Topic []interface{} Skip int Max int } @@ -220,10 +220,20 @@ func toFilterOptions(options *FilterOptions) core.FilterOptions { opts.Earliest = options.Earliest opts.Latest = options.Latest - opts.Topics = make([][]byte, len(options.Topic)) - for i, topic := range options.Topic { - opts.Topics[i] = fromHex(topic) + + topics := make([][][]byte, len(options.Topic)) + for i, topicDat := range options.Topic { + if slice, ok := topicDat.([]interface{}); ok { + topics[i] = make([][]byte, len(slice)) + for j, topic := range slice { + topics[i][j] = fromHex(topic.(string)) + } + } else if str, ok := topicDat.(string); ok { + topics[i] = make([][]byte, 1) + topics[i][0] = fromHex(str) + } } + opts.Topics = topics return opts } diff --git a/rpc/ws/server.go b/rpc/ws/server.go deleted file mode 100644 index 2c2988f5d..000000000 --- a/rpc/ws/server.go +++ /dev/null @@ -1,121 +0,0 @@ -/* - This file is part of go-ethereum - - go-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - go-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. -*/ -package rpcws - -import ( - "fmt" - "net" - "net/http" - - "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/rpc" - "github.com/ethereum/go-ethereum/xeth" - "golang.org/x/net/websocket" -) - -var wslogger = logger.NewLogger("RPC-WS") -var JSON rpc.JsonWrapper - -type WebSocketServer struct { - pipe *xeth.XEth - port int - doneCh chan bool - listener net.Listener -} - -func NewWebSocketServer(pipe *xeth.XEth, port int) (*WebSocketServer, error) { - sport := fmt.Sprintf(":%d", port) - l, err := net.Listen("tcp", sport) - if err != nil { - return nil, err - } - - return &WebSocketServer{ - pipe, - port, - make(chan bool), - l, - }, nil -} - -func (self *WebSocketServer) handlerLoop() { - for { - select { - case <-self.doneCh: - wslogger.Infoln("Shutdown RPC-WS server") - return - } - } -} - -func (self *WebSocketServer) Stop() { - close(self.doneCh) -} - -func (self *WebSocketServer) Start() { - wslogger.Infof("Starting RPC-WS server on port %d", self.port) - go self.handlerLoop() - - api := rpc.NewEthereumApi(self.pipe) - h := self.apiHandler(api) - http.Handle("/ws", h) - - err := http.Serve(self.listener, nil) - if err != nil { - wslogger.Errorln("Error on RPC-WS interface:", err) - } -} - -func (s *WebSocketServer) apiHandler(api *rpc.EthereumApi) http.Handler { - fn := func(w http.ResponseWriter, req *http.Request) { - h := sockHandler(api) - s := websocket.Server{Handler: h} - s.ServeHTTP(w, req) - } - - return http.HandlerFunc(fn) -} - -func sockHandler(api *rpc.EthereumApi) websocket.Handler { - var jsonrpcver string = "2.0" - fn := func(conn *websocket.Conn) { - for { - wslogger.Debugln("Handling connection") - var reqParsed rpc.RpcRequest - - // reqParsed, reqerr := JSON.ParseRequestBody(conn.Request()) - if err := websocket.JSON.Receive(conn, &reqParsed); err != nil { - jsonerr := &rpc.RpcErrorObject{-32700, "Error: Could not parse request"} - JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr}) - continue - } - - var response interface{} - reserr := api.GetRequestReply(&reqParsed, &response) - if reserr != nil { - wslogger.Warnln(reserr) - jsonerr := &rpc.RpcErrorObject{-32603, reserr.Error()} - JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Error: jsonerr}) - continue - } - - wslogger.Debugf("Generated response: %T %s", response, response) - JSON.Send(conn, &rpc.RpcSuccessResponse{JsonRpc: jsonrpcver, ID: reqParsed.ID, Result: response}) - } - } - return websocket.Handler(fn) -} diff --git a/state/statedb.go b/state/statedb.go index 7e2b24b94..ff8242e1a 100644 --- a/state/statedb.go +++ b/state/statedb.go @@ -54,7 +54,7 @@ func (self *StateDB) Refund(addr []byte, gas *big.Int) { // Retrieve the balance from the given address or 0 if object not found func (self *StateDB) GetBalance(addr []byte) *big.Int { - stateObject := self.GetStateObject(addr) + stateObject := self.GetOrNewStateObject(addr) if stateObject != nil { return stateObject.balance } @@ -63,14 +63,14 @@ func (self *StateDB) GetBalance(addr []byte) *big.Int { } func (self *StateDB) AddBalance(addr []byte, amount *big.Int) { - stateObject := self.GetStateObject(addr) + stateObject := self.GetOrNewStateObject(addr) if stateObject != nil { stateObject.AddBalance(amount) } } func (self *StateDB) GetNonce(addr []byte) uint64 { - stateObject := self.GetStateObject(addr) + stateObject := self.GetOrNewStateObject(addr) if stateObject != nil { return stateObject.nonce } @@ -79,7 +79,7 @@ func (self *StateDB) GetNonce(addr []byte) uint64 { } func (self *StateDB) GetCode(addr []byte) []byte { - stateObject := self.GetStateObject(addr) + stateObject := self.GetOrNewStateObject(addr) if stateObject != nil { return stateObject.code } @@ -88,7 +88,7 @@ func (self *StateDB) GetCode(addr []byte) []byte { } func (self *StateDB) GetState(a, b []byte) []byte { - stateObject := self.GetStateObject(a) + stateObject := self.GetOrNewStateObject(a) if stateObject != nil { return stateObject.GetState(b).Bytes() } @@ -97,28 +97,28 @@ func (self *StateDB) GetState(a, b []byte) []byte { } func (self *StateDB) SetNonce(addr []byte, nonce uint64) { - stateObject := self.GetStateObject(addr) + stateObject := self.GetOrNewStateObject(addr) if stateObject != nil { stateObject.SetNonce(nonce) } } func (self *StateDB) SetCode(addr, code []byte) { - stateObject := self.GetStateObject(addr) + stateObject := self.GetOrNewStateObject(addr) if stateObject != nil { stateObject.SetCode(code) } } func (self *StateDB) SetState(addr, key []byte, value interface{}) { - stateObject := self.GetStateObject(addr) + stateObject := self.GetOrNewStateObject(addr) if stateObject != nil { stateObject.SetState(key, ethutil.NewValue(value)) } } func (self *StateDB) Delete(addr []byte) bool { - stateObject := self.GetStateObject(addr) + stateObject := self.GetOrNewStateObject(addr) if stateObject != nil { stateObject.MarkForDeletion() diff --git a/ui/filter.go b/ui/filter.go index 0d1746915..5b1faa293 100644 --- a/ui/filter.go +++ b/ui/filter.go @@ -1,77 +1 @@ package ui - -import ( - "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/ethutil" -) - -func fromHex(s string) []byte { - if len(s) > 1 { - if s[0:2] == "0x" { - s = s[2:] - } - return ethutil.Hex2Bytes(s) - } - return nil -} - -func NewFilterFromMap(object map[string]interface{}, eth core.Backend) *core.Filter { - filter := core.NewFilter(eth) - - if object["earliest"] != nil { - val := ethutil.NewValue(object["earliest"]) - filter.SetEarliestBlock(val.Int()) - } - - if object["latest"] != nil { - val := ethutil.NewValue(object["latest"]) - filter.SetLatestBlock(val.Int()) - } - - if object["address"] != nil { - //val := ethutil.NewValue(object["address"]) - //filter.SetAddress(fromHex(val.Str())) - } - - if object["max"] != nil { - val := ethutil.NewValue(object["max"]) - filter.SetMax(int(val.Uint())) - } - - if object["skip"] != nil { - val := ethutil.NewValue(object["skip"]) - filter.SetSkip(int(val.Uint())) - } - - if object["topics"] != nil { - filter.SetTopics(MakeTopics(object["topics"])) - } - - return filter -} - -// Conversion methodn -func mapToAccountChange(m map[string]interface{}) (d core.AccountChange) { - if str, ok := m["id"].(string); ok { - d.Address = fromHex(str) - } - - if str, ok := m["at"].(string); ok { - d.StateAddress = fromHex(str) - } - - return -} - -// data can come in in the following formats: -// ["aabbccdd", {id: "ccddee", at: "11223344"}], "aabbcc", {id: "ccddee", at: "1122"} -func MakeTopics(v interface{}) (d [][]byte) { - if str, ok := v.(string); ok { - d = append(d, fromHex(str)) - } else if slice, ok := v.([]string); ok { - for _, item := range slice { - d = append(d, fromHex(item)) - } - } - return -} diff --git a/xeth/xeth.go b/xeth/xeth.go index d4c188fec..677d40fd5 100644 --- a/xeth/xeth.go +++ b/xeth/xeth.go @@ -300,14 +300,6 @@ func (self *XEth) Transact(toStr, valueStr, gasStr, gasPriceStr, codeStr string) tx.SetNonce(nonce) tx.Sign(key.PrivateKey) - //fmt.Printf("create tx: %x %v\n", tx.Hash()[:4], tx.Nonce()) - - // Do some pre processing for our "pre" events and hooks - //block := self.chainManager.NewBlock(key.Address()) - //coinbase := state.GetOrNewStateObject(key.Address()) - //coinbase.SetGasPool(block.GasLimit()) - //self.blockProcessor.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true) - err = self.eth.TxPool().Add(tx) if err != nil { return "", err |