diff --git a/Makefile b/Makefile index 03e3bf4c6f..b243d26796 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,11 @@ geth: @echo "Done building." @echo "Run \"$(GOBIN)/geth\" to launch geth." +console: + build/env.sh go install -v $(shell build/ldflags.sh) ./cmd/console + @echo "Done building." + @echo "Run \"$(GOBIN)/console\" to launch the console." + mist: build/env.sh go install -v $(shell build/ldflags.sh) ./cmd/mist @echo "Done building." diff --git a/cmd/geth/main.go b/cmd/geth/main.go index a355d60084..3deff5df6d 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -239,6 +239,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso utils.RPCListenAddrFlag, utils.RPCPortFlag, utils.IPCDisabledFlag, + utils.IPCApiFlag, utils.IPCPathFlag, utils.WhisperEnabledFlag, utils.VMDebugFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 57bc17c569..03cf682226 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -208,6 +208,11 @@ var ( Name: "ipcdisable", Usage: "Disable the IPC-RPC server", } + IPCApiFlag = cli.StringFlag{ + Name: "ipcapi", + Usage: "Specify the API's which are offered over this interface", + Value: api.DEFAULT_IPC_APIS, + } IPCPathFlag = cli.StringFlag{ Name: "ipcpath", Usage: "Filename for IPC socket/pipe", @@ -382,19 +387,19 @@ func StartRPC(eth *eth.Ethereum, ctx *cli.Context) error { } func StartIPC(eth *eth.Ethereum, ctx *cli.Context) error { - config := comms.IpcConfig{ + codec := codec.JSON + apis, err := api.ParseApiString(ctx.GlobalString(IPCApiFlag.Name), codec, eth) + if err != nil { + return err + } + + glog.V(logger.Error).Infof("IPC api's: %s", ctx.GlobalString(IPCApiFlag.Name)) + + cfg := comms.IpcConfig{ Endpoint: ctx.GlobalString(IPCPathFlag.Name), } - xeth := xeth.New(eth, nil) - // offered API over IPC - codec := codec.JSON - web3Api := api.NewWeb3(xeth, codec) - ethApi := api.NewEth(xeth, codec) - netApi := api.NewNet(xeth, codec) - minerApi := api.NewMiner(eth, codec) - - return comms.StartIpc(config, codec, web3Api, ethApi, netApi, minerApi) + return comms.StartIpc(cfg, codec, apis...) } func StartPProf(ctx *cli.Context) { diff --git a/rpc/api/admin.go b/rpc/api/admin.go index c2f2dea41f..b1b2aa9374 100644 --- a/rpc/api/admin.go +++ b/rpc/api/admin.go @@ -22,13 +22,13 @@ type adminhandler func(*admin, *shared.Request) (interface{}, error) // admin api provider type admin struct { - ethereum ethereum.Ethereum + ethereum *ethereum.Ethereum methods map[string]adminhandler codec codec.ApiCoder } // create a new admin api instance -func NewAdmin(ethereum ethereum.Ethereum, coder codec.Codec) *admin { +func NewAdmin(ethereum *ethereum.Ethereum, coder codec.Codec) *admin { return &admin{ ethereum: ethereum, methods: AdminMapping, @@ -46,3 +46,16 @@ func (self *admin) Methods() []string { } return methods } + +// Execute given request +func (self *admin) Execute(req *shared.Request) (interface{}, error) { + if callback, ok := self.methods[req.Method]; ok { + return callback(self, req) + } + + return nil, &shared.NotImplementedError{req.Method} +} + +func (self *admin) Id() string { + return "admin" +} diff --git a/rpc/api/api.go b/rpc/api/api.go index 0e1e844f76..32c775721b 100644 --- a/rpc/api/api.go +++ b/rpc/api/api.go @@ -1,9 +1,24 @@ package api -import "github.com/ethereum/go-ethereum/rpc/shared" +import ( + "fmt" + + "github.com/ethereum/go-ethereum/rpc/shared" + e "github.com/ethereum/go-ethereum/eth" + "strings" + "github.com/ethereum/go-ethereum/rpc/codec" + "github.com/ethereum/go-ethereum/xeth" +) + +const ( + DEFAULT_IPC_APIS = "admin,debug,eth,miner,net,web3" + DEFAULT_HTTP_APIS = "web3,eth" +) // Descriptor for all API implementations type Ethereum interface { + // API identifier, e.g. admin or web3 + Id() string // Execute single API request Execute(*shared.Request) (interface{}, error) // List with supported methods @@ -37,6 +52,38 @@ func (self *mergedEthereumApi) Execute(req *shared.Request) (interface{}, error) return nil, shared.NewNotImplementedError(req.Method) } +func (self *mergedEthereumApi) Id() string { + return "mergedEthereumApi" +} + func Merge(apis ...Ethereum) Ethereum { return newMergedEthereumApi(apis...) } + +// Parses the given apiString (comma separated list with api identifiers) to a collection of API's +func ParseApiString(apiString string, codec codec.Codec, eth *e.Ethereum) ([]Ethereum, error) { + xeth := xeth.New(eth, nil) + apiNames := strings.Split(apiString, ",") + apis := make([]Ethereum, len(apiNames)) + + for i, name := range apiNames { + switch name { + case "admin": + apis[i] = NewAdmin(eth, codec) + case "eth": + apis[i] = NewEth(xeth, codec) + case "debug": + apis[i] = NewDebug(xeth, eth, codec) + case "miner": + apis[i] = NewMiner(eth, codec) + case "net": + apis[i] = NewNet(xeth, codec) + case "web3": + apis[i] = NewWeb3(xeth, codec) + default: + return nil, fmt.Errorf("Api '%s' isn't supported", name) + } + } + + return apis, nil +} diff --git a/rpc/api/debug.go b/rpc/api/debug.go index 0aab2dda56..6e436cdaf5 100644 --- a/rpc/api/debug.go +++ b/rpc/api/debug.go @@ -35,13 +35,13 @@ type debughandler func(*debug, *shared.Request) (interface{}, error) // admin api provider type debug struct { xeth *xeth.XEth - ethereum ethereum.Ethereum + ethereum *ethereum.Ethereum methods map[string]debughandler codec codec.ApiCoder } // create a new debug api instance -func NewDebug(xeth *xeth.XEth, ethereum ethereum.Ethereum, coder codec.Codec) *debug { +func NewDebug(xeth *xeth.XEth, ethereum *ethereum.Ethereum, coder codec.Codec) *debug { return &debug{ xeth: xeth, ethereum: ethereum, @@ -61,6 +61,19 @@ func (self *debug) Methods() []string { return methods } +// Execute given request +func (self *debug) Execute(req *shared.Request) (interface{}, error) { + if callback, ok := self.methods[req.Method]; ok { + return callback(self, req) + } + + return nil, &shared.NotImplementedError{req.Method} +} + +func (self *debug) Id() string { + return "debug" +} + func (self *debug) PrintBlock(req *shared.Request) (interface{}, error) { args := new(BlockNumArg) if err := self.codec.Decode(req.Params, &args); err != nil { diff --git a/rpc/api/eth.go b/rpc/api/eth.go index 5078cb2d77..e15700fc28 100644 --- a/rpc/api/eth.go +++ b/rpc/api/eth.go @@ -107,6 +107,10 @@ func (self *eth) Version() string { return ethVersion } +func (self *eth) Id() string { + return "eth" +} + func (self *eth) Accounts(req *shared.Request) (interface{}, error) { return self.xeth.Accounts(), nil } diff --git a/rpc/api/miner.go b/rpc/api/miner.go index 058f682e98..5a387b2e51 100644 --- a/rpc/api/miner.go +++ b/rpc/api/miner.go @@ -65,6 +65,10 @@ func (self *miner) Methods() []string { return methods } +func (self *miner) Id() string { + return "miner" +} + func (self *miner) StartMiner(req *shared.Request) (interface{}, error) { args := new(StartMinerArgs) if err := self.codec.Decode(req.Params, &args); err != nil { diff --git a/rpc/api/net.go b/rpc/api/net.go index f6f9b7bff5..465dcc2ef3 100644 --- a/rpc/api/net.go +++ b/rpc/api/net.go @@ -54,6 +54,10 @@ func (self *net) Execute(req *shared.Request) (interface{}, error) { return nil, shared.NewNotImplementedError(req.Method) } +func (self *net) Id() string { + return "net" +} + // Network version func (self *net) Version(req *shared.Request) (interface{}, error) { return self.xeth.NetworkVersion(), nil diff --git a/rpc/api/web3.go b/rpc/api/web3.go index 69d63b26e8..7fa74aff2d 100644 --- a/rpc/api/web3.go +++ b/rpc/api/web3.go @@ -59,6 +59,10 @@ func (self *web3) Execute(req *shared.Request) (interface{}, error) { return nil, &shared.NotImplementedError{req.Method} } +func (self *web3) Id() string { + return "web3" +} + // Version of the API this instance provides func (self *web3) Version() string { return Web3Version