From 7330c97b5b00255db9dc1ffaff942992f80fb7d1 Mon Sep 17 00:00:00 2001 From: Maran Date: Mon, 16 Mar 2015 15:17:19 +0100 Subject: DRY up the use of toHex in the project and move it to common --- rpc/api.go | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 1846e7db5..7ce360f86 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -9,11 +9,11 @@ import ( "sync" "time" + "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/common" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event/filter" "github.com/ethereum/go-ethereum/state" @@ -251,7 +251,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error) result, _ := account.Transact(common.FromHex(args.To), common.FromHex(args.Value), common.FromHex(args.Gas), common.FromHex(args.GasPrice), common.FromHex(args.Data)) if len(result) > 0 { - *reply = toHex(result) + *reply = common.ToHex(result) } } else if _, exists := p.register[args.From]; exists { p.register[ags.From] = append(p.register[args.From], args) @@ -291,7 +291,7 @@ func (p *EthereumApi) GetBalance(args *GetBalanceArgs, reply *interface{}) error return err } state := p.getStateWithNum(args.BlockNumber).SafeGet(args.Address) - *reply = toHex(state.Balance().Bytes()) + *reply = common.ToHex(state.Balance().Bytes()) return nil } @@ -384,7 +384,7 @@ func (p *EthereumApi) NewWhisperFilter(args *WhisperFilterArgs, reply *interface } id = p.xeth().Whisper().Watch(opts) p.messages[id] = &whisperFilter{timeout: time.Now()} - *reply = toHex(big.NewInt(int64(id)).Bytes()) + *reply = common.ToHex(big.NewInt(int64(id)).Bytes()) return nil } @@ -480,7 +480,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - *reply = toHex(crypto.Sha3(common.FromHex(args.Data))) + *reply = common.ToHex(crypto.Sha3(common.FromHex(args.Data))) case "web3_clientVersion": *reply = p.xeth().Backend().Version() case "net_version": @@ -488,7 +488,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error case "net_listening": *reply = p.xeth().IsListening() case "net_peerCount": - *reply = toHex(big.NewInt(int64(p.xeth().PeerCount())).Bytes()) + *reply = common.ToHex(big.NewInt(int64(p.xeth().PeerCount())).Bytes()) case "eth_coinbase": // TODO handling of empty coinbase due to lack of accounts res := p.xeth().Coinbase() @@ -500,11 +500,11 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error case "eth_mining": *reply = p.xeth().IsMining() case "eth_gasPrice": - *reply = toHex(defaultGasPrice.Bytes()) + *reply = common.ToHex(defaultGasPrice.Bytes()) case "eth_accounts": *reply = p.xeth().Accounts() case "eth_blockNumber": - *reply = toHex(p.xeth().Backend().ChainManager().CurrentBlock().Number().Bytes()) + *reply = common.ToHex(p.xeth().Backend().ChainManager().CurrentBlock().Number().Bytes()) case "eth_getBalance": args := new(GetBalanceArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -539,7 +539,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err != nil { return err } - *reply = toHex(big.NewInt(v).Bytes()) + *reply = common.ToHex(big.NewInt(v).Bytes()) case "eth_getBlockTransactionCountByNumber": args := new(GetBlockByNumberArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -550,7 +550,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err != nil { return err } - *reply = toHex(big.NewInt(v).Bytes()) + *reply = common.ToHex(big.NewInt(v).Bytes()) case "eth_getUncleCountByBlockHash": args := new(GetBlockByHashArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -561,7 +561,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err != nil { return err } - *reply = toHex(big.NewInt(v).Bytes()) + *reply = common.ToHex(big.NewInt(v).Bytes()) case "eth_getUncleCountByBlockNumber": args := new(GetBlockByNumberArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -572,7 +572,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err != nil { return err } - *reply = toHex(big.NewInt(v).Bytes()) + *reply = common.ToHex(big.NewInt(v).Bytes()) case "eth_getData", "eth_getCode": args := new(GetDataArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -663,7 +663,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return NewValidationError("Index", "does not exist") } - uncle, err := p.GetBlockByHash(toHex(v.Uncles[args.Index]), false) + uncle, err := p.GetBlockByHash(common.ToHex(v.Uncles[args.Index]), false) if err != nil { return err } @@ -682,7 +682,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return NewValidationError("Index", "does not exist") } - uncle, err := p.GetBlockByHash(toHex(v.Uncles[args.Index]), false) + uncle, err := p.GetBlockByHash(common.ToHex(v.Uncles[args.Index]), false) if err != nil { return err } -- cgit v1.2.3