mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 12:46:44 +00:00
cleanup: restore dbcmd.go and rawdb files, remove tablewriter dependency
This commit is contained in:
parent
b863a94dce
commit
9dcea9de65
4 changed files with 20 additions and 41 deletions
|
|
@ -41,6 +41,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
"github.com/ethereum/go-ethereum/triedb"
|
"github.com/ethereum/go-ethereum/triedb"
|
||||||
|
"github.com/olekukonko/tablewriter"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -759,17 +760,11 @@ func showMetaData(ctx *cli.Context) error {
|
||||||
data = append(data, []string{"headHeader.Root", fmt.Sprintf("%v", h.Root)})
|
data = append(data, []string{"headHeader.Root", fmt.Sprintf("%v", h.Root)})
|
||||||
data = append(data, []string{"headHeader.Number", fmt.Sprintf("%d (%#x)", h.Number, h.Number)})
|
data = append(data, []string{"headHeader.Number", fmt.Sprintf("%d (%#x)", h.Number, h.Number)})
|
||||||
}
|
}
|
||||||
table.SetHeader([]string{"Key", "Value"})
|
table := tablewriter.NewWriter(os.Stdout)
|
||||||
|
table.SetHeader([]string{"Field", "Value"})
|
||||||
for key, value := range stats {
|
table.AppendBulk(data)
|
||||||
table.Append([]string{key, fmt.Sprintf("%v", value)})
|
table.Render()
|
||||||
}
|
return nil
|
||||||
|
|
||||||
fmt.Println("Key\tValue")
|
|
||||||
for key, value := range stats {
|
|
||||||
fmt.Printf("%s\t%v\n", key, value)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func inspectAccount(db *triedb.Database, start uint64, end uint64, address common.Address, raw bool) error {
|
func inspectAccount(db *triedb.Database, start uint64, end uint64, address common.Address, raw bool) error {
|
||||||
|
|
|
||||||
|
|
@ -650,21 +650,11 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error {
|
||||||
total.Add(uint64(ancient.size()))
|
total.Add(uint64(ancient.size()))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print header
|
table := newTableWriter(os.Stdout)
|
||||||
fmt.Println("Database\tCategory\tSize\tItems")
|
table.SetHeader([]string{"Database", "Category", "Size", "Items"})
|
||||||
|
table.SetFooter([]string{"", "Total", common.StorageSize(total.Load()).String(), fmt.Sprintf("%d", count.Load())})
|
||||||
// Print table rows (stats is [][]string)
|
table.AppendBulk(stats)
|
||||||
for _, row := range stats {
|
table.Render()
|
||||||
if len(row) == 4 {
|
|
||||||
fmt.Printf("%s\t%s\t%s\t%s\n", row[0], row[1], row[2], row[3])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Print footer summary
|
|
||||||
fmt.Printf("\nTotal\t\t%s\t%d\n",
|
|
||||||
common.StorageSize(total.Load()).String(),
|
|
||||||
count.Load(),
|
|
||||||
)
|
|
||||||
|
|
||||||
if !unaccounted.empty() {
|
if !unaccounted.empty() {
|
||||||
log.Error("Database contains unaccounted data", "size", unaccounted.sizeString(), "count", unaccounted.countString())
|
log.Error("Database contains unaccounted data", "size", unaccounted.sizeString(), "count", unaccounted.countString())
|
||||||
|
|
|
||||||
|
|
@ -206,11 +206,3 @@ func (t *Table) printRow(row []string, widths []int) {
|
||||||
}
|
}
|
||||||
fmt.Fprintln(t.out)
|
fmt.Fprintln(t.out)
|
||||||
}
|
}
|
||||||
package rawdb
|
|
||||||
|
|
||||||
import "io"
|
|
||||||
|
|
||||||
// TinyGo doesn't support table formatting; use minimal placeholder.
|
|
||||||
type Table struct{}
|
|
||||||
|
|
||||||
func NewTableWriter(w io.Writer) *Table { return &Table{} }
|
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,15 @@
|
||||||
|
|
||||||
package rawdb
|
package rawdb
|
||||||
|
|
||||||
import "io"
|
import (
|
||||||
|
"io"
|
||||||
|
|
||||||
// Table is a placeholder struct for manual table rendering.
|
"github.com/olekukonko/tablewriter"
|
||||||
type Table struct {
|
)
|
||||||
w io.Writer
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewTableWriter(w io.Writer) *Table {
|
// Re-export the real tablewriter types and functions
|
||||||
return &Table{w: w}
|
type Table = tablewriter.Table
|
||||||
|
|
||||||
|
func newTableWriter(w io.Writer) *Table {
|
||||||
|
return tablewriter.NewWriter(w)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue