mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 21:26:42 +00:00
feat: add debug_db* methods (#1177)
This commit is contained in:
parent
eaf06e30a0
commit
a4109fd8a9
4 changed files with 71 additions and 1 deletions
|
|
@ -19,6 +19,9 @@ package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/scroll-tech/go-ethereum/common/hexutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FromHex returns the bytes represented by the hexadecimal string s.
|
// FromHex returns the bytes represented by the hexadecimal string s.
|
||||||
|
|
@ -92,6 +95,15 @@ func Hex2BytesFixed(str string, flen int) []byte {
|
||||||
return hh
|
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.
|
// RightPadBytes zero-pads slice to the right up to length l.
|
||||||
func RightPadBytes(slice []byte, l int) []byte {
|
func RightPadBytes(slice []byte, l int) []byte {
|
||||||
if l <= len(slice) {
|
if l <= len(slice) {
|
||||||
|
|
|
||||||
43
internal/ethapi/dbapi.go
Normal file
43
internal/ethapi/dbapi.go
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
// Copyright 2022 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library 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 Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package ethapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/scroll-tech/go-ethereum/common"
|
||||||
|
"github.com/scroll-tech/go-ethereum/common/hexutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
// DbGet returns the raw value of a key stored in the database.
|
||||||
|
func (api *PublicDebugAPI) DbGet(key string) (hexutil.Bytes, error) {
|
||||||
|
blob, err := common.ParseHexOrString(key)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return api.b.ChainDb().Get(blob)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DbAncient retrieves an ancient binary blob from the append-only immutable files.
|
||||||
|
// It is a mapping to the `AncientReaderOp.Ancient` method
|
||||||
|
func (api *PublicDebugAPI) DbAncient(kind string, number uint64) (hexutil.Bytes, error) {
|
||||||
|
return api.b.ChainDb().Ancient(kind, number)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DbAncients returns the ancient item numbers in the ancient store.
|
||||||
|
// It is a mapping to the `AncientReaderOp.Ancients` method
|
||||||
|
func (api *PublicDebugAPI) DbAncients() (uint64, error) {
|
||||||
|
return api.b.ChainDb().Ancients()
|
||||||
|
}
|
||||||
|
|
@ -482,6 +482,21 @@ web3._extend({
|
||||||
params: 2,
|
params: 2,
|
||||||
inputFormatter:[web3._extend.formatters.inputBlockNumberFormatter, web3._extend.formatters.inputBlockNumberFormatter],
|
inputFormatter:[web3._extend.formatters.inputBlockNumberFormatter, web3._extend.formatters.inputBlockNumberFormatter],
|
||||||
}),
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'dbGet',
|
||||||
|
call: 'debug_dbGet',
|
||||||
|
params: 1
|
||||||
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'dbAncient',
|
||||||
|
call: 'debug_dbAncient',
|
||||||
|
params: 2
|
||||||
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'dbAncients',
|
||||||
|
call: 'debug_dbAncients',
|
||||||
|
params: 0
|
||||||
|
}),
|
||||||
new web3._extend.Method({
|
new web3._extend.Method({
|
||||||
name: 'executionWitness',
|
name: 'executionWitness',
|
||||||
call: 'debug_executionWitness',
|
call: 'debug_executionWitness',
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
const (
|
const (
|
||||||
VersionMajor = 5 // Major version component of the current release
|
VersionMajor = 5 // Major version component of the current release
|
||||||
VersionMinor = 8 // Minor version component of the current release
|
VersionMinor = 8 // Minor version component of the current release
|
||||||
VersionPatch = 40 // Patch version component of the current release
|
VersionPatch = 41 // Patch version component of the current release
|
||||||
VersionMeta = "mainnet" // Version metadata to append to the version string
|
VersionMeta = "mainnet" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue