aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/api
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-11-18 00:33:25 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-11-27 17:06:12 +0800
commit1e806c4c775bd98b224eb0249007502d348e737b (patch)
treea34bfcac320df6f65e73eb1578b212289be86b5f /rpc/api
parent8a44451edfa36ea40da564a2fa7ea905d45440a4 (diff)
downloadgo-tangerine-1e806c4c775bd98b224eb0249007502d348e737b.tar
go-tangerine-1e806c4c775bd98b224eb0249007502d348e737b.tar.gz
go-tangerine-1e806c4c775bd98b224eb0249007502d348e737b.tar.bz2
go-tangerine-1e806c4c775bd98b224eb0249007502d348e737b.tar.lz
go-tangerine-1e806c4c775bd98b224eb0249007502d348e737b.tar.xz
go-tangerine-1e806c4c775bd98b224eb0249007502d348e737b.tar.zst
go-tangerine-1e806c4c775bd98b224eb0249007502d348e737b.zip
cmd, common, core, eth, node, rpc, tests, whisper, xeth: use protocol stacks
Diffstat (limited to 'rpc/api')
-rw-r--r--rpc/api/admin.go37
-rw-r--r--rpc/api/api_test.go2
-rw-r--r--rpc/api/utils.go12
3 files changed, 32 insertions, 19 deletions
diff --git a/rpc/api/admin.go b/rpc/api/admin.go
index c11662577..4682062e0 100644
--- a/rpc/api/admin.go
+++ b/rpc/api/admin.go
@@ -32,6 +32,8 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/node"
+ "github.com/ethereum/go-ethereum/p2p/discover"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/comms"
@@ -80,19 +82,24 @@ type adminhandler func(*adminApi, *shared.Request) (interface{}, error)
// admin api provider
type adminApi struct {
xeth *xeth.XEth
+ stack *node.Node
ethereum *eth.Ethereum
codec codec.Codec
coder codec.ApiCoder
}
// create a new admin api instance
-func NewAdminApi(xeth *xeth.XEth, ethereum *eth.Ethereum, codec codec.Codec) *adminApi {
- return &adminApi{
- xeth: xeth,
- ethereum: ethereum,
- codec: codec,
- coder: codec.New(nil),
+func NewAdminApi(xeth *xeth.XEth, stack *node.Node, codec codec.Codec) *adminApi {
+ api := &adminApi{
+ xeth: xeth,
+ stack: stack,
+ codec: codec,
+ coder: codec.New(nil),
}
+ if stack != nil {
+ stack.SingletonService(&api.ethereum)
+ }
+ return api
}
// collection with supported methods
@@ -128,24 +135,24 @@ func (self *adminApi) AddPeer(req *shared.Request) (interface{}, error) {
if err := self.coder.Decode(req.Params, &args); err != nil {
return nil, shared.NewDecodeParamError(err.Error())
}
-
- err := self.ethereum.AddPeer(args.Url)
- if err == nil {
- return true, nil
+ node, err := discover.ParseNode(args.Url)
+ if err != nil {
+ return nil, fmt.Errorf("invalid node URL: %v", err)
}
- return false, err
+ self.stack.Server().AddPeer(node)
+ return true, nil
}
func (self *adminApi) Peers(req *shared.Request) (interface{}, error) {
- return self.ethereum.Network().PeersInfo(), nil
+ return self.stack.Server().PeersInfo(), nil
}
func (self *adminApi) NodeInfo(req *shared.Request) (interface{}, error) {
- return self.ethereum.Network().NodeInfo(), nil
+ return self.stack.Server().NodeInfo(), nil
}
func (self *adminApi) DataDir(req *shared.Request) (interface{}, error) {
- return self.ethereum.DataDir, nil
+ return self.stack.DataDir(), nil
}
func hasAllBlocks(chain *core.BlockChain, bs []*types.Block) bool {
@@ -253,7 +260,7 @@ func (self *adminApi) StartRPC(req *shared.Request) (interface{}, error) {
CorsDomain: args.CorsDomain,
}
- apis, err := ParseApiString(args.Apis, self.codec, self.xeth, self.ethereum)
+ apis, err := ParseApiString(args.Apis, self.codec, self.xeth, self.stack)
if err != nil {
return false, err
}
diff --git a/rpc/api/api_test.go b/rpc/api/api_test.go
index 131ef68f8..eb63e8151 100644
--- a/rpc/api/api_test.go
+++ b/rpc/api/api_test.go
@@ -93,7 +93,7 @@ func TestCompileSolidity(t *testing.T) {
expSource := source
eth := &eth.Ethereum{}
- xeth := xeth.NewTest(eth, nil)
+ xeth := xeth.NewTest(nil, nil)
api := NewEthApi(xeth, eth, codec.JSON)
var rpcRequest shared.Request
diff --git a/rpc/api/utils.go b/rpc/api/utils.go
index 8351e88d3..6e372c061 100644
--- a/rpc/api/utils.go
+++ b/rpc/api/utils.go
@@ -22,6 +22,7 @@ import (
"fmt"
"github.com/ethereum/go-ethereum/eth"
+ "github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/xeth"
@@ -154,7 +155,7 @@ var (
)
// Parse a comma separated API string to individual api's
-func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, eth *eth.Ethereum) ([]shared.EthereumApi, error) {
+func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, stack *node.Node) ([]shared.EthereumApi, error) {
if len(strings.TrimSpace(apistr)) == 0 {
return nil, fmt.Errorf("Empty apistr provided")
}
@@ -162,10 +163,16 @@ func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, eth *eth.
names := strings.Split(apistr, ",")
apis := make([]shared.EthereumApi, len(names))
+ var eth *eth.Ethereum
+ if stack != nil {
+ if _, err := stack.SingletonService(&eth); err != nil {
+ return nil, err
+ }
+ }
for i, name := range names {
switch strings.ToLower(strings.TrimSpace(name)) {
case shared.AdminApiName:
- apis[i] = NewAdminApi(xeth, eth, codec)
+ apis[i] = NewAdminApi(xeth, stack, codec)
case shared.DebugApiName:
apis[i] = NewDebugApi(xeth, eth, codec)
case shared.DbApiName:
@@ -188,7 +195,6 @@ func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, eth *eth.
return nil, fmt.Errorf("Unknown API '%s'", name)
}
}
-
return apis, nil
}