good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
adab2e16
Commit
adab2e16
authored
Dec 12, 2016
by
Felix Lange
Browse files
Options
Downloads
Patches
Plain Diff
rpc: remove HexBytes, replace all uses with hexutil.Bytes
parent
a3e3235d
Branches
Branches containing commit
Tags
v4.0.2
Tags containing commit
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
internal/ethapi/api.go
+9
-9
9 additions, 9 deletions
internal/ethapi/api.go
rpc/types.go
+0
-30
0 additions, 30 deletions
rpc/types.go
rpc/types_test.go
+0
-22
0 additions, 22 deletions
rpc/types_test.go
whisper/shhapi/api.go
+6
-5
6 additions, 5 deletions
whisper/shhapi/api.go
with
15 additions
and
66 deletions
internal/ethapi/api.go
+
9
−
9
View file @
adab2e16
...
...
@@ -633,7 +633,7 @@ func (s *PublicBlockChainAPI) rpcOutputBlock(b *types.Block, inclTx bool, fullTx
"miner"
:
head
.
Coinbase
,
"difficulty"
:
rpc
.
NewHexNumber
(
head
.
Difficulty
),
"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
()),
"gasLimit"
:
rpc
.
NewHexNumber
(
head
.
GasLimit
),
"gasUsed"
:
rpc
.
NewHexNumber
(
head
.
GasUsed
),
...
...
@@ -682,7 +682,7 @@ type RPCTransaction struct {
Gas
*
rpc
.
HexNumber
`json:"gas"`
GasPrice
*
rpc
.
HexNumber
`json:"gasPrice"`
Hash
common
.
Hash
`json:"hash"`
Input
rpc
.
Hex
Bytes
`json:"input"`
Input
hexutil
.
Bytes
`json:"input"`
Nonce
*
rpc
.
HexNumber
`json:"nonce"`
To
*
common
.
Address
`json:"to"`
TransactionIndex
*
rpc
.
HexNumber
`json:"transactionIndex"`
...
...
@@ -705,7 +705,7 @@ func newRPCPendingTransaction(tx *types.Transaction) *RPCTransaction {
Gas
:
rpc
.
NewHexNumber
(
tx
.
Gas
()),
GasPrice
:
rpc
.
NewHexNumber
(
tx
.
GasPrice
()),
Hash
:
tx
.
Hash
(),
Input
:
rpc
.
Hex
Bytes
(
tx
.
Data
()),
Input
:
hexutil
.
Bytes
(
tx
.
Data
()),
Nonce
:
rpc
.
NewHexNumber
(
tx
.
Nonce
()),
To
:
tx
.
To
(),
Value
:
rpc
.
NewHexNumber
(
tx
.
Value
()),
...
...
@@ -732,7 +732,7 @@ func newRPCTransactionFromBlockIndex(b *types.Block, txIndex int) (*RPCTransacti
Gas
:
rpc
.
NewHexNumber
(
tx
.
Gas
()),
GasPrice
:
rpc
.
NewHexNumber
(
tx
.
GasPrice
()),
Hash
:
tx
.
Hash
(),
Input
:
rpc
.
Hex
Bytes
(
tx
.
Data
()),
Input
:
hexutil
.
Bytes
(
tx
.
Data
()),
Nonce
:
rpc
.
NewHexNumber
(
tx
.
Nonce
()),
To
:
tx
.
To
(),
TransactionIndex
:
rpc
.
NewHexNumber
(
txIndex
),
...
...
@@ -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.
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
())
{
tx
:=
b
.
Transactions
()[
txIndex
]
return
rlp
.
EncodeToBytes
(
tx
)
...
...
@@ -828,7 +828,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionByBlockHashAndIndex(ctx context
}
// 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
{
return
newRPCRawTransactionFromBlockIndex
(
block
,
index
.
Int
())
}
...
...
@@ -836,7 +836,7 @@ func (s *PublicTransactionPoolAPI) GetRawTransactionByBlockNumberAndIndex(ctx co
}
// 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
{
return
newRPCRawTransactionFromBlockIndex
(
block
,
index
.
Int
())
}
...
...
@@ -909,7 +909,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionByHash(ctx context.Context, txH
}
// 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
err
error
...
...
@@ -950,7 +950,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(txHash common.Hash) (ma
from
,
_
:=
types
.
Sender
(
signer
,
tx
)
fields
:=
map
[
string
]
interface
{}{
"root"
:
rpc
.
Hex
Bytes
(
receipt
.
PostState
),
"root"
:
hexutil
.
Bytes
(
receipt
.
PostState
),
"blockHash"
:
txBlock
,
"blockNumber"
:
rpc
.
NewHexNumber
(
blockIndex
),
"transactionHash"
:
txHash
,
...
...
This diff is collapsed.
Click to expand it.
rpc/types.go
+
0
−
30
View file @
adab2e16
...
...
@@ -17,8 +17,6 @@
package
rpc
import
(
"bytes"
"encoding/hex"
"fmt"
"math"
"math/big"
...
...
@@ -274,31 +272,3 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
func
(
bn
BlockNumber
)
Int64
()
int64
{
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
}
This diff is collapsed.
Click to expand it.
rpc/types_test.go
+
0
−
22
View file @
adab2e16
...
...
@@ -71,25 +71,3 @@ func TestHexNumberMarshalJSON(t *testing.T) {
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
)
}
}
}
This diff is collapsed.
Click to expand it.
whisper/shhapi/api.go
+
6
−
5
View file @
adab2e16
...
...
@@ -23,6 +23,7 @@ import (
mathrand
"math/rand"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
...
...
@@ -81,7 +82,7 @@ func (api *PublicWhisperAPI) Version() (*rpc.HexNumber, error) {
// MarkPeerTrusted marks specific peer trusted, which will allow it
// 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
{
return
whisperOffLineErr
}
...
...
@@ -92,7 +93,7 @@ func (api *PublicWhisperAPI) MarkPeerTrusted(peerID rpc.HexBytes) error {
// data contains parameters (time frame, payment details, etc.), required
// by the remote email-like server. Whisper is not aware about the data format,
// it will just forward the raw data to the server.
func
(
api
*
PublicWhisperAPI
)
RequestHistoricMessages
(
peerID
rpc
.
Hex
Bytes
,
data
rpc
.
Hex
Bytes
)
error
{
func
(
api
*
PublicWhisperAPI
)
RequestHistoricMessages
(
peerID
hexutil
.
Bytes
,
data
hexutil
.
Bytes
)
error
{
if
api
.
whisper
==
nil
{
return
whisperOffLineErr
}
...
...
@@ -388,12 +389,12 @@ type PostArgs struct {
To
string
`json:"to"`
KeyName
string
`json:"keyname"`
Topic
whisperv5
.
TopicType
`json:"topic"`
Padding
rpc
.
Hex
Bytes
`json:"padding"`
Payload
rpc
.
Hex
Bytes
`json:"payload"`
Padding
hexutil
.
Bytes
`json:"padding"`
Payload
hexutil
.
Bytes
`json:"payload"`
WorkTime
uint32
`json:"worktime"`
PoW
float64
`json:"pow"`
FilterID
uint32
`json:"filterID"`
PeerID
rpc
.
Hex
Bytes
`json:"peerID"`
PeerID
hexutil
.
Bytes
`json:"peerID"`
}
type
WhisperFilterArgs
struct
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment