aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cmd/ethereum/flags.go73
-rw-r--r--cmd/ethereum/main.go35
-rw-r--r--cmd/mist/flags.go52
-rw-r--r--cmd/mist/main.go2
-rw-r--r--cmd/utils/cmd.go4
-rw-r--r--core/filter.go35
-rw-r--r--ethutil/common.go13
-rw-r--r--javascript/types.go15
-rw-r--r--miner/miner.go7
-rw-r--r--miner/worker.go14
-rw-r--r--rpc/args.go18
-rw-r--r--rpc/http/server.go8
-rw-r--r--state/statedb.go18
-rw-r--r--ui/filter.go76
-rw-r--r--xeth/xeth.go8
15 files changed, 169 insertions, 209 deletions
diff --git a/cmd/ethereum/flags.go b/cmd/ethereum/flags.go
index c42083160..356571a23 100644
--- a/cmd/ethereum/flags.go
+++ b/cmd/ethereum/flags.go
@@ -27,6 +27,7 @@ import (
"log"
"os"
"path"
+ "runtime"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethutil"
@@ -36,40 +37,42 @@ import (
)
var (
- Identifier string
- KeyRing string
- DiffTool bool
- DiffType string
- KeyStore string
- StartRpc bool
- StartWebSockets bool
- RpcPort int
- WsPort int
- OutboundPort string
- ShowGenesis bool
- AddPeer string
- MaxPeer int
- GenAddr bool
- BootNodes string
- NodeKey *ecdsa.PrivateKey
- NAT nat.Interface
- SecretFile string
- ExportDir string
- NonInteractive bool
- Datadir string
- LogFile string
- ConfigFile string
- DebugFile string
- LogLevel int
- LogFormat string
- Dump bool
- DumpHash string
- DumpNumber int
- VmType int
- ImportChain string
- SHH bool
- Dial bool
- PrintVersion bool
+ Identifier string
+ KeyRing string
+ DiffTool bool
+ DiffType string
+ KeyStore string
+ StartRpc bool
+ StartWebSockets bool
+ RpcListenAddress string
+ RpcPort int
+ WsPort int
+ OutboundPort string
+ ShowGenesis bool
+ AddPeer string
+ MaxPeer int
+ GenAddr bool
+ BootNodes string
+ NodeKey *ecdsa.PrivateKey
+ NAT nat.Interface
+ SecretFile string
+ ExportDir string
+ NonInteractive bool
+ Datadir string
+ LogFile string
+ ConfigFile string
+ DebugFile string
+ LogLevel int
+ LogFormat string
+ Dump bool
+ DumpHash string
+ DumpNumber int
+ VmType int
+ ImportChain string
+ SHH bool
+ Dial bool
+ PrintVersion bool
+ MinerThreads int
)
// flags specific to cli client
@@ -93,6 +96,7 @@ func Init() {
flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)")
+ 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")
@@ -119,6 +123,7 @@ func Init() {
flag.BoolVar(&StartMining, "mine", false, "start dagger mining")
flag.BoolVar(&StartJsConsole, "js", false, "launches javascript console")
flag.BoolVar(&PrintVersion, "version", false, "prints version number")
+ flag.IntVar(&MinerThreads, "minerthreads", runtime.NumCPU(), "number of miner threads")
// Network stuff
var (
diff --git a/cmd/ethereum/main.go b/cmd/ethereum/main.go
index dc25e4ae0..9d78b6282 100644
--- a/cmd/ethereum/main.go
+++ b/cmd/ethereum/main.go
@@ -62,20 +62,21 @@ func main() {
utils.InitConfig(VmType, ConfigFile, Datadir, "ETH")
ethereum, err := eth.New(&eth.Config{
- Name: p2p.MakeName(ClientIdentifier, Version),
- KeyStore: KeyStore,
- DataDir: Datadir,
- LogFile: LogFile,
- LogLevel: LogLevel,
- LogFormat: LogFormat,
- MaxPeers: MaxPeer,
- Port: OutboundPort,
- NAT: NAT,
- KeyRing: KeyRing,
- Shh: true,
- Dial: Dial,
- BootNodes: BootNodes,
- NodeKey: NodeKey,
+ Name: p2p.MakeName(ClientIdentifier, Version),
+ KeyStore: KeyStore,
+ DataDir: Datadir,
+ LogFile: LogFile,
+ LogLevel: LogLevel,
+ LogFormat: LogFormat,
+ MaxPeers: MaxPeer,
+ Port: OutboundPort,
+ NAT: NAT,
+ KeyRing: KeyRing,
+ Shh: true,
+ Dial: Dial,
+ BootNodes: BootNodes,
+ NodeKey: NodeKey,
+ MinerThreads: MinerThreads,
})
if err != nil {
@@ -128,7 +129,7 @@ func main() {
}
if StartRpc {
- utils.StartRpc(ethereum, RpcPort)
+ utils.StartRpc(ethereum, RpcListenAddress, RpcPort)
}
if StartWebSockets {
@@ -139,6 +140,10 @@ func main() {
fmt.Printf("Welcome to the FRONTIER\n")
+ if StartMining {
+ ethereum.Miner().Start()
+ }
+
if StartJsConsole {
InitJsConsole(ethereum)
} else if len(InputFile) > 0 {
diff --git a/cmd/mist/flags.go b/cmd/mist/flags.go
index 0010df826..1ffeb1915 100644
--- a/cmd/mist/flags.go
+++ b/cmd/mist/flags.go
@@ -37,31 +37,32 @@ import (
)
var (
- Identifier string
- KeyRing string
- KeyStore string
- StartRpc bool
- StartWebSockets bool
- RpcPort int
- WsPort int
- OutboundPort string
- ShowGenesis bool
- AddPeer string
- MaxPeer int
- GenAddr bool
- BootNodes string
- NodeKey *ecdsa.PrivateKey
- NAT nat.Interface
- SecretFile string
- ExportDir string
- NonInteractive bool
- Datadir string
- LogFile string
- ConfigFile string
- DebugFile string
- LogLevel int
- VmType int
- MinerThreads int
+ Identifier string
+ KeyRing string
+ KeyStore string
+ StartRpc bool
+ StartWebSockets bool
+ RpcListenAddress string
+ RpcPort int
+ WsPort int
+ OutboundPort string
+ ShowGenesis bool
+ AddPeer string
+ MaxPeer int
+ GenAddr bool
+ BootNodes string
+ NodeKey *ecdsa.PrivateKey
+ NAT nat.Interface
+ SecretFile string
+ ExportDir string
+ NonInteractive bool
+ Datadir string
+ LogFile string
+ ConfigFile string
+ DebugFile string
+ LogLevel int
+ VmType int
+ MinerThreads int
)
// flags specific to gui client
@@ -79,6 +80,7 @@ func Init() {
flag.StringVar(&Identifier, "id", "", "Custom client identifier")
flag.StringVar(&KeyRing, "keyring", "", "identifier for keyring to use")
flag.StringVar(&KeyStore, "keystore", "db", "system to store keyrings: db|file (db)")
+ 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")
diff --git a/cmd/mist/main.go b/cmd/mist/main.go
index 3abe16767..c9a07bfde 100644
--- a/cmd/mist/main.go
+++ b/cmd/mist/main.go
@@ -73,7 +73,7 @@ func run() error {
utils.KeyTasks(ethereum.KeyManager(), KeyRing, GenAddr, SecretFile, ExportDir, NonInteractive)
if StartRpc {
- utils.StartRpc(ethereum, RpcPort)
+ utils.StartRpc(ethereum, RpcListenAddress, RpcPort)
}
if StartWebSockets {
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index 03ad883d7..794753f11 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -159,9 +159,9 @@ func KeyTasks(keyManager *crypto.KeyManager, KeyRing string, GenAddr bool, Secre
clilogger.Infof("Main address %x\n", keyManager.Address())
}
-func StartRpc(ethereum *eth.Ethereum, RpcPort int) {
+func StartRpc(ethereum *eth.Ethereum, RpcListenAddress string, RpcPort int) {
var err error
- ethereum.RpcServer, err = rpchttp.NewRpcHttpServer(xeth.New(ethereum), RpcPort)
+ ethereum.RpcServer, err = rpchttp.NewRpcHttpServer(xeth.New(ethereum), RpcListenAddress, RpcPort)
if err != nil {
clilogger.Errorf("Could not start RPC interface (port %v): %v", RpcPort, err)
} else {
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/ethutil/common.go b/ethutil/common.go
index c4e7415dc..9b66763b8 100644
--- a/ethutil/common.go
+++ b/ethutil/common.go
@@ -15,11 +15,13 @@ import (
func DefaultAssetPath() string {
var assetPath string
+ pwd, _ := os.Getwd()
+ srcdir := path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist")
+
// If the current working directory is the go-ethereum dir
// assume a debug build and use the source directory as
// asset directory.
- pwd, _ := os.Getwd()
- if pwd == path.Join(os.Getenv("GOPATH"), "src", "github.com", "ethereum", "go-ethereum", "cmd", "mist") {
+ if pwd == srcdir {
assetPath = path.Join(pwd, "assets")
} else {
switch runtime.GOOS {
@@ -35,6 +37,13 @@ func DefaultAssetPath() string {
assetPath = "."
}
}
+
+ // Check if the assetPath exists. If not, try the source directory
+ // This happens when binary is run from outside cmd/mist directory
+ if _, err := os.Stat(assetPath); os.IsNotExist(err) {
+ assetPath = path.Join(srcdir, "assets")
+ }
+
return assetPath
}
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/miner/miner.go b/miner/miner.go
index f207948a5..b60422a3a 100644
--- a/miner/miner.go
+++ b/miner/miner.go
@@ -55,10 +55,5 @@ func (self *Miner) Stop() {
}
func (self *Miner) HashRate() int64 {
- var tot int64
- for _, agent := range self.worker.agents {
- tot += agent.Pow().GetHashrate()
- }
-
- return tot
+ return self.worker.HashRate()
}
diff --git a/miner/worker.go b/miner/worker.go
index fe80b63ee..774ef9a7e 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -5,6 +5,7 @@ import (
"math/big"
"sort"
"sync"
+ "time"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
@@ -113,6 +114,8 @@ func (self *worker) register(agent Agent) {
func (self *worker) update() {
events := self.mux.Subscribe(core.ChainEvent{}, core.NewMinedBlockEvent{})
+ timer := time.NewTicker(2 * time.Second)
+
out:
for {
select {
@@ -131,6 +134,8 @@ out:
agent.Stop()
}
break out
+ case <-timer.C:
+ minerlogger.Debugln("Hash rate:", self.HashRate(), "Khash")
}
}
@@ -250,3 +255,12 @@ func (self *worker) commitTransaction(tx *types.Transaction) error {
return nil
}
+
+func (self *worker) HashRate() int64 {
+ var tot int64
+ for _, agent := range self.agents {
+ tot += agent.Pow().GetHashrate()
+ }
+
+ return tot
+}
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/http/server.go b/rpc/http/server.go
index fa66eed48..452b7c9af 100644
--- a/rpc/http/server.go
+++ b/rpc/http/server.go
@@ -29,8 +29,8 @@ import (
var rpchttplogger = logger.NewLogger("RPC-HTTP")
var JSON rpc.JsonWrapper
-func NewRpcHttpServer(pipe *xeth.XEth, port int) (*RpcHttpServer, error) {
- sport := fmt.Sprintf("127.0.0.1:%d", port)
+func NewRpcHttpServer(pipe *xeth.XEth, address string, port int) (*RpcHttpServer, error) {
+ sport := fmt.Sprintf("%s:%d", address, port)
l, err := net.Listen("tcp", sport)
if err != nil {
return nil, err
@@ -41,6 +41,7 @@ func NewRpcHttpServer(pipe *xeth.XEth, port int) (*RpcHttpServer, error) {
quit: make(chan bool),
pipe: pipe,
port: port,
+ addr: address,
}, nil
}
@@ -49,6 +50,7 @@ type RpcHttpServer struct {
listener net.Listener
pipe *xeth.XEth
port int
+ addr string
}
func (s *RpcHttpServer) exitHandler() {
@@ -69,7 +71,7 @@ func (s *RpcHttpServer) Stop() {
}
func (s *RpcHttpServer) Start() {
- rpchttplogger.Infof("Starting RPC-HTTP server on port %d", s.port)
+ rpchttplogger.Infof("Starting RPC-HTTP server on %s:%d", s.addr, s.port)
go s.exitHandler()
api := rpc.NewEthereumApi(s.pipe)
diff --git a/state/statedb.go b/state/statedb.go
index 2ef928a9d..1231b4c1d 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