Skip to content

Commit 82641ce

Browse files
karalabekielbarry
authored andcommitted
rpc: golint fixes
1 parent 200ad6b commit 82641ce

File tree

4 files changed

+8
-32
lines changed

4 files changed

+8
-32
lines changed

internal/ethapi/api.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ func NewPublicEthereumAPI(b Backend) *PublicEthereumAPI {
6262
}
6363

6464
// GasPrice returns a suggestion for a gas price.
65-
func (s *PublicEthereumAPI) GasPrice(ctx context.Context) (*big.Int, error) {
66-
return s.b.SuggestPrice(ctx)
65+
func (s *PublicEthereumAPI) GasPrice(ctx context.Context) (*hexutil.Big, error) {
66+
price, err := s.b.SuggestPrice(ctx)
67+
return (*hexutil.Big)(price), err
6768
}
6869

6970
// ProtocolVersion returns the current Ethereum protocol version this node supports
@@ -487,21 +488,20 @@ func NewPublicBlockChainAPI(b Backend) *PublicBlockChainAPI {
487488
}
488489

489490
// BlockNumber returns the block number of the chain head.
490-
func (s *PublicBlockChainAPI) BlockNumber() *big.Int {
491+
func (s *PublicBlockChainAPI) BlockNumber() hexutil.Uint64 {
491492
header, _ := s.b.HeaderByNumber(context.Background(), rpc.LatestBlockNumber) // latest header should always be available
492-
return header.Number
493+
return hexutil.Uint64(header.Number.Uint64())
493494
}
494495

495496
// GetBalance returns the amount of wei for the given address in the state of the
496497
// given block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta
497498
// block numbers are also allowed.
498-
func (s *PublicBlockChainAPI) GetBalance(ctx context.Context, address common.Address, blockNr rpc.BlockNumber) (*big.Int, error) {
499+
func (s *PublicBlockChainAPI) GetBalance(ctx context.Context, address common.Address, blockNr rpc.BlockNumber) (*hexutil.Big, error) {
499500
state, _, err := s.b.StateAndHeaderByNumber(ctx, blockNr)
500501
if state == nil || err != nil {
501502
return nil, err
502503
}
503-
b := state.GetBalance(address)
504-
return b, state.Error()
504+
return (*hexutil.Big)(state.GetBalance(address)), state.Error()
505505
}
506506

507507
// GetBlockByNumber returns the requested block. When blockNr is -1 the chain head is returned. When fullTx is true all

rpc/json.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,7 @@ func parsePositionalArguments(rawArgs json.RawMessage, types []reflect.Type) ([]
320320

321321
// CreateResponse will create a JSON-RPC success response with the given id and reply as result.
322322
func (c *jsonCodec) CreateResponse(id interface{}, reply interface{}) interface{} {
323-
if isHexNum(reflect.TypeOf(reply)) {
324-
return &jsonSuccessResponse{Version: jsonrpcVersion, ID: id, Result: fmt.Sprintf(`%#x`, reply)}
325-
}
326-
return &jsonSuccessResponse{Version: jsonrpcVersion, ID: id, Result: reply}
323+
return &jsonSuccessResponse{Version: jsonrpcVersion, Id: id, Result: reply}
327324
}
328325

329326
// CreateErrorResponse will create a JSON-RPC error response with the given id and error.
@@ -340,11 +337,6 @@ func (c *jsonCodec) CreateErrorResponseWithInfo(id interface{}, err Error, info
340337

341338
// CreateNotification will create a JSON-RPC notification with the given subscription id and event as params.
342339
func (c *jsonCodec) CreateNotification(subid, namespace string, event interface{}) interface{} {
343-
if isHexNum(reflect.TypeOf(event)) {
344-
return &jsonNotification{Version: jsonrpcVersion, Method: namespace + notificationMethodSuffix,
345-
Params: jsonSubscription{Subscription: subid, Result: fmt.Sprintf(`%#x`, event)}}
346-
}
347-
348340
return &jsonNotification{Version: jsonrpcVersion, Method: namespace + notificationMethodSuffix,
349341
Params: jsonSubscription{Subscription: subid, Result: event}}
350342
}

rpc/server.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ func (s *Server) handle(ctx context.Context, codec ServerCodec, req *serverReque
313313
if len(reply) == 0 {
314314
return codec.CreateResponse(req.id, nil), nil
315315
}
316-
317316
if req.callb.errPos >= 0 { // test if method returned an error
318317
if !reply[req.callb.errPos].IsNil() {
319318
e := reply[req.callb.errPos].Interface().(error)

rpc/utils.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
crand "crypto/rand"
2323
"encoding/binary"
2424
"encoding/hex"
25-
"math/big"
2625
"math/rand"
2726
"reflect"
2827
"strings"
@@ -105,20 +104,6 @@ func formatName(name string) string {
105104
return string(ret)
106105
}
107106

108-
var bigIntType = reflect.TypeOf((*big.Int)(nil)).Elem()
109-
110-
// Indication if this type should be serialized in hex
111-
func isHexNum(t reflect.Type) bool {
112-
if t == nil {
113-
return false
114-
}
115-
for t.Kind() == reflect.Ptr {
116-
t = t.Elem()
117-
}
118-
119-
return t == bigIntType
120-
}
121-
122107
// suitableCallbacks iterates over the methods of the given type. It will determine if a method satisfies the criteria
123108
// for a RPC callback or a subscription callback and adds it to the collection of callbacks or subscriptions. See server
124109
// documentation for a summary of these criteria.

0 commit comments

Comments
 (0)