mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
internal: add db operations to api (#24739)
This commit is contained in:
parent
69ea5327b8
commit
d6d6906881
3 changed files with 26 additions and 0 deletions
|
|
@ -19,6 +19,9 @@ package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
"errors"
|
||||||
|
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/common/hexutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
// FromHex returns the bytes represented by the hexadecimal string s.
|
// FromHex returns the bytes represented by the hexadecimal string s.
|
||||||
|
|
@ -99,6 +102,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) {
|
||||||
|
|
|
||||||
|
|
@ -3499,6 +3499,15 @@ func (api *PrivateDebugAPI) SetHead(number hexutil.Uint64) {
|
||||||
api.b.SetHead(uint64(number))
|
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
|
// PublicNetAPI offers network related RPC methods
|
||||||
type PublicNetAPI struct {
|
type PublicNetAPI struct {
|
||||||
net *p2p.Server
|
net *p2p.Server
|
||||||
|
|
|
||||||
|
|
@ -470,6 +470,11 @@ web3._extend({
|
||||||
params: 2,
|
params: 2,
|
||||||
inputFormatter:[null, null],
|
inputFormatter:[null, null],
|
||||||
}),
|
}),
|
||||||
|
new web3._extend.Method({
|
||||||
|
name: 'dbGet',
|
||||||
|
call: 'debug_dbGet',
|
||||||
|
params: 1
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
properties: []
|
properties: []
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue