mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
ethapi: Move PrivateDebugAPI into a separate file excluded from WASM compilation to enable importing signer/core in WASM projects
This commit is contained in:
parent
d5af3a584c
commit
6d8ecdbbf2
2 changed files with 63 additions and 46 deletions
|
|
@ -22,7 +22,6 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
|
@ -44,7 +43,6 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/ethereum/go-ethereum/rpc"
|
"github.com/ethereum/go-ethereum/rpc"
|
||||||
"github.com/syndtr/goleveldb/leveldb"
|
|
||||||
"github.com/tyler-smith/go-bip39"
|
"github.com/tyler-smith/go-bip39"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -1585,50 +1583,6 @@ func (api *PublicDebugAPI) SeedHash(ctx context.Context, number uint64) (string,
|
||||||
return fmt.Sprintf("0x%x", ethash.SeedHash(number)), nil
|
return fmt.Sprintf("0x%x", ethash.SeedHash(number)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrivateDebugAPI is the collection of Ethereum APIs exposed over the private
|
|
||||||
// debugging endpoint.
|
|
||||||
type PrivateDebugAPI struct {
|
|
||||||
b Backend
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewPrivateDebugAPI creates a new API definition for the private debug methods
|
|
||||||
// of the Ethereum service.
|
|
||||||
func NewPrivateDebugAPI(b Backend) *PrivateDebugAPI {
|
|
||||||
return &PrivateDebugAPI{b: b}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ChaindbProperty returns leveldb properties of the chain database.
|
|
||||||
func (api *PrivateDebugAPI) ChaindbProperty(property string) (string, error) {
|
|
||||||
ldb, ok := api.b.ChainDb().(interface {
|
|
||||||
LDB() *leveldb.DB
|
|
||||||
})
|
|
||||||
if !ok {
|
|
||||||
return "", fmt.Errorf("chaindbProperty does not work for memory databases")
|
|
||||||
}
|
|
||||||
if property == "" {
|
|
||||||
property = "leveldb.stats"
|
|
||||||
} else if !strings.HasPrefix(property, "leveldb.") {
|
|
||||||
property = "leveldb." + property
|
|
||||||
}
|
|
||||||
return ldb.LDB().GetProperty(property)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (api *PrivateDebugAPI) ChaindbCompact() error {
|
|
||||||
for b := byte(0); b < 255; b++ {
|
|
||||||
log.Info("Compacting chain database", "range", fmt.Sprintf("0x%0.2X-0x%0.2X", b, b+1))
|
|
||||||
if err := api.b.ChainDb().Compact([]byte{b}, []byte{b + 1}); err != nil {
|
|
||||||
log.Error("Database compaction failed", "err", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetHead rewinds the head of the blockchain to a previous block.
|
|
||||||
func (api *PrivateDebugAPI) SetHead(number hexutil.Uint64) {
|
|
||||||
api.b.SetHead(uint64(number))
|
|
||||||
}
|
|
||||||
|
|
||||||
// PublicNetAPI offers network related RPC methods
|
// PublicNetAPI offers network related RPC methods
|
||||||
type PublicNetAPI struct {
|
type PublicNetAPI struct {
|
||||||
net *p2p.Server
|
net *p2p.Server
|
||||||
|
|
|
||||||
63
internal/ethapi/private_debug_api.go
Normal file
63
internal/ethapi/private_debug_api.go
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
// +build !js
|
||||||
|
package ethapi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
"github.com/syndtr/goleveldb/leveldb"
|
||||||
|
"github.com/syndtr/goleveldb/leveldb/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PrivateDebugAPI is the collection of Ethereum APIs exposed over the private
|
||||||
|
// debugging endpoint.
|
||||||
|
type PrivateDebugAPI struct {
|
||||||
|
b Backend
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPrivateDebugAPI creates a new API definition for the private debug methods
|
||||||
|
// of the Ethereum service.
|
||||||
|
func NewPrivateDebugAPI(b Backend) *PrivateDebugAPI {
|
||||||
|
return &PrivateDebugAPI{b: b}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ChaindbProperty returns leveldb properties of the chain database.
|
||||||
|
func (api *PrivateDebugAPI) ChaindbProperty(property string) (string, error) {
|
||||||
|
ldb, ok := api.b.ChainDb().(interface {
|
||||||
|
LDB() *leveldb.DB
|
||||||
|
})
|
||||||
|
if !ok {
|
||||||
|
return "", fmt.Errorf("chaindbProperty does not work for memory databases")
|
||||||
|
}
|
||||||
|
if property == "" {
|
||||||
|
property = "leveldb.stats"
|
||||||
|
} else if !strings.HasPrefix(property, "leveldb.") {
|
||||||
|
property = "leveldb." + property
|
||||||
|
}
|
||||||
|
return ldb.LDB().GetProperty(property)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (api *PrivateDebugAPI) ChaindbCompact() error {
|
||||||
|
ldb, ok := api.b.ChainDb().(interface {
|
||||||
|
LDB() *leveldb.DB
|
||||||
|
})
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("chaindbCompact does not work for memory databases")
|
||||||
|
}
|
||||||
|
for b := byte(0); b < 255; b++ {
|
||||||
|
log.Info("Compacting chain database", "range", fmt.Sprintf("0x%0.2X-0x%0.2X", b, b+1))
|
||||||
|
err := ldb.LDB().CompactRange(util.Range{Start: []byte{b}, Limit: []byte{b + 1}})
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Database compaction failed", "err", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetHead rewinds the head of the blockchain to a previous block.
|
||||||
|
func (api *PrivateDebugAPI) SetHead(number hexutil.Uint64) {
|
||||||
|
api.b.SetHead(uint64(number))
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue