diff options
Diffstat (limited to 'ethrpc/packages.go')
-rw-r--r-- | ethrpc/packages.go | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/ethrpc/packages.go b/ethrpc/packages.go index 0662f0edd..f2e57fa49 100644 --- a/ethrpc/packages.go +++ b/ethrpc/packages.go @@ -3,14 +3,15 @@ package ethrpc import ( "encoding/json" "errors" - "github.com/ethereum/eth-go/ethpub" - "github.com/ethereum/eth-go/ethutil" "math/big" "strings" + + "github.com/ethereum/eth-go/ethpipe" + "github.com/ethereum/eth-go/ethutil" ) type EthereumApi struct { - ethp *ethpub.PEthereum + pipe *ethpipe.JSPipe } type JsonArgs interface { @@ -72,8 +73,8 @@ func (p *EthereumApi) GetBlock(args *GetBlockArgs, reply *string) error { if err != nil { return err } - // Do something - block := p.ethp.GetBlock(args.Hash) + + block := p.pipe.BlockByHash(args.Hash) *reply = NewSuccessRes(block) return nil } @@ -128,7 +129,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *string) error { if err != nil { return err } - result, _ := p.ethp.Transact(p.ethp.GetKey().PrivateKey, args.Recipient, args.Value, args.Gas, args.GasPrice, args.Body) + result, _ := p.pipe.Transact(p.pipe.Key().PrivateKey, args.Recipient, args.Value, args.Gas, args.GasPrice, args.Body) *reply = NewSuccessRes(result) return nil } @@ -138,13 +139,14 @@ func (p *EthereumApi) Create(args *NewTxArgs, reply *string) error { if err != nil { return err } - result, _ := p.ethp.Create(p.ethp.GetKey().PrivateKey, args.Value, args.Gas, args.GasPrice, args.Body) + + result, _ := p.pipe.Transact(p.pipe.Key().PrivateKey, "", args.Value, args.Gas, args.GasPrice, args.Body) *reply = NewSuccessRes(result) return nil } func (p *EthereumApi) GetKey(args interface{}, reply *string) error { - *reply = NewSuccessRes(p.ethp.GetKey()) + *reply = NewSuccessRes(p.pipe.Key()) return nil } @@ -174,7 +176,8 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageArgs, reply *string) error { if err != nil { return err } - state := p.ethp.GetStateObject(args.Address) + + state := p.pipe.World().SafeGet(ethutil.Hex2Bytes(args.Address)) var hx string if strings.Index(args.Key, "0x") == 0 { @@ -185,8 +188,8 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageArgs, reply *string) error { hx = ethutil.Bytes2Hex(i.Bytes()) } logger.Debugf("GetStorageAt(%s, %s)\n", args.Address, hx) - value := state.GetStorage(hx) - *reply = NewSuccessRes(GetStorageAtRes{Address: args.Address, Key: args.Key, Value: value}) + value := state.Storage(ethutil.Hex2Bytes(hx)) + *reply = NewSuccessRes(GetStorageAtRes{Address: args.Address, Key: args.Key, Value: value.Str()}) return nil } @@ -209,7 +212,7 @@ type GetPeerCountRes struct { } func (p *EthereumApi) GetPeerCount(args *interface{}, reply *string) error { - *reply = NewSuccessRes(GetPeerCountRes{PeerCount: p.ethp.GetPeerCount()}) + *reply = NewSuccessRes(GetPeerCountRes{PeerCount: p.pipe.PeerCount()}) return nil } @@ -218,7 +221,7 @@ type GetListeningRes struct { } func (p *EthereumApi) GetIsListening(args *interface{}, reply *string) error { - *reply = NewSuccessRes(GetListeningRes{IsListening: p.ethp.GetIsListening()}) + *reply = NewSuccessRes(GetListeningRes{IsListening: p.pipe.IsListening()}) return nil } @@ -227,7 +230,7 @@ type GetCoinbaseRes struct { } func (p *EthereumApi) GetCoinbase(args *interface{}, reply *string) error { - *reply = NewSuccessRes(GetCoinbaseRes{Coinbase: p.ethp.GetCoinBase()}) + *reply = NewSuccessRes(GetCoinbaseRes{Coinbase: p.pipe.CoinBase()}) return nil } @@ -236,7 +239,7 @@ type GetMiningRes struct { } func (p *EthereumApi) GetIsMining(args *interface{}, reply *string) error { - *reply = NewSuccessRes(GetMiningRes{IsMining: p.ethp.GetIsMining()}) + *reply = NewSuccessRes(GetMiningRes{IsMining: p.pipe.IsMining()}) return nil } @@ -245,7 +248,7 @@ func (p *EthereumApi) GetTxCountAt(args *GetTxCountArgs, reply *string) error { if err != nil { return err } - state := p.ethp.GetTxCountAt(args.Address) + state := p.pipe.TxCountAt(args.Address) *reply = NewSuccessRes(GetTxCountRes{Nonce: state}) return nil } @@ -271,8 +274,8 @@ func (p *EthereumApi) GetBalanceAt(args *GetBalanceArgs, reply *string) error { if err != nil { return err } - state := p.ethp.GetStateObject(args.Address) - *reply = NewSuccessRes(BalanceRes{Balance: state.Value(), Address: args.Address}) + state := p.pipe.World().SafeGet(ethutil.Hex2Bytes(args.Address)) + *reply = NewSuccessRes(BalanceRes{Balance: state.Balance.String(), Address: args.Address}) return nil } |