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
16701c51
Unverified
Commit
16701c51
authored
Apr 27, 2022
by
Sina Mahmoodi
Committed by
GitHub
Apr 27, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
internal/ethapi: add db operations to api (#24739)
Adds `debug_dbGet` method to rpc api
parent
a52bcccf
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
13 deletions
+29
-13
dbcmd.go
cmd/geth/dbcmd.go
+3
-13
bytes.go
common/bytes.go
+12
-0
api.go
internal/ethapi/api.go
+9
-0
web3ext.go
internal/web3ext/web3ext.go
+5
-0
No files found.
cmd/geth/dbcmd.go
View file @
16701c51
...
...
@@ -18,7 +18,6 @@ package main
import
(
"bytes"
"errors"
"fmt"
"os"
"os/signal"
...
...
@@ -418,7 +417,7 @@ func dbGet(ctx *cli.Context) error {
db
:=
utils
.
MakeChainDatabase
(
ctx
,
stack
,
true
)
defer
db
.
Close
()
key
,
err
:=
p
arseHexOrString
(
ctx
.
Args
()
.
Get
(
0
))
key
,
err
:=
common
.
P
arseHexOrString
(
ctx
.
Args
()
.
Get
(
0
))
if
err
!=
nil
{
log
.
Info
(
"Could not decode the key"
,
"error"
,
err
)
return
err
...
...
@@ -444,7 +443,7 @@ func dbDelete(ctx *cli.Context) error {
db
:=
utils
.
MakeChainDatabase
(
ctx
,
stack
,
false
)
defer
db
.
Close
()
key
,
err
:=
p
arseHexOrString
(
ctx
.
Args
()
.
Get
(
0
))
key
,
err
:=
common
.
P
arseHexOrString
(
ctx
.
Args
()
.
Get
(
0
))
if
err
!=
nil
{
log
.
Info
(
"Could not decode the key"
,
"error"
,
err
)
return
err
...
...
@@ -477,7 +476,7 @@ func dbPut(ctx *cli.Context) error {
data
[]
byte
err
error
)
key
,
err
=
p
arseHexOrString
(
ctx
.
Args
()
.
Get
(
0
))
key
,
err
=
common
.
P
arseHexOrString
(
ctx
.
Args
()
.
Get
(
0
))
if
err
!=
nil
{
log
.
Info
(
"Could not decode the key"
,
"error"
,
err
)
return
err
...
...
@@ -584,15 +583,6 @@ func freezerInspect(ctx *cli.Context) error {
return
nil
}
// ParseHexOrString tries to hexdecode b, but if the prefix is missing, it instead just returns the raw bytes
func
parseHexOrString
(
str
string
)
([]
byte
,
error
)
{
b
,
err
:=
hexutil
.
Decode
(
str
)
if
errors
.
Is
(
err
,
hexutil
.
ErrMissingPrefix
)
{
return
[]
byte
(
str
),
nil
}
return
b
,
err
}
func
importLDBdata
(
ctx
*
cli
.
Context
)
error
{
start
:=
0
switch
ctx
.
NArg
()
{
...
...
common/bytes.go
View file @
16701c51
...
...
@@ -19,6 +19,9 @@ package common
import
(
"encoding/hex"
"errors"
"github.com/ethereum/go-ethereum/common/hexutil"
)
// FromHex returns the bytes represented by the hexadecimal string s.
...
...
@@ -92,6 +95,15 @@ func Hex2BytesFixed(str string, flen int) []byte {
return
hh
}
// ParseHexOrString tries to hexdecode b, but if the prefix is missing, it instead just returns the raw bytes
func
ParseHexOrString
(
str
string
)
([]
byte
,
error
)
{
b
,
err
:=
hexutil
.
Decode
(
str
)
if
errors
.
Is
(
err
,
hexutil
.
ErrMissingPrefix
)
{
return
[]
byte
(
str
),
nil
}
return
b
,
err
}
// RightPadBytes zero-pads slice to the right up to length l.
func
RightPadBytes
(
slice
[]
byte
,
l
int
)
[]
byte
{
if
l
<=
len
(
slice
)
{
...
...
internal/ethapi/api.go
View file @
16701c51
...
...
@@ -1972,6 +1972,15 @@ func (api *PrivateDebugAPI) SetHead(number hexutil.Uint64) {
api
.
b
.
SetHead
(
uint64
(
number
))
}
// DbGet returns the raw value of a key stored in the database.
func
(
api
*
PrivateDebugAPI
)
DbGet
(
key
string
)
(
hexutil
.
Bytes
,
error
)
{
blob
,
err
:=
common
.
ParseHexOrString
(
key
)
if
err
!=
nil
{
return
nil
,
err
}
return
api
.
b
.
ChainDb
()
.
Get
(
blob
)
}
// PublicNetAPI offers network related RPC methods
type
PublicNetAPI
struct
{
net
*
p2p
.
Server
...
...
internal/web3ext/web3ext.go
View file @
16701c51
...
...
@@ -471,6 +471,11 @@ web3._extend({
params: 2,
inputFormatter:[web3._extend.formatters.inputBlockNumberFormatter, web3._extend.formatters.inputBlockNumberFormatter],
}),
new web3._extend.Method({
name: 'dbGet',
call: 'debug_dbGet',
params: 1
}),
],
properties: []
});
...
...
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