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
adab2e16
Commit
adab2e16
authored
Dec 12, 2016
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rpc: remove HexBytes, replace all uses with hexutil.Bytes
parent
a3e3235d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
66 deletions
+15
-66
api.go
internal/ethapi/api.go
+9
-9
types.go
rpc/types.go
+0
-30
types_test.go
rpc/types_test.go
+0
-22
api.go
whisper/shhapi/api.go
+6
-5
No files found.
internal/ethapi/api.go
View file @
adab2e16
...
@@ -633,7 +633,7 @@ func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx
...
@@ -633,7 +633,7 @@ func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx
"miner"
:
head
.
Coinbase
,
"miner"
:
head
.
Coinbase
,
"difficulty"
:
rpc
.
NewHexNumber
(
head
.
Difficulty
),
"difficulty"
:
rpc
.
NewHexNumber
(
head
.
Difficulty
),
"totalDifficulty"
:
rpc
.
NewHexNumber
(
s
.
b
.
GetTd
(
b
.
Hash
())),
"totalDifficulty"
:
rpc
.
NewHexNumber
(
s
.
b
.
GetTd
(
b
.
Hash
())),
"extraData"
:
rpc
.
Hex
Bytes
(
head
.
Extra
),
"extraData"
:
hexutil
.
Bytes
(
head
.
Extra
),
"size"
:
rpc
.
NewHexNumber
(
b
.
Size
()
.
Int64
()),
"size"
:
rpc
.
NewHexNumber
(
b
.
Size
()
.
Int64
()),
"gasLimit"
:
rpc
.
NewHexNumber
(
head
.
GasLimit
),
"gasLimit"
:
rpc
.
NewHexNumber
(
head
.
GasLimit
),
"gasUsed"
:
rpc
.
NewHexNumber
(
head
.
GasUsed
),
"gasUsed"
:
rpc
.
NewHexNumber
(
head
.
GasUsed
),
...
@@ -682,7 +682,7 @@ type RPCTransaction struct {
...
@@ -682,7 +682,7 @@ type RPCTransaction struct {
Gas
*
rpc
.
HexNumber
`json:"gas"`
Gas
*
rpc
.
HexNumber
`json:"gas"`
GasPrice
*
rpc
.
HexNumber
`json:"gasPrice"`
GasPrice
*
rpc
.
HexNumber
`json:"gasPrice"`
Hash
common
.
Hash
`json:"hash"`
Hash
common
.
Hash
`json:"hash"`
Input
rpc
.
HexBytes
`json:"input"`
Input
hexutil
.
Bytes
`json:"input"`
Nonce
*
rpc
.
HexNumber
`json:"nonce"`
Nonce
*
rpc
.
HexNumber
`json:"nonce"`
To
*
common
.
Address
`json:"to"`
To
*
common
.
Address
`json:"to"`
TransactionIndex
*
rpc
.
HexNumber
`json:"transactionIndex"`
TransactionIndex
*
rpc
.
HexNumber
`json:"transactionIndex"`
...
@@ -705,7 +705,7 @@ func newRPCPendingTransaction(tx *types.Transaction) *RPCTransaction {
...
@@ -705,7 +705,7 @@ func newRPCPendingTransaction(tx *types.Transaction) *RPCTransaction {
Gas
:
rpc
.
NewHexNumber
(
tx
.
Gas
()),
Gas
:
rpc
.
NewHexNumber
(
tx
.
Gas
()),
GasPrice
:
rpc
.
NewHexNumber
(
tx
.
GasPrice
()),
GasPrice
:
rpc
.
NewHexNumber
(
tx
.
GasPrice
()),
Hash
:
tx
.
Hash
(),
Hash
:
tx
.
Hash
(),
Input
:
rpc
.
Hex
Bytes
(
tx
.
Data
()),
Input
:
hexutil
.
Bytes
(
tx
.
Data
()),
Nonce
:
rpc
.
NewHexNumber
(
tx
.
Nonce
()),
Nonce
:
rpc
.
NewHexNumber
(
tx
.
Nonce
()),
To
:
tx
.
To
(),
To
:
tx
.
To
(),
Value
:
rpc
.
NewHexNumber
(
tx
.
Value
()),
Value
:
rpc
.
NewHexNumber
(
tx
.
Value
()),
...
@@ -732,7 +732,7 @@ func newRPCTransactionFromBlockIndex(b *types.Block, txIndex int) (*RPCTransacti
...
@@ -732,7 +732,7 @@ func newRPCTransactionFromBlockIndex(b *types.Block, txIndex int) (*RPCTransacti
Gas
:
rpc
.
NewHexNumber
(
tx
.
Gas
()),
Gas
:
rpc
.
NewHexNumber
(
tx
.
Gas
()),
GasPrice
:
rpc
.
NewHexNumber
(
tx
.
GasPrice
()),
GasPrice
:
rpc
.
NewHexNumber
(
tx
.
GasPrice
()),
Hash
:
tx
.
Hash
(),
Hash
:
tx
.
Hash
(),
Input
:
rpc
.
Hex
Bytes
(
tx
.
Data
()),
Input
:
hexutil
.
Bytes
(
tx
.
Data
()),
Nonce
:
rpc
.
NewHexNumber
(
tx
.
Nonce
()),
Nonce
:
rpc
.
NewHexNumber
(
tx
.
Nonce
()),
To
:
tx
.
To
(),
To
:
tx
.
To
(),
TransactionIndex
:
rpc
.
NewHexNumber
(
txIndex
),
TransactionIndex
:
rpc
.
NewHexNumber
(
txIndex
),
...
@@ -747,7 +747,7 @@ func newRPCTransactionFromBlockIndex(b *types.Block, txIndex int) (*RPCTransacti
...
@@ -747,7 +747,7 @@ func newRPCTransactionFromBlockIndex(b *types.Block, txIndex int) (*RPCTransacti
}
}
// newRPCRawTransactionFromBlockIndex returns the bytes of a transaction given a block and a transaction index.
// newRPCRawTransactionFromBlockIndex returns the bytes of a transaction given a block and a transaction index.
func
newRPCRawTransactionFromBlockIndex
(
b
*
types
.
Block
,
txIndex
int
)
(
rpc
.
Hex
Bytes
,
error
)
{
func
newRPCRawTransactionFromBlockIndex
(
b
*
types
.
Block
,
txIndex
int
)
(
hexutil
.
Bytes
,
error
)
{
if
txIndex
>=
0
&&
txIndex
<
len
(
b
.
Transactions
())
{
if
txIndex
>=
0
&&
txIndex
<
len
(
b
.
Transactions
())
{
tx
:=
b
.
Transactions
()[
txIndex
]
tx
:=
b
.
Transactions
()[
txIndex
]
return
rlp
.
EncodeToBytes
(
tx
)
return
rlp
.
EncodeToBytes
(
tx
)
...
@@ -828,7 +828,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context
...
@@ -828,7 +828,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context
}
}
// GetRawTransactionByBlockNumberAndIndex returns the bytes of the transaction for the given block number and index.
// GetRawTransactionByBlockNumberAndIndex returns the bytes of the transaction for the given block number and index.
func
(
s
*
PublicTransactionPoolAPI
)
GetRawTransactionByBlockNumberAndIndex
(
ctx
context
.
Context
,
blockNr
rpc
.
BlockNumber
,
index
rpc
.
HexNumber
)
(
rpc
.
Hex
Bytes
,
error
)
{
func
(
s
*
PublicTransactionPoolAPI
)
GetRawTransactionByBlockNumberAndIndex
(
ctx
context
.
Context
,
blockNr
rpc
.
BlockNumber
,
index
rpc
.
HexNumber
)
(
hexutil
.
Bytes
,
error
)
{
if
block
,
_
:=
s
.
b
.
BlockByNumber
(
ctx
,
blockNr
);
block
!=
nil
{
if
block
,
_
:=
s
.
b
.
BlockByNumber
(
ctx
,
blockNr
);
block
!=
nil
{
return
newRPCRawTransactionFromBlockIndex
(
block
,
index
.
Int
())
return
newRPCRawTransactionFromBlockIndex
(
block
,
index
.
Int
())
}
}
...
@@ -836,7 +836,7 @@ func (s *PublicTransactionPoolAPI) GetRawTransactionByBlockNumberAndIndex(ctx co
...
@@ -836,7 +836,7 @@ func (s *PublicTransactionPoolAPI) GetRawTransactionByBlockNumberAndIndex(ctx co
}
}
// GetRawTransactionByBlockHashAndIndex returns the bytes of the transaction for the given block hash and index.
// GetRawTransactionByBlockHashAndIndex returns the bytes of the transaction for the given block hash and index.
func
(
s
*
PublicTransactionPoolAPI
)
GetRawTransactionByBlockHashAndIndex
(
ctx
context
.
Context
,
blockHash
common
.
Hash
,
index
rpc
.
HexNumber
)
(
rpc
.
Hex
Bytes
,
error
)
{
func
(
s
*
PublicTransactionPoolAPI
)
GetRawTransactionByBlockHashAndIndex
(
ctx
context
.
Context
,
blockHash
common
.
Hash
,
index
rpc
.
HexNumber
)
(
hexutil
.
Bytes
,
error
)
{
if
block
,
_
:=
s
.
b
.
GetBlock
(
ctx
,
blockHash
);
block
!=
nil
{
if
block
,
_
:=
s
.
b
.
GetBlock
(
ctx
,
blockHash
);
block
!=
nil
{
return
newRPCRawTransactionFromBlockIndex
(
block
,
index
.
Int
())
return
newRPCRawTransactionFromBlockIndex
(
block
,
index
.
Int
())
}
}
...
@@ -909,7 +909,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, txH
...
@@ -909,7 +909,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, txH
}
}
// GetRawTransactionByHash returns the bytes of the transaction for the given hash.
// GetRawTransactionByHash returns the bytes of the transaction for the given hash.
func
(
s
*
PublicTransactionPoolAPI
)
GetRawTransactionByHash
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
rpc
.
Hex
Bytes
,
error
)
{
func
(
s
*
PublicTransactionPoolAPI
)
GetRawTransactionByHash
(
ctx
context
.
Context
,
txHash
common
.
Hash
)
(
hexutil
.
Bytes
,
error
)
{
var
tx
*
types
.
Transaction
var
tx
*
types
.
Transaction
var
err
error
var
err
error
...
@@ -950,7 +950,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(txHash common.Hash) (ma
...
@@ -950,7 +950,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(txHash common.Hash) (ma
from
,
_
:=
types
.
Sender
(
signer
,
tx
)
from
,
_
:=
types
.
Sender
(
signer
,
tx
)
fields
:=
map
[
string
]
interface
{}{
fields
:=
map
[
string
]
interface
{}{
"root"
:
rpc
.
Hex
Bytes
(
receipt
.
PostState
),
"root"
:
hexutil
.
Bytes
(
receipt
.
PostState
),
"blockHash"
:
txBlock
,
"blockHash"
:
txBlock
,
"blockNumber"
:
rpc
.
NewHexNumber
(
blockIndex
),
"blockNumber"
:
rpc
.
NewHexNumber
(
blockIndex
),
"transactionHash"
:
txHash
,
"transactionHash"
:
txHash
,
...
...
rpc/types.go
View file @
adab2e16
...
@@ -17,8 +17,6 @@
...
@@ -17,8 +17,6 @@
package
rpc
package
rpc
import
(
import
(
"bytes"
"encoding/hex"
"fmt"
"fmt"
"math"
"math"
"math/big"
"math/big"
...
@@ -274,31 +272,3 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
...
@@ -274,31 +272,3 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
func
(
bn
BlockNumber
)
Int64
()
int64
{
func
(
bn
BlockNumber
)
Int64
()
int64
{
return
(
int64
)(
bn
)
return
(
int64
)(
bn
)
}
}
// HexBytes JSON-encodes as hex with 0x prefix.
type
HexBytes
[]
byte
func
(
b
HexBytes
)
MarshalJSON
()
([]
byte
,
error
)
{
result
:=
make
([]
byte
,
len
(
b
)
*
2
+
4
)
copy
(
result
,
`"0x`
)
hex
.
Encode
(
result
[
3
:
],
b
)
result
[
len
(
result
)
-
1
]
=
'"'
return
result
,
nil
}
func
(
b
*
HexBytes
)
UnmarshalJSON
(
input
[]
byte
)
error
{
if
len
(
input
)
>=
2
&&
input
[
0
]
==
'"'
&&
input
[
len
(
input
)
-
1
]
==
'"'
{
input
=
input
[
1
:
len
(
input
)
-
1
]
}
if
!
bytes
.
HasPrefix
(
input
,
[]
byte
(
"0x"
))
{
return
fmt
.
Errorf
(
"missing 0x prefix for hex byte array"
)
}
input
=
input
[
2
:
]
if
len
(
input
)
==
0
{
*
b
=
nil
return
nil
}
*
b
=
make
([]
byte
,
len
(
input
)
/
2
)
_
,
err
:=
hex
.
Decode
(
*
b
,
input
)
return
err
}
rpc/types_test.go
View file @
adab2e16
...
@@ -71,25 +71,3 @@ func TestHexNumberMarshalJSON(t *testing.T) {
...
@@ -71,25 +71,3 @@ func TestHexNumberMarshalJSON(t *testing.T) {
t
.
Fatalf
(
"Invalid json.Marshal, expected '%s', got '%s'"
,
exp
,
got
)
t
.
Fatalf
(
"Invalid json.Marshal, expected '%s', got '%s'"
,
exp
,
got
)
}
}
}
}
var
hexBytesTests
=
[]
struct
{
in
,
out
[]
byte
}{
{
in
:
[]
byte
(
`"0x"`
),
out
:
[]
byte
{}},
{
in
:
[]
byte
(
`"0x00"`
),
out
:
[]
byte
{
0
}},
{
in
:
[]
byte
(
`"0x01ff"`
),
out
:
[]
byte
{
0x01
,
0xFF
}},
}
func
TestHexBytes
(
t
*
testing
.
T
)
{
for
i
,
test
:=
range
hexBytesTests
{
var
dec
HexBytes
if
err
:=
json
.
Unmarshal
(
test
.
in
,
&
dec
);
err
!=
nil
{
t
.
Fatalf
(
"test %d: can't decode: %v"
,
i
,
err
)
}
enc
,
_
:=
json
.
Marshal
(
HexBytes
(
test
.
out
))
if
!
bytes
.
Equal
(
dec
,
test
.
out
)
{
t
.
Errorf
(
"test %d: wrong decoded value 0x%x"
,
i
,
dec
)
}
if
!
bytes
.
Equal
(
enc
,
test
.
in
)
{
t
.
Errorf
(
"test %d: wrong encoded value %#q"
,
i
,
enc
)
}
}
}
whisper/shhapi/api.go
View file @
adab2e16
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
mathrand
"math/rand"
mathrand
"math/rand"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/logger/glog"
...
@@ -81,7 +82,7 @@ func (api *PublicWhisperAPI) Version() (*rpc.HexNumber, error) {
...
@@ -81,7 +82,7 @@ func (api *PublicWhisperAPI) Version() (*rpc.HexNumber, error) {
// MarkPeerTrusted marks specific peer trusted, which will allow it
// MarkPeerTrusted marks specific peer trusted, which will allow it
// to send historic (expired) messages.
// to send historic (expired) messages.
func
(
api
*
PublicWhisperAPI
)
MarkPeerTrusted
(
peerID
rpc
.
Hex
Bytes
)
error
{
func
(
api
*
PublicWhisperAPI
)
MarkPeerTrusted
(
peerID
hexutil
.
Bytes
)
error
{
if
api
.
whisper
==
nil
{
if
api
.
whisper
==
nil
{
return
whisperOffLineErr
return
whisperOffLineErr
}
}
...
@@ -92,7 +93,7 @@ func (api *PublicWhisperAPI) MarkPeerTrusted(peerID rpc.HexBytes) error {
...
@@ -92,7 +93,7 @@ func (api *PublicWhisperAPI) MarkPeerTrusted(peerID rpc.HexBytes) error {
// data contains parameters (time frame, payment details, etc.), required
// data contains parameters (time frame, payment details, etc.), required
// by the remote email-like server. Whisper is not aware about the data format,
// by the remote email-like server. Whisper is not aware about the data format,
// it will just forward the raw data to the server.
// it will just forward the raw data to the server.
func
(
api
*
PublicWhisperAPI
)
RequestHistoricMessages
(
peerID
rpc
.
HexBytes
,
data
rpc
.
Hex
Bytes
)
error
{
func
(
api
*
PublicWhisperAPI
)
RequestHistoricMessages
(
peerID
hexutil
.
Bytes
,
data
hexutil
.
Bytes
)
error
{
if
api
.
whisper
==
nil
{
if
api
.
whisper
==
nil
{
return
whisperOffLineErr
return
whisperOffLineErr
}
}
...
@@ -388,12 +389,12 @@ type PostArgs struct {
...
@@ -388,12 +389,12 @@ type PostArgs struct {
To
string
`json:"to"`
To
string
`json:"to"`
KeyName
string
`json:"keyname"`
KeyName
string
`json:"keyname"`
Topic
whisperv5
.
TopicType
`json:"topic"`
Topic
whisperv5
.
TopicType
`json:"topic"`
Padding
rpc
.
HexBytes
`json:"padding"`
Padding
hexutil
.
Bytes
`json:"padding"`
Payload
rpc
.
HexBytes
`json:"payload"`
Payload
hexutil
.
Bytes
`json:"payload"`
WorkTime
uint32
`json:"worktime"`
WorkTime
uint32
`json:"worktime"`
PoW
float64
`json:"pow"`
PoW
float64
`json:"pow"`
FilterID
uint32
`json:"filterID"`
FilterID
uint32
`json:"filterID"`
PeerID
rpc
.
HexBytes
`json:"peerID"`
PeerID
hexutil
.
Bytes
`json:"peerID"`
}
}
type
WhisperFilterArgs
struct
{
type
WhisperFilterArgs
struct
{
...
...
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