aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/packages.go
diff options
context:
space:
mode:
Diffstat (limited to 'rpc/packages.go')
-rw-r--r--rpc/packages.go48
1 files changed, 26 insertions, 22 deletions
diff --git a/rpc/packages.go b/rpc/packages.go
index e87e0db7c..e6d4859d2 100644
--- a/rpc/packages.go
+++ b/rpc/packages.go
@@ -33,8 +33,17 @@ import (
"github.com/ethereum/go-ethereum/xeth"
)
+type RpcServer interface {
+ Start()
+ Stop()
+}
+
+func NewEthereumApi(xeth *xeth.JSXEth) *EthereumApi {
+ return &EthereumApi{xeth: xeth}
+}
+
type EthereumApi struct {
- pipe *xeth.JSXEth
+ xeth *xeth.JSXEth
}
func (p *EthereumApi) GetBlock(args *GetBlockArgs, reply *interface{}) error {
@@ -44,9 +53,9 @@ func (p *EthereumApi) GetBlock(args *GetBlockArgs, reply *interface{}) error {
}
if args.BlockNumber > 0 {
- *reply = p.pipe.BlockByNumber(args.BlockNumber)
+ *reply = p.xeth.BlockByNumber(args.BlockNumber)
} else {
- *reply = p.pipe.BlockByHash(args.Hash)
+ *reply = p.xeth.BlockByHash(args.Hash)
}
return nil
}
@@ -56,7 +65,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) error {
if err != nil {
return err
}
- result, _ := p.pipe.Transact(p.pipe.Key().PrivateKey, args.Recipient, args.Value, args.Gas, args.GasPrice, args.Body)
+ result, _ := p.xeth.Transact( /* TODO specify account */ "", args.Recipient, args.Value, args.Gas, args.GasPrice, args.Body)
*reply = result
return nil
}
@@ -67,7 +76,7 @@ func (p *EthereumApi) Create(args *NewTxArgs, reply *interface{}) error {
return err
}
- result, _ := p.pipe.Transact(p.pipe.Key().PrivateKey, "", args.Value, args.Gas, args.GasPrice, args.Body)
+ result, _ := p.xeth.Transact( /* TODO specify account */ "", "", args.Value, args.Gas, args.GasPrice, args.Body)
*reply = result
return nil
}
@@ -77,23 +86,18 @@ func (p *EthereumApi) PushTx(args *PushTxArgs, reply *interface{}) error {
if err != nil {
return err
}
- result, _ := p.pipe.PushTx(args.Tx)
+ result, _ := p.xeth.PushTx(args.Tx)
*reply = result
return nil
}
-func (p *EthereumApi) GetKey(args interface{}, reply *interface{}) error {
- *reply = p.pipe.Key()
- return nil
-}
-
func (p *EthereumApi) GetStorageAt(args *GetStorageArgs, reply *interface{}) error {
err := args.requirements()
if err != nil {
return err
}
- state := p.pipe.World().SafeGet(ethutil.Hex2Bytes(args.Address))
+ state := p.xeth.State().SafeGet(args.Address)
var hx string
if strings.Index(args.Key, "0x") == 0 {
@@ -103,29 +107,29 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageArgs, reply *interface{}) err
i, _ := new(big.Int).SetString(args.Key, 10)
hx = ethutil.Bytes2Hex(i.Bytes())
}
- jsonlogger.Debugf("GetStorageAt(%s, %s)\n", args.Address, hx)
+ rpclogger.Debugf("GetStorageAt(%s, %s)\n", args.Address, hx)
value := state.Storage(ethutil.Hex2Bytes(hx))
*reply = GetStorageAtRes{Address: args.Address, Key: args.Key, Value: value.Str()}
return nil
}
func (p *EthereumApi) GetPeerCount(reply *interface{}) error {
- *reply = p.pipe.PeerCount()
+ *reply = p.xeth.PeerCount()
return nil
}
func (p *EthereumApi) GetIsListening(reply *interface{}) error {
- *reply = p.pipe.IsListening()
+ *reply = p.xeth.IsListening()
return nil
}
func (p *EthereumApi) GetCoinbase(reply *interface{}) error {
- *reply = p.pipe.CoinBase()
+ *reply = p.xeth.Coinbase()
return nil
}
func (p *EthereumApi) GetIsMining(reply *interface{}) error {
- *reply = p.pipe.IsMining()
+ *reply = p.xeth.IsMining()
return nil
}
@@ -134,7 +138,7 @@ func (p *EthereumApi) GetTxCountAt(args *GetTxCountArgs, reply *interface{}) err
if err != nil {
return err
}
- *reply = p.pipe.TxCountAt(args.Address)
+ *reply = p.xeth.TxCountAt(args.Address)
return nil
}
@@ -143,7 +147,7 @@ func (p *EthereumApi) GetBalanceAt(args *GetBalanceArgs, reply *interface{}) err
if err != nil {
return err
}
- state := p.pipe.World().SafeGet(ethutil.Hex2Bytes(args.Address))
+ state := p.xeth.State().SafeGet(args.Address)
*reply = BalanceRes{Balance: state.Balance().String(), Address: args.Address}
return nil
}
@@ -153,13 +157,13 @@ func (p *EthereumApi) GetCodeAt(args *GetCodeAtArgs, reply *interface{}) error {
if err != nil {
return err
}
- *reply = p.pipe.CodeAt(args.Address)
+ *reply = p.xeth.CodeAt(args.Address)
return nil
}
func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error {
// Spec at https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC
- jsonlogger.DebugDetailf("%T %s", req.Params, req.Params)
+ rpclogger.DebugDetailf("%T %s", req.Params, req.Params)
switch req.Method {
case "eth_coinbase":
return p.GetCoinbase(reply)
@@ -203,6 +207,6 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
return NewErrorResponse(ErrorNotImplemented)
}
- jsonlogger.DebugDetailf("Reply: %T %s", reply, reply)
+ rpclogger.DebugDetailf("Reply: %T %s", reply, reply)
return nil
}