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
a6ca3d02
Commit
a6ca3d02
authored
Apr 03, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #626 from tgerring/rpcfabian
RPC Tests updates
parents
29a9c6be
3e042317
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
180 additions
and
34 deletions
+180
-34
bytes.go
common/bytes.go
+5
-0
api.go
rpc/api.go
+30
-19
args.go
rpc/args.go
+13
-6
args_test.go
rpc/args_test.go
+70
-0
responses.go
rpc/responses.go
+58
-7
xeth.go
xeth/xeth.go
+4
-2
No files found.
common/bytes.go
View file @
a6ca3d02
...
...
@@ -127,6 +127,11 @@ func CopyBytes(b []byte) (copiedBytes []byte) {
return
}
func
HasHexPrefix
(
str
string
)
bool
{
l
:=
len
(
str
)
return
l
>=
2
&&
str
[
0
:
2
]
==
"0x"
}
func
IsHex
(
str
string
)
bool
{
l
:=
len
(
str
)
return
l
>=
4
&&
l
%
2
==
0
&&
str
[
0
:
2
]
==
"0x"
...
...
rpc/api.go
View file @
a6ca3d02
...
...
@@ -2,6 +2,7 @@ package rpc
import
(
"encoding/json"
// "fmt"
"math/big"
"sync"
...
...
@@ -112,7 +113,11 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
}
block
:=
NewBlockRes
(
api
.
xeth
()
.
EthBlockByHash
(
args
.
Hash
),
false
)
*
reply
=
common
.
ToHex
(
big
.
NewInt
(
int64
(
len
(
block
.
Transactions
)))
.
Bytes
())
if
block
==
nil
{
*
reply
=
nil
}
else
{
*
reply
=
common
.
ToHex
(
big
.
NewInt
(
int64
(
len
(
block
.
Transactions
)))
.
Bytes
())
}
case
"eth_getBlockTransactionCountByNumber"
:
args
:=
new
(
BlockNumArg
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
...
...
@@ -192,9 +197,9 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
*
reply
=
br
case
"eth_getTransactionByHash"
:
// HashIndexArgs used, but only the "Hash" part we need.
args
:=
new
(
HashIndexArgs
)
args
:=
new
(
HashArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
}
tx
,
bhash
,
bnum
,
txi
:=
api
.
xeth
()
.
EthTransactionByHash
(
args
.
Hash
)
if
tx
!=
nil
{
...
...
@@ -212,11 +217,16 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
block
:=
api
.
xeth
()
.
EthBlockByHash
(
args
.
Hash
)
br
:=
NewBlockRes
(
block
,
true
)
if
br
==
nil
{
*
reply
=
nil
}
if
args
.
Index
>=
int64
(
len
(
br
.
Transactions
))
||
args
.
Index
<
0
{
return
NewValidationError
(
"Index"
,
"does not exist"
)
// return NewValidationError("Index", "does not exist")
*
reply
=
nil
}
else
{
*
reply
=
br
.
Transactions
[
args
.
Index
]
}
*
reply
=
br
.
Transactions
[
args
.
Index
]
case
"eth_getTransactionByBlockNumberAndIndex"
:
args
:=
new
(
BlockNumIndexArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
...
...
@@ -225,11 +235,16 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
block
:=
api
.
xeth
()
.
EthBlockByNumber
(
args
.
BlockNumber
)
v
:=
NewBlockRes
(
block
,
true
)
if
v
==
nil
{
*
reply
=
nil
}
if
args
.
Index
>=
int64
(
len
(
v
.
Transactions
))
||
args
.
Index
<
0
{
return
NewValidationError
(
"Index"
,
"does not exist"
)
// return NewValidationError("Index", "does not exist")
*
reply
=
nil
}
else
{
*
reply
=
v
.
Transactions
[
args
.
Index
]
}
*
reply
=
v
.
Transactions
[
args
.
Index
]
case
"eth_getUncleByBlockHashAndIndex"
:
args
:=
new
(
HashIndexArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
...
...
@@ -243,13 +258,11 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
}
if
args
.
Index
>=
int64
(
len
(
br
.
Uncles
))
||
args
.
Index
<
0
{
return
NewValidationError
(
"Index"
,
"does not exist"
)
// return NewValidationError("Index", "does not exist")
*
reply
=
nil
}
else
{
*
reply
=
br
.
Uncles
[
args
.
Index
]
}
uhash
:=
br
.
Uncles
[
args
.
Index
]
uncle
:=
NewBlockRes
(
api
.
xeth
()
.
EthBlockByHash
(
uhash
.
String
()),
false
)
*
reply
=
uncle
case
"eth_getUncleByBlockNumberAndIndex"
:
args
:=
new
(
BlockNumIndexArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
...
...
@@ -265,13 +278,11 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
}
if
args
.
Index
>=
int64
(
len
(
v
.
Uncles
))
||
args
.
Index
<
0
{
return
NewValidationError
(
"Index"
,
"does not exist"
)
// return NewValidationError("Index", "does not exist")
*
reply
=
nil
}
else
{
*
reply
=
v
.
Uncles
[
args
.
Index
]
}
uhash
:=
v
.
Uncles
[
args
.
Index
]
uncle
:=
NewBlockRes
(
api
.
xeth
()
.
EthBlockByHash
(
uhash
.
String
()),
false
)
*
reply
=
uncle
case
"eth_getCompilers"
:
c
:=
[]
string
{
""
}
*
reply
=
c
...
...
rpc/args.go
View file @
a6ca3d02
...
...
@@ -41,7 +41,11 @@ func blockHeight(raw interface{}, number *int64) error {
case
"pending"
:
*
number
=
-
2
default
:
*
number
=
common
.
String2Big
(
str
)
.
Int64
()
if
common
.
HasHexPrefix
(
str
)
{
*
number
=
common
.
String2Big
(
str
)
.
Int64
()
}
else
{
return
NewInvalidTypeError
(
"blockNumber"
,
"is not a valid string"
)
}
}
return
nil
...
...
@@ -1021,12 +1025,15 @@ func (args *WhisperFilterArgs) UnmarshalJSON(b []byte) (err error) {
return
NewInsufficientParamsError
(
len
(
obj
),
1
)
}
var
argstr
string
argstr
,
ok
:=
obj
[
0
]
.
To
.
(
string
)
if
!
ok
{
return
NewInvalidTypeError
(
"to"
,
"is not a string"
)
if
obj
[
0
]
.
To
==
nil
{
args
.
To
=
""
}
else
{
argstr
,
ok
:=
obj
[
0
]
.
To
.
(
string
)
if
!
ok
{
return
NewInvalidTypeError
(
"to"
,
"is not a string"
)
}
args
.
To
=
argstr
}
args
.
To
=
argstr
t
:=
make
([]
string
,
len
(
obj
[
0
]
.
Topics
))
for
i
,
j
:=
range
obj
[
0
]
.
Topics
{
...
...
rpc/args_test.go
View file @
a6ca3d02
...
...
@@ -1805,6 +1805,16 @@ func TestWhisperFilterArgsEmpty(t *testing.T) {
}
}
func
TestWhisperFilterArgsToInt
(
t
*
testing
.
T
)
{
input
:=
`[{"to": 2}]`
args
:=
new
(
WhisperFilterArgs
)
str
:=
ExpectInvalidTypeError
(
json
.
Unmarshal
([]
byte
(
input
),
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestWhisperFilterArgsToBool
(
t
*
testing
.
T
)
{
input
:=
`[{"topics": ["0x68656c6c6f20776f726c64"], "to": false}]`
...
...
@@ -1815,6 +1825,21 @@ func TestWhisperFilterArgsToBool(t *testing.T) {
}
}
func
TestWhisperFilterArgsToMissing
(
t
*
testing
.
T
)
{
input
:=
`[{"topics": ["0x68656c6c6f20776f726c64"]}]`
expected
:=
new
(
WhisperFilterArgs
)
expected
.
To
=
""
args
:=
new
(
WhisperFilterArgs
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
t
.
Error
(
err
)
}
if
args
.
To
!=
expected
.
To
{
t
.
Errorf
(
"To shoud be %v but is %v"
,
expected
.
To
,
args
.
To
)
}
}
func
TestWhisperFilterArgsTopicInt
(
t
*
testing
.
T
)
{
input
:=
`[{"topics": [6], "to": "0x34ag445g3455b34"}]`
...
...
@@ -2090,6 +2115,51 @@ func TestHashIndexArgsInvalidIndex(t *testing.T) {
}
}
func
TestHashArgs
(
t
*
testing
.
T
)
{
input
:=
`["0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b"]`
expected
:=
new
(
HashIndexArgs
)
expected
.
Hash
=
"0xc6ef2fc5426d6ad6fd9e2a26abeab0aa2411b7ab17f30a99d3cb96aed1d1055b"
args
:=
new
(
HashArgs
)
if
err
:=
json
.
Unmarshal
([]
byte
(
input
),
&
args
);
err
!=
nil
{
t
.
Error
(
err
)
}
if
expected
.
Hash
!=
args
.
Hash
{
t
.
Errorf
(
"Hash shoud be %#v but is %#v"
,
expected
.
Hash
,
args
.
Hash
)
}
}
func
TestHashArgsEmpty
(
t
*
testing
.
T
)
{
input
:=
`[]`
args
:=
new
(
HashArgs
)
str
:=
ExpectInsufficientParamsError
(
json
.
Unmarshal
([]
byte
(
input
),
&
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestHashArgsInvalid
(
t
*
testing
.
T
)
{
input
:=
`{}`
args
:=
new
(
HashArgs
)
str
:=
ExpectDecodeParamError
(
json
.
Unmarshal
([]
byte
(
input
),
&
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestHashArgsInvalidHash
(
t
*
testing
.
T
)
{
input
:=
`[7]`
args
:=
new
(
HashArgs
)
str
:=
ExpectInvalidTypeError
(
json
.
Unmarshal
([]
byte
(
input
),
&
args
))
if
len
(
str
)
>
0
{
t
.
Error
(
str
)
}
}
func
TestSubmitWorkArgs
(
t
*
testing
.
T
)
{
input
:=
`["0x0000000000000001", "0x1234567890abcdef1234567890abcdef", "0xD1GE5700000000000000000000000000"]`
expected
:=
new
(
SubmitWorkArgs
)
...
...
rpc/responses.go
View file @
a6ca3d02
...
...
@@ -28,7 +28,7 @@ type BlockRes struct {
GasUsed
*
hexnum
`json:"gasUsed"`
UnixTimestamp
*
hexnum
`json:"timestamp"`
Transactions
[]
*
TransactionRes
`json:"transactions"`
Uncles
[]
*
hexdata
`json:"uncles"`
Uncles
[]
*
UncleRes
`json:"uncles"`
}
func
(
b
*
BlockRes
)
MarshalJSON
()
([]
byte
,
error
)
{
...
...
@@ -73,7 +73,10 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) {
ext
.
GasUsed
=
b
.
GasUsed
ext
.
UnixTimestamp
=
b
.
UnixTimestamp
ext
.
Transactions
=
b
.
Transactions
ext
.
Uncles
=
b
.
Uncles
ext
.
Uncles
=
make
([]
*
hexdata
,
len
(
b
.
Uncles
))
for
i
,
u
:=
range
b
.
Uncles
{
ext
.
Uncles
[
i
]
=
u
.
BlockHash
}
return
json
.
Marshal
(
ext
)
}
else
{
var
ext
struct
{
...
...
@@ -119,14 +122,15 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) {
for
i
,
tx
:=
range
b
.
Transactions
{
ext
.
Transactions
[
i
]
=
tx
.
Hash
}
ext
.
Uncles
=
b
.
Uncles
ext
.
Uncles
=
make
([]
*
hexdata
,
len
(
b
.
Uncles
))
for
i
,
u
:=
range
b
.
Uncles
{
ext
.
Uncles
[
i
]
=
u
.
BlockHash
}
return
json
.
Marshal
(
ext
)
}
}
func
NewBlockRes
(
block
*
types
.
Block
,
fullTx
bool
)
*
BlockRes
{
// TODO respect fullTx flag
if
block
==
nil
{
return
nil
}
...
...
@@ -159,9 +163,9 @@ func NewBlockRes(block *types.Block, fullTx bool) *BlockRes {
res
.
Transactions
[
i
]
.
TxIndex
=
newHexNum
(
i
)
}
res
.
Uncles
=
make
([]
*
hexdata
,
len
(
block
.
Uncles
()))
res
.
Uncles
=
make
([]
*
UncleRes
,
len
(
block
.
Uncles
()))
for
i
,
uncle
:=
range
block
.
Uncles
()
{
res
.
Uncles
[
i
]
=
newHexData
(
uncle
.
Hash
()
)
res
.
Uncles
[
i
]
=
NewUncleRes
(
uncle
)
}
return
res
...
...
@@ -182,6 +186,10 @@ type TransactionRes struct {
}
func
NewTransactionRes
(
tx
*
types
.
Transaction
)
*
TransactionRes
{
if
tx
==
nil
{
return
nil
}
var
v
=
new
(
TransactionRes
)
v
.
Hash
=
newHexData
(
tx
.
Hash
())
v
.
Nonce
=
newHexNum
(
tx
.
Nonce
())
...
...
@@ -198,6 +206,49 @@ func NewTransactionRes(tx *types.Transaction) *TransactionRes {
return
v
}
type
UncleRes
struct
{
BlockNumber
*
hexnum
`json:"number"`
BlockHash
*
hexdata
`json:"hash"`
ParentHash
*
hexdata
`json:"parentHash"`
Nonce
*
hexdata
`json:"nonce"`
Sha3Uncles
*
hexdata
`json:"sha3Uncles"`
ReceiptHash
*
hexdata
`json:"receiptHash"`
LogsBloom
*
hexdata
`json:"logsBloom"`
TransactionRoot
*
hexdata
`json:"transactionsRoot"`
StateRoot
*
hexdata
`json:"stateRoot"`
Miner
*
hexdata
`json:"miner"`
Difficulty
*
hexnum
`json:"difficulty"`
ExtraData
*
hexdata
`json:"extraData"`
GasLimit
*
hexnum
`json:"gasLimit"`
GasUsed
*
hexnum
`json:"gasUsed"`
UnixTimestamp
*
hexnum
`json:"timestamp"`
}
func
NewUncleRes
(
h
*
types
.
Header
)
*
UncleRes
{
if
h
==
nil
{
return
nil
}
var
v
=
new
(
UncleRes
)
v
.
BlockNumber
=
newHexNum
(
h
.
Number
)
v
.
BlockHash
=
newHexData
(
h
.
Hash
())
v
.
ParentHash
=
newHexData
(
h
.
ParentHash
)
v
.
Sha3Uncles
=
newHexData
(
h
.
UncleHash
)
v
.
Nonce
=
newHexData
(
h
.
Nonce
[
:
])
v
.
LogsBloom
=
newHexData
(
h
.
Bloom
)
v
.
TransactionRoot
=
newHexData
(
h
.
TxHash
)
v
.
StateRoot
=
newHexData
(
h
.
Root
)
v
.
Miner
=
newHexData
(
h
.
Coinbase
)
v
.
Difficulty
=
newHexNum
(
h
.
Difficulty
)
v
.
ExtraData
=
newHexData
(
h
.
Extra
)
v
.
GasLimit
=
newHexNum
(
h
.
GasLimit
)
v
.
GasUsed
=
newHexNum
(
h
.
GasUsed
)
v
.
UnixTimestamp
=
newHexNum
(
h
.
Time
)
v
.
ReceiptHash
=
newHexData
(
h
.
ReceiptHash
)
return
v
}
// type FilterLogRes struct {
// Hash string `json:"hash"`
// Address string `json:"address"`
...
...
xeth/xeth.go
View file @
a6ca3d02
...
...
@@ -196,7 +196,7 @@ func (self *XEth) EthTransactionByHash(hash string) (tx *types.Transaction, blha
// meta
var
txExtra
struct
{
BlockHash
common
.
Hash
BlockIndex
int64
BlockIndex
u
int64
Index
uint64
}
...
...
@@ -205,8 +205,10 @@ func (self *XEth) EthTransactionByHash(hash string) (tx *types.Transaction, blha
err
:=
rlp
.
Decode
(
r
,
&
txExtra
)
if
err
==
nil
{
blhash
=
txExtra
.
BlockHash
blnum
=
big
.
NewInt
(
txExtra
.
BlockIndex
)
blnum
=
big
.
NewInt
(
int64
(
txExtra
.
BlockIndex
)
)
txi
=
txExtra
.
Index
}
else
{
pipelogger
.
Errorln
(
err
)
}
return
...
...
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