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
09d0d55f
Commit
09d0d55f
authored
Jun 09, 2015
by
Bas van Kervel
Committed by
Bas van Kervel
Jun 11, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added debug API
parent
faab931c
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
980 additions
and
712 deletions
+980
-712
api.go
rpc/api/api.go
+2
-1
debug.go
rpc/api/debug.go
+169
-0
debug_args.go
rpc/api/debug_args.go
+47
-0
debug_js.go
rpc/api/debug_js.go
+48
-0
utils.go
rpc/api/utils.go
+4
-0
ipc_unix.go
rpc/comms/ipc_unix.go
+5
-5
ipc_windows.go
rpc/comms/ipc_windows.go
+696
-699
jeth.go
rpc/jeth.go
+4
-3
types.go
rpc/shared/types.go
+5
-4
No files found.
rpc/api/api.go
View file @
09d0d55f
...
...
@@ -4,9 +4,10 @@ import "github.com/ethereum/go-ethereum/rpc/shared"
const
(
// List with all API's which are offered over the IPC interface by default
DefaultIpcApis
=
"eth,miner,net,web3"
DefaultIpcApis
=
"
debug,
eth,miner,net,web3"
EthApiName
=
"eth"
DebugApiName
=
"debug"
MergedApiName
=
"merged"
MinerApiName
=
"miner"
NetApiName
=
"net"
...
...
rpc/api/debug.go
0 → 100644
View file @
09d0d55f
package
api
import
(
"fmt"
"github.com/ethereum/ethash"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/xeth"
)
const
(
DebugVersion
=
"1.0.0"
)
var
(
// mapping between methods and handlers
DebugMapping
=
map
[
string
]
debughandler
{
"debug_dumpBlock"
:
(
*
DebugApi
)
.
DumpBlock
,
"debug_getBlockRlp"
:
(
*
DebugApi
)
.
GetBlockRlp
,
"debug_printBlock"
:
(
*
DebugApi
)
.
PrintBlock
,
"debug_processBlock"
:
(
*
DebugApi
)
.
ProcessBlock
,
"debug_seedHash"
:
(
*
DebugApi
)
.
SeedHash
,
"debug_setHead"
:
(
*
DebugApi
)
.
SetHead
,
}
)
// debug callback handler
type
debughandler
func
(
*
DebugApi
,
*
shared
.
Request
)
(
interface
{},
error
)
// admin api provider
type
DebugApi
struct
{
xeth
*
xeth
.
XEth
ethereum
*
eth
.
Ethereum
methods
map
[
string
]
debughandler
codec
codec
.
ApiCoder
}
// create a new debug api instance
func
NewDebugApi
(
xeth
*
xeth
.
XEth
,
ethereum
*
eth
.
Ethereum
,
coder
codec
.
Codec
)
*
DebugApi
{
return
&
DebugApi
{
xeth
:
xeth
,
ethereum
:
ethereum
,
methods
:
DebugMapping
,
codec
:
coder
.
New
(
nil
),
}
}
// collection with supported methods
func
(
self
*
DebugApi
)
Methods
()
[]
string
{
methods
:=
make
([]
string
,
len
(
self
.
methods
))
i
:=
0
for
k
:=
range
self
.
methods
{
methods
[
i
]
=
k
i
++
}
return
methods
}
// Execute given request
func
(
self
*
DebugApi
)
Execute
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
if
callback
,
ok
:=
self
.
methods
[
req
.
Method
];
ok
{
return
callback
(
self
,
req
)
}
return
nil
,
&
shared
.
NotImplementedError
{
req
.
Method
}
}
func
(
self
*
DebugApi
)
Name
()
string
{
return
DebugApiName
}
func
(
self
*
DebugApi
)
PrintBlock
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
args
:=
new
(
BlockNumArg
)
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
nil
,
shared
.
NewDecodeParamError
(
err
.
Error
())
}
block
:=
self
.
xeth
.
EthBlockByNumber
(
args
.
BlockNumber
)
return
fmt
.
Sprintf
(
"%s"
,
block
),
nil
}
func
(
self
*
DebugApi
)
DumpBlock
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
args
:=
new
(
BlockNumArg
)
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
nil
,
shared
.
NewDecodeParamError
(
err
.
Error
())
}
block
:=
self
.
xeth
.
EthBlockByNumber
(
args
.
BlockNumber
)
if
block
==
nil
{
return
nil
,
fmt
.
Errorf
(
"block #%d not found"
,
args
.
BlockNumber
)
}
stateDb
:=
state
.
New
(
block
.
Root
(),
self
.
ethereum
.
StateDb
())
if
stateDb
==
nil
{
return
nil
,
nil
}
return
stateDb
.
Dump
(),
nil
}
func
(
self
*
DebugApi
)
GetBlockRlp
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
args
:=
new
(
BlockNumArg
)
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
nil
,
shared
.
NewDecodeParamError
(
err
.
Error
())
}
block
:=
self
.
xeth
.
EthBlockByNumber
(
args
.
BlockNumber
)
if
block
==
nil
{
return
nil
,
fmt
.
Errorf
(
"block #%d not found"
,
args
.
BlockNumber
)
}
encoded
,
err
:=
rlp
.
EncodeToBytes
(
block
)
return
fmt
.
Sprintf
(
"%x"
,
encoded
),
err
}
func
(
self
*
DebugApi
)
SetHead
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
args
:=
new
(
BlockNumArg
)
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
nil
,
shared
.
NewDecodeParamError
(
err
.
Error
())
}
block
:=
self
.
xeth
.
EthBlockByNumber
(
args
.
BlockNumber
)
if
block
==
nil
{
return
nil
,
fmt
.
Errorf
(
"block #%d not found"
,
args
.
BlockNumber
)
}
self
.
ethereum
.
ChainManager
()
.
SetHead
(
block
)
return
nil
,
nil
}
func
(
self
*
DebugApi
)
ProcessBlock
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
args
:=
new
(
BlockNumArg
)
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
nil
,
shared
.
NewDecodeParamError
(
err
.
Error
())
}
block
:=
self
.
xeth
.
EthBlockByNumber
(
args
.
BlockNumber
)
if
block
==
nil
{
return
nil
,
fmt
.
Errorf
(
"block #%d not found"
,
args
.
BlockNumber
)
}
old
:=
vm
.
Debug
defer
func
()
{
vm
.
Debug
=
old
}()
vm
.
Debug
=
true
_
,
err
:=
self
.
ethereum
.
BlockProcessor
()
.
RetryProcess
(
block
)
if
err
==
nil
{
return
true
,
nil
}
return
false
,
err
}
func
(
self
*
DebugApi
)
SeedHash
(
req
*
shared
.
Request
)
(
interface
{},
error
)
{
args
:=
new
(
BlockNumArg
)
if
err
:=
self
.
codec
.
Decode
(
req
.
Params
,
&
args
);
err
!=
nil
{
return
nil
,
shared
.
NewDecodeParamError
(
err
.
Error
())
}
if
hash
,
err
:=
ethash
.
GetSeedHash
(
uint64
(
args
.
BlockNumber
));
err
==
nil
{
return
fmt
.
Sprintf
(
"0x%x"
,
hash
),
nil
}
else
{
return
nil
,
err
}
}
rpc/api/debug_args.go
0 → 100644
View file @
09d0d55f
package
api
import
(
"encoding/json"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/rpc/shared"
)
type
WaitForBlockArgs
struct
{
MinHeight
int
Timeout
int
// in seconds
}
func
(
args
*
WaitForBlockArgs
)
UnmarshalJSON
(
b
[]
byte
)
(
err
error
)
{
var
obj
[]
interface
{}
if
err
:=
json
.
Unmarshal
(
b
,
&
obj
);
err
!=
nil
{
return
shared
.
NewDecodeParamError
(
err
.
Error
())
}
if
len
(
obj
)
>
2
{
return
fmt
.
Errorf
(
"waitForArgs needs 0, 1, 2 arguments"
)
}
// default values when not provided
args
.
MinHeight
=
-
1
args
.
Timeout
=
-
1
if
len
(
obj
)
>=
1
{
var
minHeight
*
big
.
Int
if
minHeight
,
err
=
numString
(
obj
[
0
]);
err
!=
nil
{
return
err
}
args
.
MinHeight
=
int
(
minHeight
.
Int64
())
}
if
len
(
obj
)
>=
2
{
timeout
,
err
:=
numString
(
obj
[
1
])
if
err
!=
nil
{
return
err
}
args
.
Timeout
=
int
(
timeout
.
Int64
())
}
return
nil
}
rpc/api/debug_js.go
0 → 100644
View file @
09d0d55f
package
api
const
Debug_JS
=
`
web3.extend({
property: 'debug',
methods:
[
new web3.extend.Method({
name: 'printBlock',
call: 'debug_printBlock',
params: 1,
inputFormatter: [web3.extend.formatters.formatInputInt],
outputFormatter: web3.extend.formatters.formatOutputString
}),
new web3.extend.Method({
name: 'getBlockRlp',
call: 'debug_getBlockRlp',
params: 1,
inputFormatter: [web3.extend.formatters.formatInputInt],
outputFormatter: web3.extend.formatters.formatOutputString
}),
new web3.extend.Method({
name: 'setHead',
call: 'debug_setHead',
params: 1,
inputFormatter: [web3.extend.formatters.formatInputInt],
outputFormatter: web3.extend.formatters.formatOutputBool
}),
new web3.extend.Method({
name: 'processBlock',
call: 'debug_processBlock',
params: 1,
inputFormatter: [web3.extend.formatters.formatInputInt],
outputFormatter: function(obj) { return obj; }
}),
new web3.extend.Method({
name: 'seedHash',
call: 'debug_seedHash',
params: 1,
inputFormatter: [web3.extend.formatters.formatInputInt],
outputFormatter: web3.extend.formatters.formatOutputString
})
],
properties:
[
]
});
`
rpc/api/utils.go
View file @
09d0d55f
...
...
@@ -21,6 +21,8 @@ func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, eth *eth.
for
i
,
name
:=
range
names
{
switch
strings
.
ToLower
(
strings
.
TrimSpace
(
name
))
{
case
DebugApiName
:
apis
[
i
]
=
NewDebugApi
(
xeth
,
eth
,
codec
)
case
EthApiName
:
apis
[
i
]
=
NewEthApi
(
xeth
,
codec
)
case
MinerApiName
:
...
...
@@ -39,6 +41,8 @@ func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, eth *eth.
func
Javascript
(
name
string
)
string
{
switch
strings
.
ToLower
(
strings
.
TrimSpace
(
name
))
{
case
DebugApiName
:
return
Debug_JS
case
MinerApiName
:
return
Miner_JS
case
NetApiName
:
...
...
rpc/comms/ipc_unix.go
View file @
09d0d55f
...
...
@@ -3,9 +3,9 @@
package
comms
import
(
"io"
"io"
"net"
"os"
"os"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
...
...
@@ -70,8 +70,8 @@ func startIpc(cfg IpcConfig, codec codec.Codec, api api.EthereumApi) error {
os
.
Remove
(
cfg
.
Endpoint
)
}()
glog
.
V
(
logger
.
Info
)
.
Infof
(
"IPC service started (%s)
\n
"
,
cfg
.
Endpoint
)
glog
.
V
(
logger
.
Info
)
.
Infof
(
"IPC service started (%s)
\n
"
,
cfg
.
Endpoint
)
return
nil
}
rpc/comms/ipc_windows.go
View file @
09d0d55f
This diff is collapsed.
Click to expand it.
rpc/jeth.go
View file @
09d0d55f
...
...
@@ -4,12 +4,13 @@ import (
"encoding/json"
"fmt"
"reflect"
"github.com/ethereum/go-ethereum/jsre"
"github.com/robertkrimen/otto"
"github.com/ethereum/go-ethereum/rpc/comms"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/comms"
"github.com/ethereum/go-ethereum/rpc/shared"
"
reflect
"
"
github.com/robertkrimen/otto
"
)
type
Jeth
struct
{
...
...
rpc/shared/types.go
View file @
09d0d55f
...
...
@@ -2,6 +2,7 @@ package shared
import
(
"encoding/json"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
)
...
...
@@ -45,15 +46,15 @@ func NewRpcResponse(id interface{}, jsonrpcver string, reply interface{}, err er
var
response
interface
{}
switch
err
.
(
type
)
{
case
nil
:
case
nil
:
response
=
&
SuccessResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
id
,
Result
:
reply
}
case
*
NotImplementedError
:
case
*
NotImplementedError
:
jsonerr
:=
&
ErrorObject
{
-
32601
,
err
.
Error
()}
response
=
&
ErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
id
,
Error
:
jsonerr
}
case
*
DecodeParamError
,
*
InsufficientParamsError
,
*
ValidationError
,
*
InvalidTypeError
:
case
*
DecodeParamError
,
*
InsufficientParamsError
,
*
ValidationError
,
*
InvalidTypeError
:
jsonerr
:=
&
ErrorObject
{
-
32602
,
err
.
Error
()}
response
=
&
ErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
id
,
Error
:
jsonerr
}
default
:
default
:
jsonerr
:=
&
ErrorObject
{
-
32603
,
err
.
Error
()}
response
=
&
ErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
id
,
Error
:
jsonerr
}
}
...
...
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