mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
add debug.getLevelDbKey
This commit is contained in:
parent
dcdd57df62
commit
025acb40ad
2 changed files with 27 additions and 0 deletions
|
|
@ -1395,6 +1395,28 @@ func (api *PublicDebugAPI) GetBlockRlp(ctx context.Context, number uint64) (stri
|
||||||
return fmt.Sprintf("%x", encoded), nil
|
return fmt.Sprintf("%x", encoded), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetLevelDbKey retrieves the value of a key from levelDB backend
|
||||||
|
func (api *PublicDebugAPI) GetLevelDbKey(ctx context.Context, input string) (string, error) {
|
||||||
|
ldb, ok := api.b.ChainDb().(interface {
|
||||||
|
LDB() *leveldb.DB
|
||||||
|
})
|
||||||
|
if !ok {
|
||||||
|
return "", fmt.Errorf("db not found!")
|
||||||
|
}
|
||||||
|
|
||||||
|
bb, err := hexutil.Decode(input)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("incorrect input, expected string representation of hex")
|
||||||
|
}
|
||||||
|
|
||||||
|
value, err := ldb.LDB().Get(bb, nil)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error getting value from levelDB %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("%x", value), nil
|
||||||
|
}
|
||||||
|
|
||||||
// PrintBlock retrieves a block and returns its pretty printed form.
|
// PrintBlock retrieves a block and returns its pretty printed form.
|
||||||
func (api *PublicDebugAPI) PrintBlock(ctx context.Context, number uint64) (string, error) {
|
func (api *PublicDebugAPI) PrintBlock(ctx context.Context, number uint64) (string, error) {
|
||||||
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number))
|
block, _ := api.b.BlockByNumber(ctx, rpc.BlockNumber(number))
|
||||||
|
|
|
||||||
|
|
@ -191,6 +191,11 @@ web3._extend({
|
||||||
call: 'debug_getBlockRlp',
|
call: 'debug_getBlockRlp',
|
||||||
params: 1
|
params: 1
|
||||||
}),
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'getLevelDbKey',
|
||||||
|
call: 'debug_getLevelDbKey',
|
||||||
|
params: 1
|
||||||
|
}),
|
||||||
new web3._extend.Method({
|
new web3._extend.Method({
|
||||||
name: 'setHead',
|
name: 'setHead',
|
||||||
call: 'debug_setHead',
|
call: 'debug_setHead',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue