diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2015-03-20 11:28:45 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2015-03-20 11:28:45 +0800 |
commit | 19360c00795d356d052a379663c3f36aedba3f9e (patch) | |
tree | 1cadbb43e1490221d8ae0e18d022514be39f4cce /rpc | |
parent | 6669ef5b701f8b060287c8a63e9f3c1116b4b74a (diff) | |
download | go-tangerine-19360c00795d356d052a379663c3f36aedba3f9e.tar go-tangerine-19360c00795d356d052a379663c3f36aedba3f9e.tar.gz go-tangerine-19360c00795d356d052a379663c3f36aedba3f9e.tar.bz2 go-tangerine-19360c00795d356d052a379663c3f36aedba3f9e.tar.lz go-tangerine-19360c00795d356d052a379663c3f36aedba3f9e.tar.xz go-tangerine-19360c00795d356d052a379663c3f36aedba3f9e.tar.zst go-tangerine-19360c00795d356d052a379663c3f36aedba3f9e.zip |
Move stateAt func to XEth
Diffstat (limited to 'rpc')
-rw-r--r-- | rpc/api.go | 36 |
1 files changed, 6 insertions, 30 deletions
diff --git a/rpc/api.go b/rpc/api.go index 06014c74f..f31b9a344 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -10,11 +10,9 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" - "github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/xeth" ) @@ -53,28 +51,6 @@ func (self *EthereumApi) xeth() *xeth.XEth { return self.eth } -func (self *EthereumApi) xethWithStateNum(num int64) *xeth.XEth { - chain := self.xeth().Backend().ChainManager() - var block *types.Block - - if num < 0 { - num = chain.CurrentBlock().Number().Int64() + num + 1 - } - block = chain.GetBlockByNumber(uint64(num)) - - var st *state.StateDB - if block != nil { - st = state.New(block.Root(), self.xeth().Backend().StateDb()) - } else { - st = chain.State() - } - return self.xeth().WithState(st) -} - -func (self *EthereumApi) getStateWithNum(num int64) *xeth.State { - return self.xethWithStateNum(num).State() -} - // func (self *EthereumApi) Register(args string, reply *interface{}) error { // self.regmut.Lock() // defer self.regmut.Unlock() @@ -152,7 +128,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error) } func (p *EthereumApi) Call(args *NewTxArgs, reply *interface{}) error { - result, err := p.xethWithStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data) + result, err := p.xeth().AtStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data) if err != nil { return err } @@ -166,7 +142,7 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e return err } - state := p.xethWithStateNum(args.BlockNumber).State().SafeGet(args.Address) + state := p.xeth().AtStateNum(args.BlockNumber).State().SafeGet(args.Address) value := state.StorageString(args.Key) var hx string @@ -240,7 +216,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - *reply = common.ToHex(p.xethWithStateNum(args.BlockNumber).State().SafeGet(args.Address).Balance().Bytes()) + *reply = common.ToHex(p.xeth().AtStateNum(args.BlockNumber).State().SafeGet(args.Address).Balance().Bytes()) case "eth_getStorage", "eth_storageAt": args := new(GetStorageArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -251,7 +227,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - *reply = p.xethWithStateNum(args.BlockNumber).State().SafeGet(args.Address).Storage() + *reply = p.xeth().AtStateNum(args.BlockNumber).State().SafeGet(args.Address).Storage() case "eth_getStorageAt": args := new(GetStorageAtArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -269,7 +245,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - *reply = p.xethWithStateNum(args.BlockNumber).TxCountAt(args.Address) + *reply = p.xeth().AtStateNum(args.BlockNumber).TxCountAt(args.Address) case "eth_getBlockTransactionCountByHash": args := new(GetBlockByHashArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -314,7 +290,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := args.requirements(); err != nil { return err } - *reply = p.xethWithStateNum(args.BlockNumber).CodeAt(args.Address) + *reply = p.xeth().AtStateNum(args.BlockNumber).CodeAt(args.Address) case "eth_sendTransaction", "eth_transact": args := new(NewTxArgs) if err := json.Unmarshal(req.Params, &args); err != nil { |