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
b6f0b400
Commit
b6f0b400
authored
Apr 1, 2015
by
Taylor Gerring
Browse files
Options
Downloads
Patches
Plain Diff
Respect fullTx option #614
parent
55b96899
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
rpc/responses.go
+95
-0
95 additions, 0 deletions
rpc/responses.go
rpc/responses_test.go
+63
-0
63 additions, 0 deletions
rpc/responses_test.go
with
158 additions
and
0 deletions
rpc/responses.go
+
95
−
0
View file @
b6f0b400
package
rpc
package
rpc
import
(
import
(
"encoding/json"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
)
)
...
@@ -29,6 +31,99 @@ type BlockRes struct {
...
@@ -29,6 +31,99 @@ type BlockRes struct {
Uncles
[]
*
hexdata
`json:"uncles"`
Uncles
[]
*
hexdata
`json:"uncles"`
}
}
func
(
b
*
BlockRes
)
MarshalJSON
()
([]
byte
,
error
)
{
if
b
.
fullTx
{
var
ext
struct
{
BlockNumber
*
hexnum
`json:"number"`
BlockHash
*
hexdata
`json:"hash"`
ParentHash
*
hexdata
`json:"parentHash"`
Nonce
*
hexdata
`json:"nonce"`
Sha3Uncles
*
hexdata
`json:"sha3Uncles"`
LogsBloom
*
hexdata
`json:"logsBloom"`
TransactionRoot
*
hexdata
`json:"transactionRoot"`
StateRoot
*
hexdata
`json:"stateRoot"`
Miner
*
hexdata
`json:"miner"`
Difficulty
*
hexnum
`json:"difficulty"`
TotalDifficulty
*
hexnum
`json:"totalDifficulty"`
Size
*
hexnum
`json:"size"`
ExtraData
*
hexdata
`json:"extraData"`
GasLimit
*
hexnum
`json:"gasLimit"`
MinGasPrice
*
hexnum
`json:"minGasPrice"`
GasUsed
*
hexnum
`json:"gasUsed"`
UnixTimestamp
*
hexnum
`json:"timestamp"`
Transactions
[]
*
TransactionRes
`json:"transactions"`
Uncles
[]
*
hexdata
`json:"uncles"`
}
ext
.
BlockNumber
=
b
.
BlockNumber
ext
.
BlockHash
=
b
.
BlockHash
ext
.
ParentHash
=
b
.
ParentHash
ext
.
Nonce
=
b
.
Nonce
ext
.
Sha3Uncles
=
b
.
Sha3Uncles
ext
.
LogsBloom
=
b
.
LogsBloom
ext
.
TransactionRoot
=
b
.
TransactionRoot
ext
.
StateRoot
=
b
.
StateRoot
ext
.
Miner
=
b
.
Miner
ext
.
Difficulty
=
b
.
Difficulty
ext
.
TotalDifficulty
=
b
.
TotalDifficulty
ext
.
Size
=
b
.
Size
ext
.
ExtraData
=
b
.
ExtraData
ext
.
GasLimit
=
b
.
GasLimit
ext
.
MinGasPrice
=
b
.
MinGasPrice
ext
.
GasUsed
=
b
.
GasUsed
ext
.
UnixTimestamp
=
b
.
UnixTimestamp
ext
.
Transactions
=
b
.
Transactions
ext
.
Uncles
=
b
.
Uncles
return
json
.
Marshal
(
ext
)
}
else
{
var
ext
struct
{
BlockNumber
*
hexnum
`json:"number"`
BlockHash
*
hexdata
`json:"hash"`
ParentHash
*
hexdata
`json:"parentHash"`
Nonce
*
hexdata
`json:"nonce"`
Sha3Uncles
*
hexdata
`json:"sha3Uncles"`
LogsBloom
*
hexdata
`json:"logsBloom"`
TransactionRoot
*
hexdata
`json:"transactionRoot"`
StateRoot
*
hexdata
`json:"stateRoot"`
Miner
*
hexdata
`json:"miner"`
Difficulty
*
hexnum
`json:"difficulty"`
TotalDifficulty
*
hexnum
`json:"totalDifficulty"`
Size
*
hexnum
`json:"size"`
ExtraData
*
hexdata
`json:"extraData"`
GasLimit
*
hexnum
`json:"gasLimit"`
MinGasPrice
*
hexnum
`json:"minGasPrice"`
GasUsed
*
hexnum
`json:"gasUsed"`
UnixTimestamp
*
hexnum
`json:"timestamp"`
Transactions
[]
*
hexdata
`json:"transactions"`
Uncles
[]
*
hexdata
`json:"uncles"`
}
ext
.
BlockNumber
=
b
.
BlockNumber
ext
.
BlockHash
=
b
.
BlockHash
ext
.
ParentHash
=
b
.
ParentHash
ext
.
Nonce
=
b
.
Nonce
ext
.
Sha3Uncles
=
b
.
Sha3Uncles
ext
.
LogsBloom
=
b
.
LogsBloom
ext
.
TransactionRoot
=
b
.
TransactionRoot
ext
.
StateRoot
=
b
.
StateRoot
ext
.
Miner
=
b
.
Miner
ext
.
Difficulty
=
b
.
Difficulty
ext
.
TotalDifficulty
=
b
.
TotalDifficulty
ext
.
Size
=
b
.
Size
ext
.
ExtraData
=
b
.
ExtraData
ext
.
GasLimit
=
b
.
GasLimit
ext
.
MinGasPrice
=
b
.
MinGasPrice
ext
.
GasUsed
=
b
.
GasUsed
ext
.
UnixTimestamp
=
b
.
UnixTimestamp
ext
.
Transactions
=
make
([]
*
hexdata
,
len
(
b
.
Transactions
))
for
i
,
tx
:=
range
b
.
Transactions
{
ext
.
Transactions
[
i
]
=
tx
.
Hash
}
ext
.
Uncles
=
b
.
Uncles
return
json
.
Marshal
(
ext
)
}
}
func
NewBlockRes
(
block
*
types
.
Block
,
fullTx
bool
)
*
BlockRes
{
func
NewBlockRes
(
block
*
types
.
Block
,
fullTx
bool
)
*
BlockRes
{
// TODO respect fullTx flag
// TODO respect fullTx flag
...
...
This diff is collapsed.
Click to expand it.
rpc/responses_test.go
+
63
−
0
View file @
b6f0b400
...
@@ -21,6 +21,8 @@ const (
...
@@ -21,6 +21,8 @@ const (
reNumNonZero
=
`"0x([1-9a-f][0-9a-f]{0,15})"`
// non-zero required must not have left-padded zeros
reNumNonZero
=
`"0x([1-9a-f][0-9a-f]{0,15})"`
// non-zero required must not have left-padded zeros
reNumOpt
=
`"0x([1-9a-f][0-9a-f]{0,15})|0"|null`
// must not have left-padded zeros or null
reNumOpt
=
`"0x([1-9a-f][0-9a-f]{0,15})|0"|null`
// must not have left-padded zeros or null
reData
=
`"0x[0-9a-f]*"`
// can be "empty"
reData
=
`"0x[0-9a-f]*"`
// can be "empty"
// reListHash = `[("\w":"0x[0-9a-f]{64}",?)*]`
// reListObj = `[("\w":(".+"|null),?)*]`
)
)
func
TestNewBlockRes
(
t
*
testing
.
T
)
{
func
TestNewBlockRes
(
t
*
testing
.
T
)
{
...
@@ -49,9 +51,70 @@ func TestNewBlockRes(t *testing.T) {
...
@@ -49,9 +51,70 @@ func TestNewBlockRes(t *testing.T) {
// "minGasPrice": "0x",
// "minGasPrice": "0x",
"gasUsed"
:
reNum
,
"gasUsed"
:
reNum
,
"timestamp"
:
reNum
,
"timestamp"
:
reNum
,
// "transactions": reListHash,
// "uncles": reListHash,
}
}
to
:=
common
.
HexToAddress
(
"0x02"
)
amount
:=
big
.
NewInt
(
1
)
gasAmount
:=
big
.
NewInt
(
1
)
gasPrice
:=
big
.
NewInt
(
1
)
data
:=
[]
byte
{
1
,
2
,
3
}
tx
:=
types
.
NewTransactionMessage
(
to
,
amount
,
gasAmount
,
gasPrice
,
data
)
v
:=
NewBlockRes
(
block
,
false
)
v
:=
NewBlockRes
(
block
,
false
)
v
.
Transactions
=
make
([]
*
TransactionRes
,
1
)
v
.
Transactions
[
0
]
=
NewTransactionRes
(
tx
)
j
,
_
:=
json
.
Marshal
(
v
)
for
k
,
re
:=
range
tests
{
match
,
_
:=
regexp
.
MatchString
(
fmt
.
Sprintf
(
`{.*"%s":%s.*}`
,
k
,
re
),
string
(
j
))
if
!
match
{
t
.
Error
(
fmt
.
Sprintf
(
"%s output json does not match format %s. Got %s"
,
k
,
re
,
j
))
}
}
}
func
TestNewBlockResWithTrans
(
t
*
testing
.
T
)
{
parentHash
:=
common
.
HexToHash
(
"0x01"
)
coinbase
:=
common
.
HexToAddress
(
"0x01"
)
root
:=
common
.
HexToHash
(
"0x01"
)
difficulty
:=
common
.
Big1
nonce
:=
uint64
(
1
)
extra
:=
""
block
:=
types
.
NewBlock
(
parentHash
,
coinbase
,
root
,
difficulty
,
nonce
,
extra
)
tests
:=
map
[
string
]
string
{
"number"
:
reNum
,
"hash"
:
reHash
,
"parentHash"
:
reHash
,
"nonce"
:
reData
,
"sha3Uncles"
:
reHash
,
"logsBloom"
:
reData
,
"transactionRoot"
:
reHash
,
"stateRoot"
:
reHash
,
"miner"
:
reAddress
,
"difficulty"
:
`"0x1"`
,
"totalDifficulty"
:
reNum
,
"size"
:
reNumNonZero
,
"extraData"
:
reData
,
"gasLimit"
:
reNum
,
// "minGasPrice": "0x",
"gasUsed"
:
reNum
,
"timestamp"
:
reNum
,
// "transactions": `[{.*}]`,
// "uncles": reListHash,
}
to
:=
common
.
HexToAddress
(
"0x02"
)
amount
:=
big
.
NewInt
(
1
)
gasAmount
:=
big
.
NewInt
(
1
)
gasPrice
:=
big
.
NewInt
(
1
)
data
:=
[]
byte
{
1
,
2
,
3
}
tx
:=
types
.
NewTransactionMessage
(
to
,
amount
,
gasAmount
,
gasPrice
,
data
)
v
:=
NewBlockRes
(
block
,
true
)
v
.
Transactions
=
make
([]
*
TransactionRes
,
1
)
v
.
Transactions
[
0
]
=
NewTransactionRes
(
tx
)
j
,
_
:=
json
.
Marshal
(
v
)
j
,
_
:=
json
.
Marshal
(
v
)
for
k
,
re
:=
range
tests
{
for
k
,
re
:=
range
tests
{
...
...
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