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
ef9d825c
Commit
ef9d825c
authored
Mar 06, 2015
by
Taylor Gerring
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor & cleanup
parent
9f5e9eb3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
543 additions
and
657 deletions
+543
-657
types.go
javascript/types.go
+1
-1
api.go
rpc/api.go
+110
-172
args.go
rpc/args.go
+402
-112
messages.go
rpc/messages.go
+26
-364
xeth.go
xeth/xeth.go
+4
-8
No files found.
javascript/types.go
View file @
ef9d825c
...
@@ -62,7 +62,7 @@ type JSEthereum struct {
...
@@ -62,7 +62,7 @@ type JSEthereum struct {
func
(
self
*
JSEthereum
)
Block
(
v
interface
{})
otto
.
Value
{
func
(
self
*
JSEthereum
)
Block
(
v
interface
{})
otto
.
Value
{
if
number
,
ok
:=
v
.
(
int64
);
ok
{
if
number
,
ok
:=
v
.
(
int64
);
ok
{
return
self
.
toVal
(
&
JSBlock
{
self
.
XEth
.
BlockByNumber
(
int32
(
number
)),
self
})
return
self
.
toVal
(
&
JSBlock
{
self
.
XEth
.
BlockByNumber
(
uint64
(
number
)),
self
})
}
else
if
hash
,
ok
:=
v
.
(
string
);
ok
{
}
else
if
hash
,
ok
:=
v
.
(
string
);
ok
{
return
self
.
toVal
(
&
JSBlock
{
self
.
XEth
.
BlockByHash
(
hash
),
self
})
return
self
.
toVal
(
&
JSBlock
{
self
.
XEth
.
BlockByHash
(
hash
),
self
})
}
}
...
...
rpc/api.go
View file @
ef9d825c
/*
For each request type, define the following:
1. RpcRequest "To" method [message.go], which does basic validation and conversion to "Args" type via json.Decoder()
2. json.Decoder() calls "UnmarshalON" defined on each "Args" struct
3. EthereumApi method, taking the "Args" type and replying with an interface to be marshalled to ON
*/
package
rpc
package
rpc
import
(
import
(
"encoding/json"
"fmt"
"fmt"
"math/big"
"math/big"
"strings"
"strings"
...
@@ -150,16 +143,16 @@ func (self *EthereumApi) Unregister(args string, reply *interface{}) error {
...
@@ -150,16 +143,16 @@ func (self *EthereumApi) Unregister(args string, reply *interface{}) error {
return
nil
return
nil
}
}
func
(
self
*
EthereumApi
)
WatchTx
(
args
string
,
reply
*
interface
{})
error
{
//
func (self *EthereumApi) WatchTx(args string, reply *interface{}) error {
self
.
regmut
.
Lock
()
//
self.regmut.Lock()
defer
self
.
regmut
.
Unlock
()
//
defer self.regmut.Unlock()
txs
:=
self
.
register
[
args
]
//
txs := self.register[args]
self
.
register
[
args
]
=
nil
//
self.register[args] = nil
*
reply
=
txs
//
*reply = txs
return
nil
//
return nil
}
//
}
func
(
self
*
EthereumApi
)
NewFilter
(
args
*
FilterOptions
,
reply
*
interface
{})
error
{
func
(
self
*
EthereumApi
)
NewFilter
(
args
*
FilterOptions
,
reply
*
interface
{})
error
{
var
id
int
var
id
int
...
@@ -241,16 +234,6 @@ func (self *EthereumApi) AllLogs(args *FilterOptions, reply *interface{}) error
...
@@ -241,16 +234,6 @@ func (self *EthereumApi) AllLogs(args *FilterOptions, reply *interface{}) error
return
nil
return
nil
}
}
func
(
p
*
EthereumApi
)
GetBlock
(
args
*
GetBlockArgs
,
reply
*
interface
{})
error
{
// This seems a bit precarious Maybe worth splitting to discrete functions
if
len
(
args
.
Hash
)
>
0
{
*
reply
=
p
.
xeth
()
.
BlockByHash
(
args
.
Hash
)
}
else
{
*
reply
=
p
.
xeth
()
.
BlockByNumber
(
args
.
BlockNumber
)
}
return
nil
}
func
(
p
*
EthereumApi
)
Transact
(
args
*
NewTxArgs
,
reply
*
interface
{})
error
{
func
(
p
*
EthereumApi
)
Transact
(
args
*
NewTxArgs
,
reply
*
interface
{})
error
{
if
args
.
Gas
==
ethutil
.
Big0
{
if
args
.
Gas
==
ethutil
.
Big0
{
args
.
Gas
=
defaultGas
args
.
Gas
=
defaultGas
...
@@ -301,22 +284,27 @@ func (p *EthereumApi) Call(args *NewTxArgs, reply *interface{}) error {
...
@@ -301,22 +284,27 @@ func (p *EthereumApi) Call(args *NewTxArgs, reply *interface{}) error {
return
nil
return
nil
}
}
func
(
p
*
EthereumApi
)
PushTx
(
args
*
PushTxArgs
,
reply
*
interface
{})
error
{
func
(
p
*
EthereumApi
)
GetBalance
(
args
*
GetBalanceArgs
,
reply
*
interface
{})
error
{
err
:=
args
.
requirementsPushTx
()
if
err
:=
args
.
requirements
();
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
result
,
_
:=
p
.
xeth
()
.
PushTx
(
args
.
Tx
)
state
:=
p
.
xeth
()
.
State
()
.
SafeGet
(
args
.
Address
)
*
reply
=
result
*
reply
=
toHex
(
state
.
Balance
()
.
Bytes
())
return
nil
return
nil
}
}
func
(
p
*
EthereumApi
)
GetStorageAt
(
args
*
GetStorageAtArgs
,
reply
*
interface
{})
error
{
func
(
p
*
EthereumApi
)
GetStorage
(
args
*
GetStorageArgs
,
reply
*
interface
{})
error
{
err
:=
args
.
requirements
()
if
err
:=
args
.
requirements
();
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
*
reply
=
p
.
xeth
()
.
State
()
.
SafeGet
(
args
.
Address
)
.
Storage
()
return
nil
}
func
(
p
*
EthereumApi
)
GetStorageAt
(
args
*
GetStorageAtArgs
,
reply
*
interface
{})
error
{
if
err
:=
args
.
requirements
();
err
!=
nil
{
return
err
}
state
:=
p
.
xeth
()
.
State
()
.
SafeGet
(
args
.
Address
)
state
:=
p
.
xeth
()
.
State
()
.
SafeGet
(
args
.
Address
)
value
:=
state
.
StorageString
(
args
.
Key
)
value
:=
state
.
StorageString
(
args
.
Key
)
...
@@ -333,47 +321,6 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e
...
@@ -333,47 +321,6 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e
return
nil
return
nil
}
}
func
(
p
*
EthereumApi
)
GetStorage
(
args
*
GetStorageArgs
,
reply
*
interface
{})
error
{
err
:=
args
.
requirements
()
if
err
!=
nil
{
return
err
}
*
reply
=
p
.
xeth
()
.
State
()
.
SafeGet
(
args
.
Address
)
.
Storage
()
return
nil
}
func
(
p
*
EthereumApi
)
GetPeerCount
(
reply
*
interface
{})
error
{
c
:=
p
.
xeth
()
.
PeerCount
()
*
reply
=
toHex
(
big
.
NewInt
(
int64
(
c
))
.
Bytes
())
return
nil
}
func
(
p
*
EthereumApi
)
GetIsListening
(
reply
*
interface
{})
error
{
*
reply
=
p
.
xeth
()
.
IsListening
()
return
nil
}
func
(
p
*
EthereumApi
)
GetCoinbase
(
reply
*
interface
{})
error
{
*
reply
=
p
.
xeth
()
.
Coinbase
()
return
nil
}
func
(
p
*
EthereumApi
)
Accounts
(
reply
*
interface
{})
error
{
*
reply
=
p
.
xeth
()
.
Accounts
()
return
nil
}
func
(
p
*
EthereumApi
)
GetIsMining
(
reply
*
interface
{})
error
{
*
reply
=
p
.
xeth
()
.
IsMining
()
return
nil
}
func
(
p
*
EthereumApi
)
BlockNumber
(
reply
*
interface
{})
error
{
*
reply
=
toHex
(
p
.
xeth
()
.
Backend
()
.
ChainManager
()
.
CurrentBlock
()
.
Number
()
.
Bytes
())
return
nil
}
func
(
p
*
EthereumApi
)
GetTxCountAt
(
args
*
GetTxCountArgs
,
reply
*
interface
{})
error
{
func
(
p
*
EthereumApi
)
GetTxCountAt
(
args
*
GetTxCountArgs
,
reply
*
interface
{})
error
{
err
:=
args
.
requirements
()
err
:=
args
.
requirements
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -383,19 +330,8 @@ func (p *EthereumApi) GetTxCountAt(args *GetTxCountArgs, reply *interface{}) err
...
@@ -383,19 +330,8 @@ func (p *EthereumApi) GetTxCountAt(args *GetTxCountArgs, reply *interface{}) err
return
nil
return
nil
}
}
func
(
p
*
EthereumApi
)
GetBalanceAt
(
args
*
GetBalanceArgs
,
reply
*
interface
{})
error
{
func
(
p
*
EthereumApi
)
GetData
(
args
*
GetDataArgs
,
reply
*
interface
{})
error
{
err
:=
args
.
requirements
()
if
err
:=
args
.
requirements
();
err
!=
nil
{
if
err
!=
nil
{
return
err
}
state
:=
p
.
xeth
()
.
State
()
.
SafeGet
(
args
.
Address
)
*
reply
=
toHex
(
state
.
Balance
()
.
Bytes
())
return
nil
}
func
(
p
*
EthereumApi
)
GetCodeAt
(
args
*
GetCodeAtArgs
,
reply
*
interface
{})
error
{
err
:=
args
.
requirements
()
if
err
!=
nil
{
return
err
return
err
}
}
*
reply
=
p
.
xeth
()
.
CodeAt
(
args
.
Address
)
*
reply
=
p
.
xeth
()
.
CodeAt
(
args
.
Address
)
...
@@ -408,8 +344,8 @@ func (p *EthereumApi) GetCompilers(reply *interface{}) error {
...
@@ -408,8 +344,8 @@ func (p *EthereumApi) GetCompilers(reply *interface{}) error {
return
nil
return
nil
}
}
func
(
p
*
EthereumApi
)
CompileSerpent
(
script
string
,
reply
*
interface
{})
error
{
func
(
p
*
EthereumApi
)
CompileSerpent
(
args
*
CompileArgs
,
reply
*
interface
{})
error
{
res
,
err
:=
ethutil
.
Compile
(
script
,
false
)
res
,
err
:=
ethutil
.
Compile
(
args
.
Source
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -417,14 +353,8 @@ func (p *EthereumApi) CompileSerpent(script string, reply *interface{}) error {
...
@@ -417,14 +353,8 @@ func (p *EthereumApi) CompileSerpent(script string, reply *interface{}) error {
return
nil
return
nil
}
}
func
(
p
*
EthereumApi
)
Sha3
(
args
*
Sha3Args
,
reply
*
interface
{})
error
{
*
reply
=
toHex
(
crypto
.
Sha3
(
fromHex
(
args
.
Data
)))
return
nil
}
func
(
p
*
EthereumApi
)
DbPut
(
args
*
DbArgs
,
reply
*
interface
{})
error
{
func
(
p
*
EthereumApi
)
DbPut
(
args
*
DbArgs
,
reply
*
interface
{})
error
{
err
:=
args
.
requirements
()
if
err
:=
args
.
requirements
();
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -434,8 +364,7 @@ func (p *EthereumApi) DbPut(args *DbArgs, reply *interface{}) error {
...
@@ -434,8 +364,7 @@ func (p *EthereumApi) DbPut(args *DbArgs, reply *interface{}) error {
}
}
func
(
p
*
EthereumApi
)
DbGet
(
args
*
DbArgs
,
reply
*
interface
{})
error
{
func
(
p
*
EthereumApi
)
DbGet
(
args
*
DbArgs
,
reply
*
interface
{})
error
{
err
:=
args
.
requirements
()
if
err
:=
args
.
requirements
();
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -449,14 +378,18 @@ func (p *EthereumApi) NewWhisperIdentity(reply *interface{}) error {
...
@@ -449,14 +378,18 @@ func (p *EthereumApi) NewWhisperIdentity(reply *interface{}) error {
return
nil
return
nil
}
}
func
(
p
*
EthereumApi
)
NewWhisperFilter
(
args
*
xeth
.
Option
s
,
reply
*
interface
{})
error
{
func
(
p
*
EthereumApi
)
NewWhisperFilter
(
args
*
WhisperFilterArg
s
,
reply
*
interface
{})
error
{
var
id
int
var
id
int
args
.
Fn
=
func
(
msg
xeth
.
WhisperMessage
)
{
opts
:=
new
(
xeth
.
Options
)
opts
.
From
=
args
.
From
opts
.
To
=
args
.
To
opts
.
Topics
=
args
.
Topics
opts
.
Fn
=
func
(
msg
xeth
.
WhisperMessage
)
{
p
.
messagesMut
.
Lock
()
p
.
messagesMut
.
Lock
()
defer
p
.
messagesMut
.
Unlock
()
defer
p
.
messagesMut
.
Unlock
()
p
.
messages
[
id
]
.
add
(
msg
)
// = append(p.messages[id], msg)
p
.
messages
[
id
]
.
add
(
msg
)
// = append(p.messages[id], msg)
}
}
id
=
p
.
xeth
()
.
Whisper
()
.
Watch
(
arg
s
)
id
=
p
.
xeth
()
.
Whisper
()
.
Watch
(
opt
s
)
p
.
messages
[
id
]
=
&
whisperFilter
{
timeout
:
time
.
Now
()}
p
.
messages
[
id
]
=
&
whisperFilter
{
timeout
:
time
.
Now
()}
*
reply
=
id
*
reply
=
id
return
nil
return
nil
...
@@ -498,51 +431,50 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
...
@@ -498,51 +431,50 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
rpclogger
.
DebugDetailf
(
"%T %s"
,
req
.
Params
,
req
.
Params
)
rpclogger
.
DebugDetailf
(
"%T %s"
,
req
.
Params
,
req
.
Params
)
switch
req
.
Method
{
switch
req
.
Method
{
case
"web3_sha3"
:
case
"web3_sha3"
:
args
,
err
:=
req
.
ToSha3Args
(
)
args
:=
new
(
Sha3Args
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
Sha3
(
args
,
reply
)
*
reply
=
toHex
(
crypto
.
Sha3
(
fromHex
(
args
.
Data
))
)
case
"net_listening"
:
case
"net_listening"
:
return
p
.
GetIsListening
(
reply
)
*
reply
=
p
.
xeth
()
.
IsListening
(
)
case
"net_peerCount"
:
case
"net_peerCount"
:
return
p
.
GetPeerCount
(
reply
)
*
reply
=
toHex
(
big
.
NewInt
(
int64
(
p
.
xeth
()
.
PeerCount
()))
.
Bytes
()
)
case
"eth_coinbase"
:
case
"eth_coinbase"
:
return
p
.
GetCoinbase
(
reply
)
*
reply
=
p
.
xeth
()
.
Coinbase
(
)
case
"eth_mining"
:
case
"eth_mining"
:
return
p
.
GetIsMining
(
reply
)
*
reply
=
p
.
xeth
()
.
IsMining
(
)
case
"eth_gasPrice"
:
case
"eth_gasPrice"
:
*
reply
=
toHex
(
defaultGasPrice
.
Bytes
())
*
reply
=
toHex
(
defaultGasPrice
.
Bytes
())
return
nil
case
"eth_accounts"
:
case
"eth_accounts"
:
return
p
.
Accounts
(
reply
)
*
reply
=
p
.
xeth
()
.
Accounts
(
)
case
"eth_blockNumber"
:
case
"eth_blockNumber"
:
return
p
.
BlockNumber
(
reply
)
*
reply
=
toHex
(
p
.
xeth
()
.
Backend
()
.
ChainManager
()
.
CurrentBlock
()
.
Number
()
.
Bytes
()
)
case
"eth_getBalance"
:
case
"eth_getBalance"
:
// TODO handle
defaultBlock
// TODO handle
BlockNumber
args
,
err
:=
req
.
ToGetBalanceArgs
(
)
args
:=
new
(
GetBalanceArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
GetBalance
At
(
args
,
reply
)
return
p
.
GetBalance
(
args
,
reply
)
case
"eth_getStorage"
:
case
"eth_getStorage"
:
// TODO handle
defaultBlock
// TODO handle
BlockNumber
args
,
err
:=
req
.
ToStorageArgs
(
)
args
:=
new
(
GetStorageArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
GetStorage
(
args
,
reply
)
return
p
.
GetStorage
(
args
,
reply
)
case
"eth_getStorageAt"
:
case
"eth_getStorageAt"
:
// TODO handle
defaultBlock
// TODO handle
BlockNumber
args
,
err
:=
req
.
ToGetStorageAtArgs
(
)
args
:=
new
(
GetStorageAtArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
GetStorageAt
(
args
,
reply
)
return
p
.
GetStorageAt
(
args
,
reply
)
case
"eth_getTransactionCount"
:
case
"eth_getTransactionCount"
:
// TODO handle
defaultBlock
// TODO handle
BlockNumber
args
,
err
:=
req
.
ToGetTxCountArgs
(
)
args
:=
new
(
GetTxCountArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
GetTxCountAt
(
args
,
reply
)
return
p
.
GetTxCountAt
(
args
,
reply
)
...
@@ -552,34 +484,40 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
...
@@ -552,34 +484,40 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
case
"eth_getUncleCountByBlockNumber"
:
case
"eth_getUncleCountByBlockNumber"
:
return
errNotImplemented
return
errNotImplemented
case
"eth_getData"
:
case
"eth_getData"
:
// TODO handle
defaultBlock
// TODO handle
BlockNumber
args
,
err
:=
req
.
ToGetCodeAtArgs
(
)
args
:=
new
(
GetDataArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
Get
CodeAt
(
args
,
reply
)
return
p
.
Get
Data
(
args
,
reply
)
case
"eth_sendTransaction"
:
case
"eth_sendTransaction"
:
args
,
err
:=
req
.
ToNewTxArgs
(
)
args
:=
new
(
NewTxArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
Transact
(
args
,
reply
)
return
p
.
Transact
(
args
,
reply
)
case
"eth_call"
:
case
"eth_call"
:
args
,
err
:=
req
.
ToNewTxArgs
(
)
args
:=
new
(
NewTxArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
Call
(
args
,
reply
)
return
p
.
Call
(
args
,
reply
)
case
"eth_flush"
:
case
"eth_flush"
:
return
errNotImplemented
return
errNotImplemented
case
"eth_getBlockByNumber"
:
case
"eth_getBlockByHash"
:
case
"eth_getBlockByHash"
:
// TODO handle second param for "include transaction objects"
// TODO handle second param for "include transaction objects"
args
,
err
:=
req
.
ToGetBlockArgs
(
)
args
:=
new
(
GetBlockByHashArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
GetBlock
(
args
,
reply
)
*
reply
=
p
.
xeth
()
.
BlockByHash
(
args
.
BlockHash
)
case
"eth_getBlockByNumber"
:
// TODO handle second param for "include transaction objects"
args
:=
new
(
GetBlockByNumberArgs
)
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
}
*
reply
=
p
.
xeth
()
.
BlockByNumber
(
args
.
BlockNumber
)
case
"eth_getTransactionByHash"
:
case
"eth_getTransactionByHash"
:
case
"eth_getTransactionByBlockHashAndIndex"
:
case
"eth_getTransactionByBlockHashAndIndex"
:
case
"eth_getTransactionByBlockNumberAndIndex"
:
case
"eth_getTransactionByBlockNumberAndIndex"
:
...
@@ -592,44 +530,44 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
...
@@ -592,44 +530,44 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
case
"eth_compileLLL"
:
case
"eth_compileLLL"
:
return
errNotImplemented
return
errNotImplemented
case
"eth_compileSerpent"
:
case
"eth_compileSerpent"
:
args
,
err
:=
req
.
ToCompileArgs
(
)
args
:=
new
(
CompileArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
CompileSerpent
(
args
,
reply
)
return
p
.
CompileSerpent
(
args
,
reply
)
case
"eth_newFilter"
:
case
"eth_newFilter"
:
args
,
err
:=
req
.
ToFilterArgs
(
)
args
:=
new
(
FilterOptions
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
NewFilter
(
args
,
reply
)
return
p
.
NewFilter
(
args
,
reply
)
case
"eth_newBlockFilter"
:
case
"eth_newBlockFilter"
:
args
,
err
:=
req
.
ToFilterStringArgs
(
)
args
:=
new
(
FilterStringArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
NewFilterString
(
args
,
reply
)
return
p
.
NewFilterString
(
args
.
Word
,
reply
)
case
"eth_uninstallFilter"
:
case
"eth_uninstallFilter"
:
args
,
err
:=
req
.
ToUninstallFilterArgs
(
)
args
:=
new
(
FilterIdArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
UninstallFilter
(
args
,
reply
)
return
p
.
UninstallFilter
(
args
.
Id
,
reply
)
case
"eth_getFilterChanges"
:
case
"eth_getFilterChanges"
:
args
,
err
:=
req
.
ToIdArgs
(
)
args
:=
new
(
FilterIdArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
FilterChanged
(
args
,
reply
)
return
p
.
FilterChanged
(
args
.
Id
,
reply
)
case
"eth_getFilterLogs"
:
case
"eth_getFilterLogs"
:
args
,
err
:=
req
.
ToIdArgs
(
)
args
:=
new
(
FilterIdArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
Logs
(
args
,
reply
)
return
p
.
Logs
(
args
.
Id
,
reply
)
case
"eth_getLogs"
:
case
"eth_getLogs"
:
args
,
err
:=
req
.
ToFilterArgs
(
)
args
:=
new
(
FilterOptions
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
AllLogs
(
args
,
reply
)
return
p
.
AllLogs
(
args
,
reply
)
...
@@ -655,54 +593,54 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
...
@@ -655,54 +593,54 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
// }
// }
// return p.WatchTx(args, reply)
// return p.WatchTx(args, reply)
case
"db_put"
:
case
"db_put"
:
args
,
err
:=
req
.
ToDbPutArgs
(
)
args
:=
new
(
DbArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
DbPut
(
args
,
reply
)
return
p
.
DbPut
(
args
,
reply
)
case
"db_get"
:
case
"db_get"
:
args
,
err
:=
req
.
ToDbGetArgs
(
)
args
:=
new
(
DbArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
DbGet
(
args
,
reply
)
return
p
.
DbGet
(
args
,
reply
)
case
"shh_post"
:
case
"shh_post"
:
args
,
err
:=
req
.
ToWhisperPostArgs
(
)
args
:=
new
(
WhisperMessageArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
WhisperPost
(
args
,
reply
)
return
p
.
WhisperPost
(
args
,
reply
)
case
"shh_newIdentity"
:
case
"shh_newIdentity"
:
return
p
.
NewWhisperIdentity
(
reply
)
return
p
.
NewWhisperIdentity
(
reply
)
case
"shh_hasIdentity"
:
case
"shh_hasIdentity"
:
args
,
err
:=
req
.
ToWhisperHasIdentityArgs
(
)
args
:=
new
(
WhisperIdentityArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
HasWhisperIdentity
(
args
,
reply
)
return
p
.
HasWhisperIdentity
(
args
.
Identity
,
reply
)
case
"shh_newGroup"
:
case
"shh_newGroup"
:
case
"shh_addToGroup"
:
case
"shh_addToGroup"
:
return
errNotImplemented
return
errNotImplemented
case
"shh_newFilter"
:
case
"shh_newFilter"
:
args
,
err
:=
req
.
ToWhisperFilterArgs
(
)
args
:=
new
(
WhisperFilterArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
NewWhisperFilter
(
args
,
reply
)
return
p
.
NewWhisperFilter
(
args
,
reply
)
case
"shh_uninstallFilter"
:
case
"shh_uninstallFilter"
:
return
errNotImplemented
return
errNotImplemented
case
"shh_getFilterChanges"
:
case
"shh_getFilterChanges"
:
args
,
err
:=
req
.
ToIdArgs
(
)
args
:=
new
(
FilterIdArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
MessagesChanged
(
args
,
reply
)
return
p
.
MessagesChanged
(
args
.
Id
,
reply
)
case
"shh_getMessages"
:
case
"shh_getMessages"
:
args
,
err
:=
req
.
ToIdArgs
(
)
args
:=
new
(
FilterIdArgs
)
if
err
!=
nil
{
if
err
:=
json
.
Unmarshal
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
err
return
err
}
}
return
p
.
WhisperMessages
(
args
,
reply
)
return
p
.
WhisperMessages
(
args
.
Id
,
reply
)
case
"client_version"
:
case
"client_version"
:
*
reply
=
p
.
eth
.
GetClientVersion
()
*
reply
=
p
.
eth
.
GetClientVersion
()
default
:
default
:
...
...
rpc/args.go
View file @
ef9d825c
package
rpc
package
rpc
import
(
import
(
"bytes"
"encoding/json"
"encoding/json"
"math/big"
"math/big"
...
@@ -8,180 +9,248 @@ import (
...
@@ -8,180 +9,248 @@ import (
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/ethutil"
)
)
type
GetBlockArgs
struct
{
type
GetBlock
ByHash
Args
struct
{
Block
Number
int32
Block
Hash
string
Hash
string
Transactions
bool
}
}
func
(
obj
*
GetBlockArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
func
(
args
*
GetBlockByHashArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
argint
,
argstr
:=
int32
(
0
),
""
var
obj
[]
interface
{}
if
err
=
json
.
Unmarshal
(
b
,
&
argint
);
err
==
nil
{
r
:=
bytes
.
NewReader
(
b
)
obj
.
BlockNumber
=
argint
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
obj
);
err
!=
nil
{
return
return
errDecodeArgs
}
if
len
(
obj
)
<
1
{
return
errArguments
}
}
if
err
=
json
.
Unmarshal
(
b
,
&
argstr
);
err
==
nil
{
args
.
BlockHash
=
obj
[
0
]
.
(
string
)
obj
.
Hash
=
argstr
return
if
len
(
obj
)
>
1
{
args
.
Transactions
=
obj
[
1
]
.
(
bool
)
}
}
return
errDecodeArgs
return
nil
}
}
type
NewTxArgs
struct
{
type
GetBlockByNumberArgs
struct
{
From
string
`json:"from"`
BlockNumber
uint64
To
string
`json:"to"`
Transactions
bool
Value
*
big
.
Int
`json:"value"`
Gas
*
big
.
Int
`json:"gas"`
GasPrice
*
big
.
Int
`json:"gasPrice"`
Data
string
`json:"data"`
}
}
func
(
obj
*
NewTxArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
func
(
args
*
GetBlockByNumberArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
// Data can be either specified as "data" or "code" :-/
var
obj
[]
interface
{}
var
ext
struct
{
r
:=
bytes
.
NewReader
(
b
)
From
string
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
obj
);
err
!=
nil
{
To
string
return
errDecodeArgs
Value
string
Gas
string
GasPrice
string
Data
string
// Code string
}
}
if
err
=
json
.
Unmarshal
(
b
,
&
ext
);
err
==
nil
{
if
len
(
obj
)
<
1
{
// if len(ext.Data) == 0 {
return
errArguments
// ext.Data = ext.Code
}
// }
args
.
BlockNumber
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
]
.
(
string
)))
obj
.
From
=
ext
.
From
obj
.
To
=
ext
.
To
obj
.
Value
=
ethutil
.
Big
(
ext
.
Value
)
obj
.
Gas
=
ethutil
.
Big
(
ext
.
Gas
)
obj
.
GasPrice
=
ethutil
.
Big
(
ext
.
GasPrice
)
obj
.
Data
=
ext
.
Data
return
if
len
(
obj
)
>
1
{
args
.
Transactions
=
obj
[
1
]
.
(
bool
)
}
}
return
errDecodeArgs
return
nil
}
}
type
PushTxArgs
struct
{
type
NewTxArgs
struct
{
Tx
string
`json:"tx"`
From
string
To
string
Value
*
big
.
Int
Gas
*
big
.
Int
GasPrice
*
big
.
Int
Data
string
}
}
func
(
obj
*
PushTxArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
func
(
args
*
NewTxArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
arg0
:=
""
var
obj
[]
struct
{
if
err
=
json
.
Unmarshal
(
b
,
&
arg0
);
err
==
nil
{
From
string
`json:"from"`
obj
.
Tx
=
arg0
To
string
`json:"to"`
return
Value
string
`json:"value"`
Gas
string
`json:"gas"`
GasPrice
string
`json:"gasPrice"`
Data
string
`json:"data"`
}
}
return
errDecodeArgs
}
func
(
a
*
PushTxArgs
)
requirementsPushTx
()
error
{
if
err
=
json
.
Unmarshal
(
b
,
&
obj
);
err
!=
nil
{
if
a
.
Tx
==
""
{
return
errDecodeArgs
return
NewErrorWithMessage
(
errArguments
,
"PushTx requires a 'tx' as argument"
)
}
if
len
(
obj
)
<
1
{
return
errArguments
}
}
args
.
From
=
obj
[
0
]
.
From
args
.
To
=
obj
[
0
]
.
To
args
.
Value
=
ethutil
.
Big
(
obj
[
0
]
.
Value
)
args
.
Gas
=
ethutil
.
Big
(
obj
[
0
]
.
Gas
)
args
.
GasPrice
=
ethutil
.
Big
(
obj
[
0
]
.
GasPrice
)
args
.
Data
=
obj
[
0
]
.
Data
return
nil
return
nil
}
}
type
GetStorageArgs
struct
{
type
GetStorageArgs
struct
{
Address
string
Address
string
BlockNumber
uint64
}
}
func
(
obj
*
GetStorageArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
func
(
args
*
GetStorageArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
if
err
=
json
.
Unmarshal
(
b
,
&
obj
.
Address
);
err
!=
nil
{
var
obj
[]
interface
{}
r
:=
bytes
.
NewReader
(
b
)
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
obj
);
err
!=
nil
{
return
errDecodeArgs
return
errDecodeArgs
}
}
return
if
len
(
obj
)
<
1
{
return
errArguments
}
args
.
Address
=
obj
[
0
]
.
(
string
)
if
len
(
obj
)
>
1
{
args
.
BlockNumber
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
1
]
.
(
string
)))
}
return
nil
}
}
func
(
a
*
GetStorageArgs
)
requirements
()
error
{
func
(
a
rgs
*
GetStorageArgs
)
requirements
()
error
{
if
len
(
a
.
Address
)
==
0
{
if
len
(
a
rgs
.
Address
)
==
0
{
return
NewErrorWithMessage
(
errArguments
,
"
GetStorageAt requires an 'address' value as argument
"
)
return
NewErrorWithMessage
(
errArguments
,
"
Address cannot be blank
"
)
}
}
return
nil
return
nil
}
}
type
GetStorageAtArgs
struct
{
type
GetStorageAtArgs
struct
{
Address
string
Address
string
Key
string
Key
string
BlockNumber
uint64
}
}
func
(
obj
*
GetStorageAtArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
func
(
args
*
GetStorageAtArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
arg0
:=
""
var
obj
[]
interface
{}
if
err
=
json
.
Unmarshal
(
b
,
&
arg0
);
err
==
nil
{
r
:=
bytes
.
NewReader
(
b
)
obj
.
Address
=
arg0
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
obj
);
err
!=
nil
{
return
return
errDecodeArgs
}
if
len
(
obj
)
<
2
{
return
errArguments
}
args
.
Address
=
obj
[
0
]
.
(
string
)
args
.
Key
=
obj
[
1
]
.
(
string
)
if
len
(
obj
)
>
2
{
args
.
BlockNumber
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
2
]
.
(
string
)))
}
}
return
errDecodeArgs
return
nil
}
}
func
(
a
*
GetStorageAtArgs
)
requirements
()
error
{
func
(
a
rgs
*
GetStorageAtArgs
)
requirements
()
error
{
if
a
.
Address
==
""
{
if
len
(
args
.
Address
)
==
0
{
return
NewErrorWithMessage
(
errArguments
,
"
GetStorageAt requires an 'address' value as argument
"
)
return
NewErrorWithMessage
(
errArguments
,
"
Address cannot be blank
"
)
}
}
if
a
.
Key
==
""
{
return
NewErrorWithMessage
(
errArguments
,
"GetStorageAt requires an 'key' value as argument"
)
if
len
(
args
.
Key
)
==
0
{
return
NewErrorWithMessage
(
errArguments
,
"Key cannot be blank"
)
}
}
return
nil
return
nil
}
}
type
GetTxCountArgs
struct
{
type
GetTxCountArgs
struct
{
Address
string
`json:"address"`
Address
string
BlockNumber
uint64
}
}
func
(
obj
*
GetTxCountArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
func
(
args
*
GetTxCountArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
arg0
:=
""
var
obj
[]
interface
{}
if
err
=
json
.
Unmarshal
(
b
,
&
arg0
);
err
==
nil
{
r
:=
bytes
.
NewReader
(
b
)
obj
.
Address
=
arg0
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
obj
);
err
!=
nil
{
return
return
errDecodeArgs
}
if
len
(
obj
)
<
1
{
return
errArguments
}
}
return
errDecodeArgs
args
.
Address
=
obj
[
0
]
.
(
string
)
if
len
(
obj
)
>
1
{
args
.
BlockNumber
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
1
]
.
(
string
)))
}
return
nil
}
}
func
(
a
*
GetTxCountArgs
)
requirements
()
error
{
func
(
a
rgs
*
GetTxCountArgs
)
requirements
()
error
{
if
a
.
Address
==
""
{
if
len
(
args
.
Address
)
==
0
{
return
NewErrorWithMessage
(
errArguments
,
"
GetTxCountAt requires an 'address' value as argument
"
)
return
NewErrorWithMessage
(
errArguments
,
"
Address cannot be blank
"
)
}
}
return
nil
return
nil
}
}
type
GetBalanceArgs
struct
{
type
GetBalanceArgs
struct
{
Address
string
Address
string
BlockNumber
uint64
}
}
func
(
obj
*
GetBalanceArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
func
(
args
*
GetBalanceArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
arg0
:=
""
var
obj
[]
interface
{}
if
err
=
json
.
Unmarshal
(
b
,
&
arg0
);
err
==
nil
{
r
:=
bytes
.
NewReader
(
b
)
obj
.
Address
=
arg0
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
obj
);
err
!=
nil
{
return
return
errDecodeArgs
}
if
len
(
obj
)
<
1
{
return
errArguments
}
args
.
Address
=
obj
[
0
]
.
(
string
)
if
len
(
obj
)
>
1
{
args
.
BlockNumber
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
1
]
.
(
string
)))
}
}
return
errDecodeArgs
return
nil
}
}
func
(
a
*
GetBalanceArgs
)
requirements
()
error
{
func
(
a
rgs
*
GetBalanceArgs
)
requirements
()
error
{
if
a
.
Address
==
""
{
if
len
(
args
.
Address
)
==
0
{
return
NewErrorWithMessage
(
errArguments
,
"
GetBalanceAt requires an 'address' value as argument
"
)
return
NewErrorWithMessage
(
errArguments
,
"
Address cannot be blank
"
)
}
}
return
nil
return
nil
}
}
type
GetCodeAtArgs
struct
{
type
GetDataArgs
struct
{
Address
string
Address
string
BlockNumber
uint64
}
}
func
(
obj
*
GetCodeAtArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
func
(
args
*
GetDataArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
arg0
:=
""
var
obj
[]
interface
{}
if
err
=
json
.
Unmarshal
(
b
,
&
arg0
);
err
==
nil
{
r
:=
bytes
.
NewReader
(
b
)
obj
.
Address
=
arg0
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
obj
);
err
!=
nil
{
return
return
errDecodeArgs
}
if
len
(
obj
)
<
1
{
return
errArguments
}
args
.
Address
=
obj
[
0
]
.
(
string
)
if
len
(
obj
)
>
1
{
args
.
BlockNumber
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
1
]
.
(
string
)))
}
}
return
errDecodeArgs
return
nil
}
}
func
(
a
*
GetCodeAt
Args
)
requirements
()
error
{
func
(
a
rgs
*
GetData
Args
)
requirements
()
error
{
if
a
.
Address
==
""
{
if
len
(
args
.
Address
)
==
0
{
return
NewErrorWithMessage
(
errArguments
,
"
GetCodeAt requires an 'address' value as argument
"
)
return
NewErrorWithMessage
(
errArguments
,
"
Address cannot be blank
"
)
}
}
return
nil
return
nil
}
}
...
@@ -190,11 +259,55 @@ type Sha3Args struct {
...
@@ -190,11 +259,55 @@ type Sha3Args struct {
Data
string
Data
string
}
}
func
(
obj
*
Sha3Args
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
func
(
args
*
Sha3Args
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
if
err
=
json
.
Unmarshal
(
b
,
&
obj
.
Data
);
err
!=
nil
{
var
obj
[]
interface
{}
r
:=
bytes
.
NewReader
(
b
)
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
obj
);
err
!=
nil
{
return
NewErrorWithMessage
(
errDecodeArgs
,
err
.
Error
())
}
if
len
(
obj
)
<
1
{
return
errArguments
}
args
.
Data
=
obj
[
0
]
.
(
string
)
return
nil
}
type
FilterArgs
struct
{
FromBlock
uint64
ToBlock
uint64
Limit
uint64
Offset
uint64
Address
string
Topics
[]
string
}
func
(
args
*
FilterArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
struct
{
FromBlock
string
`json:"fromBlock"`
ToBlock
string
`json:"toBlock"`
Limit
string
`json:"limit"`
Offset
string
`json:"offset"`
Address
string
`json:"address"`
Topics
[]
string
`json:"topics"`
}
if
err
=
json
.
Unmarshal
(
b
,
&
obj
);
err
!=
nil
{
return
errDecodeArgs
return
errDecodeArgs
}
}
return
if
len
(
obj
)
<
1
{
return
errArguments
}
args
.
FromBlock
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
]
.
FromBlock
))
args
.
ToBlock
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
]
.
ToBlock
))
args
.
Limit
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
]
.
Limit
))
args
.
Offset
=
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
]
.
Offset
))
args
.
Address
=
obj
[
0
]
.
Address
args
.
Topics
=
obj
[
0
]
.
Topics
return
nil
}
}
type
FilterOptions
struct
{
type
FilterOptions
struct
{
...
@@ -206,6 +319,33 @@ type FilterOptions struct {
...
@@ -206,6 +319,33 @@ type FilterOptions struct {
Max
int
Max
int
}
}
func
(
args
*
FilterOptions
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
struct
{
FromBlock
string
`json:"fromBlock"`
ToBlock
string
`json:"toBlock"`
Limit
string
`json:"limit"`
Offset
string
`json:"offset"`
Address
string
`json:"address"`
Topics
[]
string
`json:"topics"`
}
if
err
=
json
.
Unmarshal
(
b
,
&
obj
);
err
!=
nil
{
return
errDecodeArgs
}
if
len
(
obj
)
<
1
{
return
errArguments
}
args
.
Earliest
=
int64
(
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
]
.
FromBlock
)))
args
.
Latest
=
int64
(
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
]
.
ToBlock
)))
args
.
Max
=
int
(
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
]
.
Limit
)))
args
.
Skip
=
int
(
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
]
.
Offset
)))
args
.
Address
=
obj
[
0
]
.
Address
args
.
Topic
=
obj
[
0
]
.
Topics
return
nil
}
func
toFilterOptions
(
options
*
FilterOptions
)
core
.
FilterOptions
{
func
toFilterOptions
(
options
*
FilterOptions
)
core
.
FilterOptions
{
var
opts
core
.
FilterOptions
var
opts
core
.
FilterOptions
...
@@ -232,9 +372,9 @@ func toFilterOptions(options *FilterOptions) core.FilterOptions {
...
@@ -232,9 +372,9 @@ func toFilterOptions(options *FilterOptions) core.FilterOptions {
return
opts
return
opts
}
}
type
FilterChangedArgs
struct
{
//
type FilterChangedArgs struct {
n
int
//
n int
}
//
}
type
DbArgs
struct
{
type
DbArgs
struct
{
Database
string
Database
string
...
@@ -242,12 +382,32 @@ type DbArgs struct {
...
@@ -242,12 +382,32 @@ type DbArgs struct {
Value
string
Value
string
}
}
func
(
args
*
DbArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
interface
{}
r
:=
bytes
.
NewReader
(
b
)
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
obj
);
err
!=
nil
{
return
errDecodeArgs
}
if
len
(
obj
)
<
2
{
return
errArguments
}
args
.
Database
=
obj
[
0
]
.
(
string
)
args
.
Key
=
obj
[
1
]
.
(
string
)
if
len
(
obj
)
>
2
{
args
.
Value
=
obj
[
2
]
.
(
string
)
}
return
nil
}
func
(
a
*
DbArgs
)
requirements
()
error
{
func
(
a
*
DbArgs
)
requirements
()
error
{
if
len
(
a
.
Database
)
==
0
{
if
len
(
a
.
Database
)
==
0
{
return
NewErrorWithMessage
(
errArguments
,
"D
bPutArgs requires an 'Database' value as argument
"
)
return
NewErrorWithMessage
(
errArguments
,
"D
atabase cannot be blank
"
)
}
}
if
len
(
a
.
Key
)
==
0
{
if
len
(
a
.
Key
)
==
0
{
return
NewErrorWithMessage
(
errArguments
,
"
DbPutArgs requires an 'Key' value as argument
"
)
return
NewErrorWithMessage
(
errArguments
,
"
Key cannot be blank
"
)
}
}
return
nil
return
nil
}
}
...
@@ -260,3 +420,133 @@ type WhisperMessageArgs struct {
...
@@ -260,3 +420,133 @@ type WhisperMessageArgs struct {
Priority
uint32
Priority
uint32
Ttl
uint32
Ttl
uint32
}
}
func
(
args
*
WhisperMessageArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
struct
{
Payload
string
To
string
From
string
Topic
[]
string
Priority
string
Ttl
string
}
if
err
=
json
.
Unmarshal
(
b
,
&
obj
);
err
!=
nil
{
return
errDecodeArgs
}
if
len
(
obj
)
<
1
{
return
errArguments
}
args
.
Payload
=
obj
[
0
]
.
Payload
args
.
To
=
obj
[
0
]
.
To
args
.
From
=
obj
[
0
]
.
From
args
.
Topic
=
obj
[
0
]
.
Topic
args
.
Priority
=
uint32
(
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
]
.
Priority
)))
args
.
Ttl
=
uint32
(
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
]
.
Ttl
)))
return
nil
}
type
CompileArgs
struct
{
Source
string
}
func
(
args
*
CompileArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
interface
{}
r
:=
bytes
.
NewReader
(
b
)
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
obj
);
err
!=
nil
{
return
errDecodeArgs
}
if
len
(
obj
)
>
0
{
args
.
Source
=
obj
[
0
]
.
(
string
)
}
return
nil
}
type
FilterStringArgs
struct
{
Word
string
}
func
(
args
*
FilterStringArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
string
r
:=
bytes
.
NewReader
(
b
)
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
obj
);
err
!=
nil
{
return
errDecodeArgs
}
if
len
(
obj
)
<
1
{
return
errDecodeArgs
}
args
.
Word
=
obj
[
0
]
return
nil
}
type
FilterIdArgs
struct
{
Id
int
}
func
(
args
*
FilterIdArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
string
r
:=
bytes
.
NewReader
(
b
)
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
obj
);
err
!=
nil
{
return
errDecodeArgs
}
if
len
(
obj
)
<
1
{
return
errDecodeArgs
}
args
.
Id
=
int
(
ethutil
.
BytesToNumber
(
fromHex
(
obj
[
0
])))
return
nil
}
type
WhisperIdentityArgs
struct
{
Identity
string
}
func
(
args
*
WhisperIdentityArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
string
r
:=
bytes
.
NewReader
(
b
)
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
obj
);
err
!=
nil
{
return
errDecodeArgs
}
if
len
(
obj
)
<
1
{
return
errDecodeArgs
}
args
.
Identity
=
obj
[
0
]
return
nil
}
type
WhisperFilterArgs
struct
{
To
string
From
string
Topics
[]
string
Fn
func
()
}
func
(
args
*
WhisperFilterArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
WhisperFilterArgs
if
err
=
json
.
Unmarshal
(
b
,
&
obj
);
err
!=
nil
{
return
errDecodeArgs
}
if
len
(
obj
)
<
1
{
return
errArguments
}
args
.
To
=
obj
[
0
]
.
To
args
.
From
=
obj
[
0
]
.
From
args
.
Topics
=
obj
[
0
]
.
Topics
return
nil
}
rpc/messages.go
View file @
ef9d825c
...
@@ -17,7 +17,6 @@
...
@@ -17,7 +17,6 @@
package
rpc
package
rpc
import
(
import
(
"bytes"
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
...
@@ -33,10 +32,10 @@ var (
...
@@ -33,10 +32,10 @@ var (
)
)
type
RpcRequest
struct
{
type
RpcRequest
struct
{
ID
interface
{}
`json:"id"`
ID
interface
{}
`json:"id"`
JsonRpc
string
`json:"jsonrpc"`
JsonRpc
string
`json:"jsonrpc"`
Method
string
`json:"method"`
Method
string
`json:"method"`
Params
[]
json
.
RawMessage
`json:"params"`
Params
json
.
RawMessage
`json:"params"`
}
}
type
RpcSuccessResponse
struct
{
type
RpcSuccessResponse
struct
{
...
@@ -61,367 +60,30 @@ func NewErrorWithMessage(err error, msg string) error {
...
@@ -61,367 +60,30 @@ func NewErrorWithMessage(err error, msg string) error {
return
fmt
.
Errorf
(
"%s: %s"
,
err
.
Error
(),
msg
)
return
fmt
.
Errorf
(
"%s: %s"
,
err
.
Error
(),
msg
)
}
}
func
(
req
*
RpcRequest
)
ToSha3Args
()
(
*
Sha3Args
,
error
)
{
// func (req *RpcRequest) ToRegisterArgs() (string, error) {
if
len
(
req
.
Params
)
<
1
{
// if len(req.Params) < 1 {
return
nil
,
errArguments
// return "", errArguments
}
// }
args
:=
new
(
Sha3Args
)
r
:=
bytes
.
NewReader
(
req
.
Params
[
0
])
if
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
args
);
err
!=
nil
{
return
nil
,
errDecodeArgs
}
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToGetBlockArgs
()
(
*
GetBlockArgs
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
nil
,
errArguments
}
args
:=
new
(
GetBlockArgs
)
r
:=
bytes
.
NewReader
(
req
.
Params
[
0
])
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
args
)
if
err
!=
nil
{
return
nil
,
errDecodeArgs
}
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToNewTxArgs
()
(
*
NewTxArgs
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
nil
,
errArguments
}
args
:=
new
(
NewTxArgs
)
r
:=
bytes
.
NewReader
(
req
.
Params
[
0
])
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
args
)
if
err
!=
nil
{
return
nil
,
NewErrorWithMessage
(
errDecodeArgs
,
err
.
Error
())
}
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToPushTxArgs
()
(
*
PushTxArgs
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
nil
,
errArguments
}
args
:=
new
(
PushTxArgs
)
r
:=
bytes
.
NewReader
(
req
.
Params
[
0
])
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
args
)
if
err
!=
nil
{
return
nil
,
errDecodeArgs
}
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToGetStorageAtArgs
()
(
*
GetStorageAtArgs
,
error
)
{
if
len
(
req
.
Params
)
<
2
{
return
nil
,
errArguments
}
args
:=
new
(
GetStorageAtArgs
)
var
arg0
,
arg1
string
r0
:=
bytes
.
NewReader
(
req
.
Params
[
0
])
if
err
:=
json
.
NewDecoder
(
r0
)
.
Decode
(
arg0
);
err
!=
nil
{
return
nil
,
errDecodeArgs
}
r1
:=
bytes
.
NewReader
(
req
.
Params
[
1
])
if
err
:=
json
.
NewDecoder
(
r1
)
.
Decode
(
arg1
);
err
!=
nil
{
return
nil
,
errDecodeArgs
}
args
.
Address
=
arg0
args
.
Key
=
arg1
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToStorageArgs
()
(
*
GetStorageArgs
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
nil
,
errArguments
}
args
:=
new
(
GetStorageArgs
)
r
:=
bytes
.
NewReader
(
req
.
Params
[
0
])
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
args
)
if
err
!=
nil
{
return
nil
,
errDecodeArgs
}
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToGetTxCountArgs
()
(
*
GetTxCountArgs
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
nil
,
errArguments
}
args
:=
new
(
GetTxCountArgs
)
r
:=
bytes
.
NewReader
(
req
.
Params
[
0
])
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
args
)
if
err
!=
nil
{
return
nil
,
errDecodeArgs
}
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToGetBalanceArgs
()
(
*
GetBalanceArgs
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
nil
,
errArguments
}
args
:=
new
(
GetBalanceArgs
)
r
:=
bytes
.
NewReader
(
req
.
Params
[
0
])
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
args
)
if
err
!=
nil
{
return
nil
,
errDecodeArgs
}
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToGetCodeAtArgs
()
(
*
GetCodeAtArgs
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
nil
,
errArguments
}
args
:=
new
(
GetCodeAtArgs
)
r
:=
bytes
.
NewReader
(
req
.
Params
[
0
])
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
args
)
if
err
!=
nil
{
return
nil
,
errDecodeArgs
}
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToBoolArgs
()
(
bool
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
false
,
errArguments
}
var
args
bool
err
:=
json
.
Unmarshal
(
req
.
Params
[
0
],
&
args
)
if
err
!=
nil
{
return
false
,
errDecodeArgs
}
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToIntArgs
()
(
int
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
0
,
errArguments
}
var
args
int
if
err
:=
json
.
Unmarshal
(
req
.
Params
[
0
],
&
args
);
err
!=
nil
{
return
0
,
errArguments
}
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToCompileArgs
()
(
string
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
""
,
errArguments
}
var
args
string
err
:=
json
.
Unmarshal
(
req
.
Params
[
0
],
&
args
)
if
err
!=
nil
{
return
""
,
errDecodeArgs
}
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToFilterArgs
()
(
*
FilterOptions
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
nil
,
errArguments
}
args
:=
new
(
FilterOptions
)
r
:=
bytes
.
NewReader
(
req
.
Params
[
0
])
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
args
)
if
err
!=
nil
{
return
nil
,
errDecodeArgs
}
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToFilterStringArgs
()
(
string
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
""
,
errArguments
}
var
args
string
err
:=
json
.
Unmarshal
(
req
.
Params
[
0
],
&
args
)
if
err
!=
nil
{
return
""
,
errDecodeArgs
}
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToUninstallFilterArgs
()
(
int
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
0
,
errArguments
}
var
args
int
err
:=
json
.
Unmarshal
(
req
.
Params
[
0
],
&
args
)
if
err
!=
nil
{
return
0
,
errDecodeArgs
}
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToFilterChangedArgs
()
(
int
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
0
,
errArguments
}
var
id
int
r
:=
bytes
.
NewReader
(
req
.
Params
[
0
])
err
:=
json
.
NewDecoder
(
r
)
.
Decode
(
&
id
)
if
err
!=
nil
{
return
0
,
errDecodeArgs
}
return
id
,
nil
}
func
(
req
*
RpcRequest
)
ToDbPutArgs
()
(
*
DbArgs
,
error
)
{
if
len
(
req
.
Params
)
<
3
{
return
nil
,
errArguments
}
var
args
DbArgs
err
:=
json
.
Unmarshal
(
req
.
Params
[
0
],
&
args
.
Database
)
if
err
!=
nil
{
return
nil
,
NewErrorWithMessage
(
errDecodeArgs
,
err
.
Error
())
}
err
=
json
.
Unmarshal
(
req
.
Params
[
1
],
&
args
.
Key
)
if
err
!=
nil
{
return
nil
,
NewErrorWithMessage
(
errDecodeArgs
,
err
.
Error
())
}
err
=
json
.
Unmarshal
(
req
.
Params
[
2
],
&
args
.
Value
)
if
err
!=
nil
{
return
nil
,
NewErrorWithMessage
(
errDecodeArgs
,
err
.
Error
())
}
return
&
args
,
nil
// var args string
}
// err := json.Unmarshal(req.Params, &args)
// if err != nil {
func
(
req
*
RpcRequest
)
ToDbGetArgs
()
(
*
DbArgs
,
error
)
{
// return "", err
if
len
(
req
.
Params
)
<
2
{
// }
return
nil
,
errArguments
}
var
args
DbArgs
// return args, nil
err
:=
json
.
Unmarshal
(
req
.
Params
[
0
],
&
args
.
Database
)
// }
if
err
!=
nil
{
return
nil
,
NewErrorWithMessage
(
errDecodeArgs
,
err
.
Error
())
}
err
=
json
.
Unmarshal
(
req
.
Params
[
1
],
&
args
.
Key
)
// func (req *RpcRequest) ToWatchTxArgs() (string, error) {
if
err
!=
nil
{
// if len(req.Params) < 1
{
return
nil
,
NewErrorWithMessage
(
errDecodeArgs
,
err
.
Error
())
// return "", errArguments
}
//
}
return
&
args
,
nil
// var args string
}
// err := json.Unmarshal(req.Params, &args)
// if err != nil {
// return "", err
// }
func
(
req
*
RpcRequest
)
ToWhisperFilterArgs
()
(
*
xeth
.
Options
,
error
)
{
// return args, nil
if
len
(
req
.
Params
)
<
1
{
// }
return
nil
,
errArguments
}
var
args
xeth
.
Options
err
:=
json
.
Unmarshal
(
req
.
Params
[
0
],
&
args
)
if
err
!=
nil
{
return
nil
,
NewErrorWithMessage
(
errDecodeArgs
,
err
.
Error
())
}
return
&
args
,
nil
}
func
(
req
*
RpcRequest
)
ToIdArgs
()
(
int
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
0
,
errArguments
}
var
id
int
err
:=
json
.
Unmarshal
(
req
.
Params
[
0
],
&
id
)
if
err
!=
nil
{
return
0
,
errDecodeArgs
}
return
id
,
nil
}
func
(
req
*
RpcRequest
)
ToWhisperPostArgs
()
(
*
WhisperMessageArgs
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
nil
,
errArguments
}
var
args
WhisperMessageArgs
err
:=
json
.
Unmarshal
(
req
.
Params
[
0
],
&
args
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
args
,
nil
}
func
(
req
*
RpcRequest
)
ToWhisperHasIdentityArgs
()
(
string
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
""
,
errArguments
}
var
args
string
err
:=
json
.
Unmarshal
(
req
.
Params
[
0
],
&
args
)
if
err
!=
nil
{
return
""
,
err
}
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToRegisterArgs
()
(
string
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
""
,
errArguments
}
var
args
string
err
:=
json
.
Unmarshal
(
req
.
Params
[
0
],
&
args
)
if
err
!=
nil
{
return
""
,
err
}
return
args
,
nil
}
func
(
req
*
RpcRequest
)
ToWatchTxArgs
()
(
string
,
error
)
{
if
len
(
req
.
Params
)
<
1
{
return
""
,
errArguments
}
var
args
string
err
:=
json
.
Unmarshal
(
req
.
Params
[
0
],
&
args
)
if
err
!=
nil
{
return
""
,
err
}
return
args
,
nil
}
xeth/xeth.go
View file @
ef9d825c
...
@@ -86,21 +86,17 @@ func (self *XEth) BlockByHash(strHash string) *Block {
...
@@ -86,21 +86,17 @@ func (self *XEth) BlockByHash(strHash string) *Block {
return
NewBlock
(
block
)
return
NewBlock
(
block
)
}
}
func
(
self
*
XEth
)
BlockByNumber
(
num
int32
)
*
Block
{
func
(
self
*
XEth
)
BlockByNumber
(
num
uint64
)
*
Block
{
if
num
==
-
1
{
return
NewBlock
(
self
.
chainManager
.
GetBlockByNumber
(
num
))
return
NewBlock
(
self
.
chainManager
.
CurrentBlock
())
}
return
NewBlock
(
self
.
chainManager
.
GetBlockByNumber
(
uint64
(
num
)))
}
}
func
(
self
*
XEth
)
Block
(
v
interface
{})
*
Block
{
func
(
self
*
XEth
)
Block
(
v
interface
{})
*
Block
{
if
n
,
ok
:=
v
.
(
int32
);
ok
{
if
n
,
ok
:=
v
.
(
int32
);
ok
{
return
self
.
BlockByNumber
(
n
)
return
self
.
BlockByNumber
(
uint64
(
n
)
)
}
else
if
str
,
ok
:=
v
.
(
string
);
ok
{
}
else
if
str
,
ok
:=
v
.
(
string
);
ok
{
return
self
.
BlockByHash
(
str
)
return
self
.
BlockByHash
(
str
)
}
else
if
f
,
ok
:=
v
.
(
float64
);
ok
{
// Don't ask ...
}
else
if
f
,
ok
:=
v
.
(
float64
);
ok
{
// Don't ask ...
return
self
.
BlockByNumber
(
int32
(
f
))
return
self
.
BlockByNumber
(
uint64
(
f
))
}
}
return
nil
return
nil
...
...
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