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
65e6319b
Commit
65e6319b
authored
Nov 27, 2016
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/vm: use package hexutil for JSON handling
parent
ec75953f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
28 deletions
+23
-28
log.go
core/vm/log.go
+20
-28
log_test.go
core/vm/log_test.go
+3
-0
No files found.
core/vm/log.go
View file @
65e6319b
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
"io"
"io"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rlp"
)
)
...
@@ -47,12 +48,12 @@ type Log struct {
...
@@ -47,12 +48,12 @@ type Log struct {
type
jsonLog
struct
{
type
jsonLog
struct
{
Address
*
common
.
Address
`json:"address"`
Address
*
common
.
Address
`json:"address"`
Topics
*
[]
common
.
Hash
`json:"topics"`
Topics
*
[]
common
.
Hash
`json:"topics"`
Data
string
`json:"data"`
Data
*
hexutil
.
Bytes
`json:"data"`
BlockNumber
string
`json:"blockNumber"`
BlockNumber
*
hexutil
.
Uint64
`json:"blockNumber"`
TxIndex
string
`json:"transactionIndex"`
TxIndex
*
hexutil
.
Uint
`json:"transactionIndex"`
TxHash
*
common
.
Hash
`json:"transactionHash"`
TxHash
*
common
.
Hash
`json:"transactionHash"`
BlockHash
*
common
.
Hash
`json:"blockHash"`
BlockHash
*
common
.
Hash
`json:"blockHash"`
Index
string
`json:"logIndex"`
Index
*
hexutil
.
Uint
`json:"logIndex"`
}
}
func
NewLog
(
address
common
.
Address
,
topics
[]
common
.
Hash
,
data
[]
byte
,
number
uint64
)
*
Log
{
func
NewLog
(
address
common
.
Address
,
topics
[]
common
.
Hash
,
data
[]
byte
,
number
uint64
)
*
Log
{
...
@@ -85,12 +86,12 @@ func (r *Log) MarshalJSON() ([]byte, error) {
...
@@ -85,12 +86,12 @@ func (r *Log) MarshalJSON() ([]byte, error) {
return
json
.
Marshal
(
&
jsonLog
{
return
json
.
Marshal
(
&
jsonLog
{
Address
:
&
r
.
Address
,
Address
:
&
r
.
Address
,
Topics
:
&
r
.
Topics
,
Topics
:
&
r
.
Topics
,
Data
:
fmt
.
Sprintf
(
"0x%x"
,
r
.
Data
),
Data
:
(
*
hexutil
.
Bytes
)(
&
r
.
Data
),
BlockNumber
:
fmt
.
Sprintf
(
"0x%x"
,
r
.
BlockNumber
),
BlockNumber
:
(
*
hexutil
.
Uint64
)(
&
r
.
BlockNumber
),
TxIndex
:
fmt
.
Sprintf
(
"0x%x"
,
r
.
TxIndex
),
TxIndex
:
(
*
hexutil
.
Uint
)(
&
r
.
TxIndex
),
TxHash
:
&
r
.
TxHash
,
TxHash
:
&
r
.
TxHash
,
BlockHash
:
&
r
.
BlockHash
,
BlockHash
:
&
r
.
BlockHash
,
Index
:
fmt
.
Sprintf
(
"0x%x"
,
r
.
Index
),
Index
:
(
*
hexutil
.
Uint
)(
&
r
.
Index
),
})
})
}
}
...
@@ -100,29 +101,20 @@ func (r *Log) UnmarshalJSON(input []byte) error {
...
@@ -100,29 +101,20 @@ func (r *Log) UnmarshalJSON(input []byte) error {
if
err
:=
json
.
Unmarshal
(
input
,
&
dec
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
input
,
&
dec
);
err
!=
nil
{
return
err
return
err
}
}
if
dec
.
Address
==
nil
||
dec
.
Topics
==
nil
||
dec
.
Data
==
""
||
dec
.
BlockNumber
==
""
||
if
dec
.
Address
==
nil
||
dec
.
Topics
==
nil
||
dec
.
Data
==
nil
||
dec
.
BlockNumber
==
nil
||
dec
.
TxIndex
==
""
||
dec
.
TxHash
==
nil
||
dec
.
BlockHash
==
nil
||
dec
.
Index
==
""
{
dec
.
TxIndex
==
nil
||
dec
.
TxHash
==
nil
||
dec
.
BlockHash
==
nil
||
dec
.
Index
==
nil
{
return
errMissingLogFields
return
errMissingLogFields
}
}
declog
:
=
Log
{
*
r
=
Log
{
Address
:
*
dec
.
Address
,
Address
:
*
dec
.
Address
,
Topics
:
*
dec
.
Topics
,
Topics
:
*
dec
.
Topics
,
Data
:
*
dec
.
Data
,
BlockNumber
:
uint64
(
*
dec
.
BlockNumber
),
TxHash
:
*
dec
.
TxHash
,
TxHash
:
*
dec
.
TxHash
,
TxIndex
:
uint
(
*
dec
.
TxIndex
),
BlockHash
:
*
dec
.
BlockHash
,
BlockHash
:
*
dec
.
BlockHash
,
Index
:
uint
(
*
dec
.
Index
),
}
}
if
_
,
err
:=
fmt
.
Sscanf
(
dec
.
Data
,
"0x%x"
,
&
declog
.
Data
);
err
!=
nil
{
return
fmt
.
Errorf
(
"invalid hex log data"
)
}
if
_
,
err
:=
fmt
.
Sscanf
(
dec
.
BlockNumber
,
"0x%x"
,
&
declog
.
BlockNumber
);
err
!=
nil
{
return
fmt
.
Errorf
(
"invalid hex log block number"
)
}
if
_
,
err
:=
fmt
.
Sscanf
(
dec
.
TxIndex
,
"0x%x"
,
&
declog
.
TxIndex
);
err
!=
nil
{
return
fmt
.
Errorf
(
"invalid hex log tx index"
)
}
if
_
,
err
:=
fmt
.
Sscanf
(
dec
.
Index
,
"0x%x"
,
&
declog
.
Index
);
err
!=
nil
{
return
fmt
.
Errorf
(
"invalid hex log index"
)
}
*
r
=
declog
return
nil
return
nil
}
}
...
...
core/vm/log_test.go
View file @
65e6319b
...
@@ -28,6 +28,9 @@ var unmarshalLogTests = map[string]struct {
...
@@ -28,6 +28,9 @@ var unmarshalLogTests = map[string]struct {
"ok"
:
{
"ok"
:
{
input
:
`{"address":"0xecf8f87f810ecf450940c9f60066b4a7a501d6a7","blockHash":"0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056","blockNumber":"0x1ecfa4","data":"0x000000000000000000000000000000000000000000000001a055690d9db80000","logIndex":"0x2","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x00000000000000000000000080b2c9d7cbbf30a1b0fc8983c647d754c6525615","0x000000000000000000000000f9dff387dcb5cc4cca5b91adb07a95f54e9f1bb6"],"transactionHash":"0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e","transactionIndex":"0x3"}`
,
input
:
`{"address":"0xecf8f87f810ecf450940c9f60066b4a7a501d6a7","blockHash":"0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056","blockNumber":"0x1ecfa4","data":"0x000000000000000000000000000000000000000000000001a055690d9db80000","logIndex":"0x2","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x00000000000000000000000080b2c9d7cbbf30a1b0fc8983c647d754c6525615","0x000000000000000000000000f9dff387dcb5cc4cca5b91adb07a95f54e9f1bb6"],"transactionHash":"0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e","transactionIndex":"0x3"}`
,
},
},
"empty data"
:
{
input
:
`{"address":"0xecf8f87f810ecf450940c9f60066b4a7a501d6a7","blockHash":"0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056","blockNumber":"0x1ecfa4","data":"0x","logIndex":"0x2","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x00000000000000000000000080b2c9d7cbbf30a1b0fc8983c647d754c6525615","0x000000000000000000000000f9dff387dcb5cc4cca5b91adb07a95f54e9f1bb6"],"transactionHash":"0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e","transactionIndex":"0x3"}`
,
},
"missing data"
:
{
"missing data"
:
{
input
:
`{"address":"0xecf8f87f810ecf450940c9f60066b4a7a501d6a7","blockHash":"0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056","blockNumber":"0x1ecfa4","logIndex":"0x2","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x00000000000000000000000080b2c9d7cbbf30a1b0fc8983c647d754c6525615","0x000000000000000000000000f9dff387dcb5cc4cca5b91adb07a95f54e9f1bb6"],"transactionHash":"0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e","transactionIndex":"0x3"}`
,
input
:
`{"address":"0xecf8f87f810ecf450940c9f60066b4a7a501d6a7","blockHash":"0x656c34545f90a730a19008c0e7a7cd4fb3895064b48d6d69761bd5abad681056","blockNumber":"0x1ecfa4","logIndex":"0x2","topics":["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef","0x00000000000000000000000080b2c9d7cbbf30a1b0fc8983c647d754c6525615","0x000000000000000000000000f9dff387dcb5cc4cca5b91adb07a95f54e9f1bb6"],"transactionHash":"0x3b198bfd5d2907285af009e9ae84a0ecd63677110d89d7e030251acb87f6487e","transactionIndex":"0x3"}`
,
wantError
:
errMissingLogFields
,
wantError
:
errMissingLogFields
,
...
...
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