Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
99483e85
Unverified
Commit
99483e85
authored
Jun 11, 2018
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rpc: support returning nil pointer big.Ints (null)
parent
1d666cf2
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
7 additions
and
31 deletions
+7
-31
api.go
internal/ethapi/api.go
+7
-7
json.go
rpc/json.go
+0
-8
server.go
rpc/server.go
+0
-1
utils.go
rpc/utils.go
+0
-15
No files found.
internal/ethapi/api.go
View file @
99483e85
...
...
@@ -62,8 +62,9 @@ func NewPublicEthereumAPI(b Backend) *PublicEthereumAPI {
}
// GasPrice returns a suggestion for a gas price.
func
(
s
*
PublicEthereumAPI
)
GasPrice
(
ctx
context
.
Context
)
(
*
big
.
Int
,
error
)
{
return
s
.
b
.
SuggestPrice
(
ctx
)
func
(
s
*
PublicEthereumAPI
)
GasPrice
(
ctx
context
.
Context
)
(
*
hexutil
.
Big
,
error
)
{
price
,
err
:=
s
.
b
.
SuggestPrice
(
ctx
)
return
(
*
hexutil
.
Big
)(
price
),
err
}
// ProtocolVersion returns the current Ethereum protocol version this node supports
...
...
@@ -487,21 +488,20 @@ func NewPublicBlockChainAPI(b Backend) *PublicBlockChainAPI {
}
// BlockNumber returns the block number of the chain head.
func
(
s
*
PublicBlockChainAPI
)
BlockNumber
()
*
big
.
Int
{
func
(
s
*
PublicBlockChainAPI
)
BlockNumber
()
hexutil
.
Uint64
{
header
,
_
:=
s
.
b
.
HeaderByNumber
(
context
.
Background
(),
rpc
.
LatestBlockNumber
)
// latest header should always be available
return
he
ader
.
Number
return
he
xutil
.
Uint64
(
header
.
Number
.
Uint64
())
}
// GetBalance returns the amount of wei for the given address in the state of the
// given block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta
// block numbers are also allowed.
func
(
s
*
PublicBlockChainAPI
)
GetBalance
(
ctx
context
.
Context
,
address
common
.
Address
,
blockNr
rpc
.
BlockNumber
)
(
*
big
.
Int
,
error
)
{
func
(
s
*
PublicBlockChainAPI
)
GetBalance
(
ctx
context
.
Context
,
address
common
.
Address
,
blockNr
rpc
.
BlockNumber
)
(
*
hexutil
.
Big
,
error
)
{
state
,
_
,
err
:=
s
.
b
.
StateAndHeaderByNumber
(
ctx
,
blockNr
)
if
state
==
nil
||
err
!=
nil
{
return
nil
,
err
}
b
:=
state
.
GetBalance
(
address
)
return
b
,
state
.
Error
()
return
(
*
hexutil
.
Big
)(
state
.
GetBalance
(
address
)),
state
.
Error
()
}
// GetBlockByNumber returns the requested block. When blockNr is -1 the chain head is returned. When fullTx is true all
...
...
rpc/json.go
View file @
99483e85
...
...
@@ -320,9 +320,6 @@ func parsePositionalArguments(rawArgs json.RawMessage, types []reflect.Type) ([]
// CreateResponse will create a JSON-RPC success response with the given id and reply as result.
func
(
c
*
jsonCodec
)
CreateResponse
(
id
interface
{},
reply
interface
{})
interface
{}
{
if
isHexNum
(
reflect
.
TypeOf
(
reply
))
{
return
&
jsonSuccessResponse
{
Version
:
jsonrpcVersion
,
Id
:
id
,
Result
:
fmt
.
Sprintf
(
`%#x`
,
reply
)}
}
return
&
jsonSuccessResponse
{
Version
:
jsonrpcVersion
,
Id
:
id
,
Result
:
reply
}
}
...
...
@@ -340,11 +337,6 @@ func (c *jsonCodec) CreateErrorResponseWithInfo(id interface{}, err Error, info
// CreateNotification will create a JSON-RPC notification with the given subscription id and event as params.
func
(
c
*
jsonCodec
)
CreateNotification
(
subid
,
namespace
string
,
event
interface
{})
interface
{}
{
if
isHexNum
(
reflect
.
TypeOf
(
event
))
{
return
&
jsonNotification
{
Version
:
jsonrpcVersion
,
Method
:
namespace
+
notificationMethodSuffix
,
Params
:
jsonSubscription
{
Subscription
:
subid
,
Result
:
fmt
.
Sprintf
(
`%#x`
,
event
)}}
}
return
&
jsonNotification
{
Version
:
jsonrpcVersion
,
Method
:
namespace
+
notificationMethodSuffix
,
Params
:
jsonSubscription
{
Subscription
:
subid
,
Result
:
event
}}
}
...
...
rpc/server.go
View file @
99483e85
...
...
@@ -313,7 +313,6 @@ func (s *Server) handle(ctx context.Context, codec ServerCodec, req *serverReque
if
len
(
reply
)
==
0
{
return
codec
.
CreateResponse
(
req
.
id
,
nil
),
nil
}
if
req
.
callb
.
errPos
>=
0
{
// test if method returned an error
if
!
reply
[
req
.
callb
.
errPos
]
.
IsNil
()
{
e
:=
reply
[
req
.
callb
.
errPos
]
.
Interface
()
.
(
error
)
...
...
rpc/utils.go
View file @
99483e85
...
...
@@ -22,7 +22,6 @@ import (
crand
"crypto/rand"
"encoding/binary"
"encoding/hex"
"math/big"
"math/rand"
"reflect"
"strings"
...
...
@@ -105,20 +104,6 @@ func formatName(name string) string {
return
string
(
ret
)
}
var
bigIntType
=
reflect
.
TypeOf
((
*
big
.
Int
)(
nil
))
.
Elem
()
// Indication if this type should be serialized in hex
func
isHexNum
(
t
reflect
.
Type
)
bool
{
if
t
==
nil
{
return
false
}
for
t
.
Kind
()
==
reflect
.
Ptr
{
t
=
t
.
Elem
()
}
return
t
==
bigIntType
}
// suitableCallbacks iterates over the methods of the given type. It will determine if a method satisfies the criteria
// for a RPC callback or a subscription callback and adds it to the collection of callbacks or subscriptions. See server
// documentation for a summary of these criteria.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment