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
24f28877
Commit
24f28877
authored
Nov 27, 2016
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/types: use package hexutil for JSON handling
parent
65e6319b
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
40 additions
and
392 deletions
+40
-392
block.go
core/types/block.go
+15
-22
bloom9.go
core/types/bloom9.go
+3
-10
json.go
core/types/json.go
+0
-108
json_test.go
core/types/json_test.go
+0
-232
receipt.go
core/types/receipt.go
+5
-4
transaction.go
core/types/transaction.go
+17
-16
No files found.
core/types/block.go
View file @
24f28877
...
@@ -29,6 +29,7 @@ import (
...
@@ -29,6 +29,7 @@ import (
"time"
"time"
"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/sha3"
"github.com/ethereum/go-ethereum/crypto/sha3"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rlp"
)
)
...
@@ -63,20 +64,12 @@ func (n BlockNonce) Uint64() uint64 {
...
@@ -63,20 +64,12 @@ func (n BlockNonce) Uint64() uint64 {
// MarshalJSON implements json.Marshaler
// MarshalJSON implements json.Marshaler
func
(
n
BlockNonce
)
MarshalJSON
()
([]
byte
,
error
)
{
func
(
n
BlockNonce
)
MarshalJSON
()
([]
byte
,
error
)
{
return
[]
byte
(
fmt
.
Sprintf
(
`"0x%x"`
,
n
)),
nil
return
hexutil
.
Bytes
(
n
[
:
])
.
MarshalJSON
()
}
}
// UnmarshalJSON implements json.Unmarshaler
// UnmarshalJSON implements json.Unmarshaler
func
(
n
*
BlockNonce
)
UnmarshalJSON
(
input
[]
byte
)
error
{
func
(
n
*
BlockNonce
)
UnmarshalJSON
(
input
[]
byte
)
error
{
var
b
hexBytes
return
hexutil
.
UnmarshalJSON
(
"BlockNonce"
,
input
,
n
[
:
])
if
err
:=
b
.
UnmarshalJSON
(
input
);
err
!=
nil
{
return
err
}
if
len
(
b
)
!=
8
{
return
errBadNonceSize
}
copy
((
*
n
)[
:
],
b
)
return
nil
}
}
// Header represents a block header in the Ethereum blockchain.
// Header represents a block header in the Ethereum blockchain.
...
@@ -106,12 +99,12 @@ type jsonHeader struct {
...
@@ -106,12 +99,12 @@ type jsonHeader struct {
TxHash
*
common
.
Hash
`json:"transactionsRoot"`
TxHash
*
common
.
Hash
`json:"transactionsRoot"`
ReceiptHash
*
common
.
Hash
`json:"receiptsRoot"`
ReceiptHash
*
common
.
Hash
`json:"receiptsRoot"`
Bloom
*
Bloom
`json:"logsBloom"`
Bloom
*
Bloom
`json:"logsBloom"`
Difficulty
*
hex
Big
`json:"difficulty"`
Difficulty
*
hex
util
.
Big
`json:"difficulty"`
Number
*
hex
Big
`json:"number"`
Number
*
hex
util
.
Big
`json:"number"`
GasLimit
*
hex
Big
`json:"gasLimit"`
GasLimit
*
hex
util
.
Big
`json:"gasLimit"`
GasUsed
*
hex
Big
`json:"gasUsed"`
GasUsed
*
hex
util
.
Big
`json:"gasUsed"`
Time
*
hex
Big
`json:"timestamp"`
Time
*
hex
util
.
Big
`json:"timestamp"`
Extra
*
hex
Bytes
`json:"extraData"`
Extra
*
hex
util
.
Bytes
`json:"extraData"`
MixDigest
*
common
.
Hash
`json:"mixHash"`
MixDigest
*
common
.
Hash
`json:"mixHash"`
Nonce
*
BlockNonce
`json:"nonce"`
Nonce
*
BlockNonce
`json:"nonce"`
}
}
...
@@ -151,12 +144,12 @@ func (h *Header) MarshalJSON() ([]byte, error) {
...
@@ -151,12 +144,12 @@ func (h *Header) MarshalJSON() ([]byte, error) {
TxHash
:
&
h
.
TxHash
,
TxHash
:
&
h
.
TxHash
,
ReceiptHash
:
&
h
.
ReceiptHash
,
ReceiptHash
:
&
h
.
ReceiptHash
,
Bloom
:
&
h
.
Bloom
,
Bloom
:
&
h
.
Bloom
,
Difficulty
:
(
*
hexBig
)(
h
.
Difficulty
),
Difficulty
:
(
*
hex
util
.
Big
)(
h
.
Difficulty
),
Number
:
(
*
hexBig
)(
h
.
Number
),
Number
:
(
*
hex
util
.
Big
)(
h
.
Number
),
GasLimit
:
(
*
hexBig
)(
h
.
GasLimit
),
GasLimit
:
(
*
hex
util
.
Big
)(
h
.
GasLimit
),
GasUsed
:
(
*
hexBig
)(
h
.
GasUsed
),
GasUsed
:
(
*
hex
util
.
Big
)(
h
.
GasUsed
),
Time
:
(
*
hexBig
)(
h
.
Time
),
Time
:
(
*
hex
util
.
Big
)(
h
.
Time
),
Extra
:
(
*
hexBytes
)(
&
h
.
Extra
),
Extra
:
(
*
hex
util
.
Bytes
)(
&
h
.
Extra
),
MixDigest
:
&
h
.
MixDigest
,
MixDigest
:
&
h
.
MixDigest
,
Nonce
:
&
h
.
Nonce
,
Nonce
:
&
h
.
Nonce
,
})
})
...
...
core/types/bloom9.go
View file @
24f28877
...
@@ -21,6 +21,7 @@ import (
...
@@ -21,6 +21,7 @@ import (
"math/big"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
)
)
...
@@ -77,20 +78,12 @@ func (b Bloom) TestBytes(test []byte) bool {
...
@@ -77,20 +78,12 @@ func (b Bloom) TestBytes(test []byte) bool {
// MarshalJSON encodes b as a hex string with 0x prefix.
// MarshalJSON encodes b as a hex string with 0x prefix.
func
(
b
Bloom
)
MarshalJSON
()
([]
byte
,
error
)
{
func
(
b
Bloom
)
MarshalJSON
()
([]
byte
,
error
)
{
return
[]
byte
(
fmt
.
Sprintf
(
`"%#x"`
,
b
[
:
])),
nil
return
hexutil
.
Bytes
(
b
[
:
])
.
MarshalJSON
()
}
}
// UnmarshalJSON b as a hex string with 0x prefix.
// UnmarshalJSON b as a hex string with 0x prefix.
func
(
b
*
Bloom
)
UnmarshalJSON
(
input
[]
byte
)
error
{
func
(
b
*
Bloom
)
UnmarshalJSON
(
input
[]
byte
)
error
{
var
dec
hexBytes
return
hexutil
.
UnmarshalJSON
(
"Bloom"
,
input
,
b
[
:
])
if
err
:=
dec
.
UnmarshalJSON
(
input
);
err
!=
nil
{
return
err
}
if
len
(
dec
)
!=
bloomLength
{
return
fmt
.
Errorf
(
"invalid bloom size, want %d bytes"
,
bloomLength
)
}
copy
((
*
b
)[
:
],
dec
)
return
nil
}
}
func
CreateBloom
(
receipts
Receipts
)
Bloom
{
func
CreateBloom
(
receipts
Receipts
)
Bloom
{
...
...
core/types/json.go
deleted
100644 → 0
View file @
65e6319b
// Copyright 2016 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package
types
import
(
"encoding/hex"
"fmt"
"math/big"
)
// JSON unmarshaling utilities.
type
hexBytes
[]
byte
func
(
b
*
hexBytes
)
MarshalJSON
()
([]
byte
,
error
)
{
if
b
!=
nil
{
return
[]
byte
(
fmt
.
Sprintf
(
`"0x%x"`
,
[]
byte
(
*
b
))),
nil
}
return
nil
,
nil
}
func
(
b
*
hexBytes
)
UnmarshalJSON
(
input
[]
byte
)
error
{
if
len
(
input
)
<
2
||
input
[
0
]
!=
'"'
||
input
[
len
(
input
)
-
1
]
!=
'"'
{
return
fmt
.
Errorf
(
"cannot unmarshal non-string into hexBytes"
)
}
input
=
input
[
1
:
len
(
input
)
-
1
]
if
len
(
input
)
<
2
||
input
[
0
]
!=
'0'
||
input
[
1
]
!=
'x'
{
return
fmt
.
Errorf
(
"missing 0x prefix in hexBytes input %q"
,
input
)
}
dec
:=
make
(
hexBytes
,
(
len
(
input
)
-
2
)
/
2
)
if
_
,
err
:=
hex
.
Decode
(
dec
,
input
[
2
:
]);
err
!=
nil
{
return
err
}
*
b
=
dec
return
nil
}
type
hexBig
big
.
Int
func
(
b
*
hexBig
)
MarshalJSON
()
([]
byte
,
error
)
{
if
b
!=
nil
{
return
[]
byte
(
fmt
.
Sprintf
(
`"0x%x"`
,
(
*
big
.
Int
)(
b
))),
nil
}
return
nil
,
nil
}
func
(
b
*
hexBig
)
UnmarshalJSON
(
input
[]
byte
)
error
{
raw
,
err
:=
checkHexNumber
(
input
)
if
err
!=
nil
{
return
err
}
dec
,
ok
:=
new
(
big
.
Int
)
.
SetString
(
string
(
raw
),
16
)
if
!
ok
{
return
fmt
.
Errorf
(
"invalid hex number"
)
}
*
b
=
(
hexBig
)(
*
dec
)
return
nil
}
type
hexUint64
uint64
func
(
b
*
hexUint64
)
MarshalJSON
()
([]
byte
,
error
)
{
if
b
!=
nil
{
return
[]
byte
(
fmt
.
Sprintf
(
`"0x%x"`
,
*
(
*
uint64
)(
b
))),
nil
}
return
nil
,
nil
}
func
(
b
*
hexUint64
)
UnmarshalJSON
(
input
[]
byte
)
error
{
raw
,
err
:=
checkHexNumber
(
input
)
if
err
!=
nil
{
return
err
}
_
,
err
=
fmt
.
Sscanf
(
string
(
raw
),
"%x"
,
b
)
return
err
}
func
checkHexNumber
(
input
[]
byte
)
(
raw
[]
byte
,
err
error
)
{
if
len
(
input
)
<
2
||
input
[
0
]
!=
'"'
||
input
[
len
(
input
)
-
1
]
!=
'"'
{
return
nil
,
fmt
.
Errorf
(
"cannot unmarshal non-string into hex number"
)
}
input
=
input
[
1
:
len
(
input
)
-
1
]
if
len
(
input
)
<
2
||
input
[
0
]
!=
'0'
||
input
[
1
]
!=
'x'
{
return
nil
,
fmt
.
Errorf
(
"missing 0x prefix in hex number input %q"
,
input
)
}
if
len
(
input
)
==
2
{
return
nil
,
fmt
.
Errorf
(
"empty hex number"
)
}
raw
=
input
[
2
:
]
if
len
(
raw
)
%
2
!=
0
{
raw
=
append
([]
byte
{
'0'
},
raw
...
)
}
return
raw
,
nil
}
core/types/json_test.go
deleted
100644 → 0
View file @
65e6319b
This diff is collapsed.
Click to expand it.
core/types/receipt.go
View file @
24f28877
...
@@ -24,6 +24,7 @@ import (
...
@@ -24,6 +24,7 @@ import (
"math/big"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rlp"
)
)
...
@@ -49,12 +50,12 @@ type Receipt struct {
...
@@ -49,12 +50,12 @@ type Receipt struct {
type
jsonReceipt
struct
{
type
jsonReceipt
struct
{
PostState
*
common
.
Hash
`json:"root"`
PostState
*
common
.
Hash
`json:"root"`
CumulativeGasUsed
*
hex
Big
`json:"cumulativeGasUsed"`
CumulativeGasUsed
*
hex
util
.
Big
`json:"cumulativeGasUsed"`
Bloom
*
Bloom
`json:"logsBloom"`
Bloom
*
Bloom
`json:"logsBloom"`
Logs
*
vm
.
Logs
`json:"logs"`
Logs
*
vm
.
Logs
`json:"logs"`
TxHash
*
common
.
Hash
`json:"transactionHash"`
TxHash
*
common
.
Hash
`json:"transactionHash"`
ContractAddress
*
common
.
Address
`json:"contractAddress"`
ContractAddress
*
common
.
Address
`json:"contractAddress"`
GasUsed
*
hex
Big
`json:"gasUsed"`
GasUsed
*
hex
util
.
Big
`json:"gasUsed"`
}
}
// NewReceipt creates a barebone transaction receipt, copying the init fields.
// NewReceipt creates a barebone transaction receipt, copying the init fields.
...
@@ -90,12 +91,12 @@ func (r *Receipt) MarshalJSON() ([]byte, error) {
...
@@ -90,12 +91,12 @@ func (r *Receipt) MarshalJSON() ([]byte, error) {
return
json
.
Marshal
(
&
jsonReceipt
{
return
json
.
Marshal
(
&
jsonReceipt
{
PostState
:
&
root
,
PostState
:
&
root
,
CumulativeGasUsed
:
(
*
hexBig
)(
r
.
CumulativeGasUsed
),
CumulativeGasUsed
:
(
*
hex
util
.
Big
)(
r
.
CumulativeGasUsed
),
Bloom
:
&
r
.
Bloom
,
Bloom
:
&
r
.
Bloom
,
Logs
:
&
r
.
Logs
,
Logs
:
&
r
.
Logs
,
TxHash
:
&
r
.
TxHash
,
TxHash
:
&
r
.
TxHash
,
ContractAddress
:
&
r
.
ContractAddress
,
ContractAddress
:
&
r
.
ContractAddress
,
GasUsed
:
(
*
hexBig
)(
r
.
GasUsed
),
GasUsed
:
(
*
hex
util
.
Big
)(
r
.
GasUsed
),
})
})
}
}
...
...
core/types/transaction.go
View file @
24f28877
...
@@ -27,6 +27,7 @@ import (
...
@@ -27,6 +27,7 @@ import (
"sync/atomic"
"sync/atomic"
"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/params"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rlp"
...
@@ -69,15 +70,15 @@ type txdata struct {
...
@@ -69,15 +70,15 @@ type txdata struct {
type
jsonTransaction
struct
{
type
jsonTransaction
struct
{
Hash
*
common
.
Hash
`json:"hash"`
Hash
*
common
.
Hash
`json:"hash"`
AccountNonce
*
hex
Uint64
`json:"nonce"`
AccountNonce
*
hex
util
.
Uint64
`json:"nonce"`
Price
*
hex
Big
`json:"gasPrice"`
Price
*
hex
util
.
Big
`json:"gasPrice"`
GasLimit
*
hex
Big
`json:"gas"`
GasLimit
*
hex
util
.
Big
`json:"gas"`
Recipient
*
common
.
Address
`json:"to"`
Recipient
*
common
.
Address
`json:"to"`
Amount
*
hex
Big
`json:"value"`
Amount
*
hex
util
.
Big
`json:"value"`
Payload
*
hex
Bytes
`json:"input"`
Payload
*
hex
util
.
Bytes
`json:"input"`
V
*
hex
Big
`json:"v"`
V
*
hex
util
.
Big
`json:"v"`
R
*
hex
Big
`json:"r"`
R
*
hex
util
.
Big
`json:"r"`
S
*
hex
Big
`json:"s"`
S
*
hex
util
.
Big
`json:"s"`
}
}
func
NewTransaction
(
nonce
uint64
,
to
common
.
Address
,
amount
,
gasLimit
,
gasPrice
*
big
.
Int
,
data
[]
byte
)
*
Transaction
{
func
NewTransaction
(
nonce
uint64
,
to
common
.
Address
,
amount
,
gasLimit
,
gasPrice
*
big
.
Int
,
data
[]
byte
)
*
Transaction
{
...
@@ -170,15 +171,15 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) {
...
@@ -170,15 +171,15 @@ func (tx *Transaction) MarshalJSON() ([]byte, error) {
return
json
.
Marshal
(
&
jsonTransaction
{
return
json
.
Marshal
(
&
jsonTransaction
{
Hash
:
&
hash
,
Hash
:
&
hash
,
AccountNonce
:
(
*
hexUint64
)(
&
tx
.
data
.
AccountNonce
),
AccountNonce
:
(
*
hex
util
.
Uint64
)(
&
tx
.
data
.
AccountNonce
),
Price
:
(
*
hexBig
)(
tx
.
data
.
Price
),
Price
:
(
*
hex
util
.
Big
)(
tx
.
data
.
Price
),
GasLimit
:
(
*
hexBig
)(
tx
.
data
.
GasLimit
),
GasLimit
:
(
*
hex
util
.
Big
)(
tx
.
data
.
GasLimit
),
Recipient
:
tx
.
data
.
Recipient
,
Recipient
:
tx
.
data
.
Recipient
,
Amount
:
(
*
hexBig
)(
tx
.
data
.
Amount
),
Amount
:
(
*
hex
util
.
Big
)(
tx
.
data
.
Amount
),
Payload
:
(
*
hexBytes
)(
&
tx
.
data
.
Payload
),
Payload
:
(
*
hex
util
.
Bytes
)(
&
tx
.
data
.
Payload
),
V
:
(
*
hexBig
)(
tx
.
data
.
V
),
V
:
(
*
hex
util
.
Big
)(
tx
.
data
.
V
),
R
:
(
*
hexBig
)(
tx
.
data
.
R
),
R
:
(
*
hex
util
.
Big
)(
tx
.
data
.
R
),
S
:
(
*
hexBig
)(
tx
.
data
.
S
),
S
:
(
*
hex
util
.
Big
)(
tx
.
data
.
S
),
})
})
}
}
...
...
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