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
41c493ac
Commit
41c493ac
authored
Mar 20, 2015
by
obscuren
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'rpcfrontier' of github.com-obscure:ethereum/go-ethereum into rpcfrontier
parents
55fdf3e4
eb452115
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
97 deletions
+111
-97
api.go
rpc/api.go
+36
-3
http.go
rpc/http.go
+8
-8
messages_test.go
rpc/messages_test.go
+41
-0
responses.go
rpc/responses.go
+26
-0
util.go
rpc/util.go
+0
-86
No files found.
rpc/api.go
View file @
41c493ac
...
...
@@ -214,7 +214,7 @@ func (self *EthereumApi) FilterChanged(id int, reply *interface{}) error {
defer
self
.
logMut
.
Unlock
()
if
self
.
logs
[
id
]
!=
nil
{
*
reply
=
toLog
s
(
self
.
logs
[
id
]
.
get
())
*
reply
=
NewLogsRe
s
(
self
.
logs
[
id
]
.
get
())
}
return
nil
...
...
@@ -226,7 +226,7 @@ func (self *EthereumApi) Logs(id int, reply *interface{}) error {
filter
:=
self
.
filterManager
.
GetFilter
(
id
)
if
filter
!=
nil
{
*
reply
=
toLog
s
(
filter
.
Find
())
*
reply
=
NewLogsRe
s
(
filter
.
Find
())
}
return
nil
...
...
@@ -236,7 +236,7 @@ func (self *EthereumApi) AllLogs(args *FilterOptions, reply *interface{}) error
filter
:=
core
.
NewFilter
(
self
.
xeth
()
.
Backend
())
filter
.
SetOptions
(
toFilterOptions
(
args
))
*
reply
=
toLog
s
(
filter
.
Find
())
*
reply
=
NewLogsRe
s
(
filter
.
Find
())
return
nil
}
...
...
@@ -873,3 +873,36 @@ func toFilterOptions(options *FilterOptions) core.FilterOptions {
return
opts
}
type
whisperFilter
struct
{
messages
[]
xeth
.
WhisperMessage
timeout
time
.
Time
id
int
}
func
(
w
*
whisperFilter
)
add
(
msgs
...
xeth
.
WhisperMessage
)
{
w
.
messages
=
append
(
w
.
messages
,
msgs
...
)
}
func
(
w
*
whisperFilter
)
get
()
[]
xeth
.
WhisperMessage
{
w
.
timeout
=
time
.
Now
()
tmp
:=
w
.
messages
w
.
messages
=
nil
return
tmp
}
type
logFilter
struct
{
logs
state
.
Logs
timeout
time
.
Time
id
int
}
func
(
l
*
logFilter
)
add
(
logs
...
state
.
Log
)
{
l
.
logs
=
append
(
l
.
logs
,
logs
...
)
}
func
(
l
*
logFilter
)
get
()
state
.
Logs
{
l
.
timeout
=
time
.
Now
()
tmp
:=
l
.
logs
l
.
logs
=
nil
return
tmp
}
rpc/http.go
View file @
41c493ac
...
...
@@ -10,7 +10,7 @@ import (
"github.com/ethereum/go-ethereum/xeth"
)
var
rpc
httplogger
=
logger
.
NewLogger
(
"RPC-HTTP
"
)
var
rpc
logger
=
logger
.
NewLogger
(
"RPC
"
)
const
(
jsonrpcver
=
"2.0"
...
...
@@ -28,7 +28,7 @@ func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler {
// Limit request size to resist DoS
if
req
.
ContentLength
>
maxSizeReqLength
{
jsonerr
:=
&
RpcErrorObject
{
-
32700
,
"Request too large"
}
S
end
(
w
,
&
RpcErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
nil
,
Error
:
jsonerr
})
s
end
(
w
,
&
RpcErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
nil
,
Error
:
jsonerr
})
return
}
...
...
@@ -37,14 +37,14 @@ func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler {
body
,
err
:=
ioutil
.
ReadAll
(
req
.
Body
)
if
err
!=
nil
{
jsonerr
:=
&
RpcErrorObject
{
-
32700
,
"Could not read request body"
}
S
end
(
w
,
&
RpcErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
nil
,
Error
:
jsonerr
})
s
end
(
w
,
&
RpcErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
nil
,
Error
:
jsonerr
})
}
// Try to parse the request as a single
var
reqSingle
RpcRequest
if
err
:=
json
.
Unmarshal
(
body
,
&
reqSingle
);
err
==
nil
{
response
:=
RpcResponse
(
api
,
&
reqSingle
)
S
end
(
w
,
&
response
)
s
end
(
w
,
&
response
)
return
}
...
...
@@ -57,13 +57,13 @@ func JSONRPC(pipe *xeth.XEth, dataDir string) http.Handler {
response
:=
RpcResponse
(
api
,
&
request
)
resBatch
[
i
]
=
response
}
S
end
(
w
,
resBatch
)
s
end
(
w
,
resBatch
)
return
}
// Not a batch or single request, error
jsonerr
:=
&
RpcErrorObject
{
-
32600
,
"Could not decode request"
}
S
end
(
w
,
&
RpcErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
nil
,
Error
:
jsonerr
})
s
end
(
w
,
&
RpcErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
nil
,
Error
:
jsonerr
})
})
}
...
...
@@ -84,11 +84,11 @@ func RpcResponse(api *EthereumApi, request *RpcRequest) *interface{} {
response
=
&
RpcErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
request
.
Id
,
Error
:
jsonerr
}
}
rpc
http
logger
.
DebugDetailf
(
"Generated response: %T %s"
,
response
,
response
)
rpclogger
.
DebugDetailf
(
"Generated response: %T %s"
,
response
,
response
)
return
&
response
}
func
S
end
(
writer
io
.
Writer
,
v
interface
{})
(
n
int
,
err
error
)
{
func
s
end
(
writer
io
.
Writer
,
v
interface
{})
(
n
int
,
err
error
)
{
var
payload
[]
byte
payload
,
err
=
json
.
MarshalIndent
(
v
,
""
,
"
\t
"
)
if
err
!=
nil
{
...
...
rpc/messages_test.go
0 → 100644
View file @
41c493ac
package
rpc
import
(
"testing"
)
func
TestInsufficientParamsError
(
t
*
testing
.
T
)
{
err
:=
NewInsufficientParamsError
(
0
,
1
)
expected
:=
"insufficient params, want 1 have 0"
if
err
.
Error
()
!=
expected
{
t
.
Error
(
err
.
Error
())
}
}
func
TestNotImplementedError
(
t
*
testing
.
T
)
{
err
:=
NewNotImplementedError
(
"foo"
)
expected
:=
"foo method not implemented"
if
err
.
Error
()
!=
expected
{
t
.
Error
(
err
.
Error
())
}
}
func
TestDecodeParamError
(
t
*
testing
.
T
)
{
err
:=
NewDecodeParamError
(
"foo"
)
expected
:=
"could not decode, foo"
if
err
.
Error
()
!=
expected
{
t
.
Error
(
err
.
Error
())
}
}
func
TestValidationError
(
t
*
testing
.
T
)
{
err
:=
NewValidationError
(
"foo"
,
"should be `bar`"
)
expected
:=
"foo not valid, should be `bar`"
if
err
.
Error
()
!=
expected
{
t
.
Error
(
err
.
Error
())
}
}
rpc/responses.go
View file @
41c493ac
...
...
@@ -7,6 +7,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/state"
)
type
BlockRes
struct
{
...
...
@@ -211,3 +212,28 @@ type FilterWhisperRes struct {
Payload
string
`json:"payload"`
WorkProved
string
`json:"workProved"`
}
type
LogRes
struct
{
Address
string
`json:"address"`
Topic
[]
string
`json:"topic"`
Data
string
`json:"data"`
Number
uint64
`json:"number"`
}
func
NewLogsRes
(
logs
state
.
Logs
)
(
ls
[]
LogRes
)
{
ls
=
make
([]
LogRes
,
len
(
logs
))
for
i
,
log
:=
range
logs
{
var
l
LogRes
l
.
Topic
=
make
([]
string
,
len
(
log
.
Topics
()))
l
.
Address
=
common
.
ToHex
(
log
.
Address
())
l
.
Data
=
common
.
ToHex
(
log
.
Data
())
l
.
Number
=
log
.
Number
()
for
j
,
topic
:=
range
log
.
Topics
()
{
l
.
Topic
[
j
]
=
common
.
ToHex
(
topic
)
}
ls
[
i
]
=
l
}
return
}
rpc/util.go
deleted
100644 → 0
View file @
55fdf3e4
/*
This file is part of go-ethereum
go-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
go-ethereum 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
package
rpc
import
(
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/xeth"
)
var
rpclogger
=
logger
.
NewLogger
(
"RPC"
)
type
Log
struct
{
Address
string
`json:"address"`
Topic
[]
string
`json:"topic"`
Data
string
`json:"data"`
Number
uint64
`json:"number"`
}
func
toLogs
(
logs
state
.
Logs
)
(
ls
[]
Log
)
{
ls
=
make
([]
Log
,
len
(
logs
))
for
i
,
log
:=
range
logs
{
var
l
Log
l
.
Topic
=
make
([]
string
,
len
(
log
.
Topics
()))
l
.
Address
=
common
.
ToHex
(
log
.
Address
())
l
.
Data
=
common
.
ToHex
(
log
.
Data
())
l
.
Number
=
log
.
Number
()
for
j
,
topic
:=
range
log
.
Topics
()
{
l
.
Topic
[
j
]
=
common
.
ToHex
(
topic
)
}
ls
[
i
]
=
l
}
return
}
type
whisperFilter
struct
{
messages
[]
xeth
.
WhisperMessage
timeout
time
.
Time
id
int
}
func
(
w
*
whisperFilter
)
add
(
msgs
...
xeth
.
WhisperMessage
)
{
w
.
messages
=
append
(
w
.
messages
,
msgs
...
)
}
func
(
w
*
whisperFilter
)
get
()
[]
xeth
.
WhisperMessage
{
w
.
timeout
=
time
.
Now
()
tmp
:=
w
.
messages
w
.
messages
=
nil
return
tmp
}
type
logFilter
struct
{
logs
state
.
Logs
timeout
time
.
Time
id
int
}
func
(
l
*
logFilter
)
add
(
logs
...
state
.
Log
)
{
l
.
logs
=
append
(
l
.
logs
,
logs
...
)
}
func
(
l
*
logFilter
)
get
()
state
.
Logs
{
l
.
timeout
=
time
.
Now
()
tmp
:=
l
.
logs
l
.
logs
=
nil
return
tmp
}
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