mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
added ipcapi commandline flag
This commit is contained in:
parent
1768d51244
commit
b036853917
10 changed files with 115 additions and 15 deletions
5
Makefile
5
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."
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue