Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/geth: support string (non-hex) keys in db get/put/delete #23744

Merged
merged 6 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add a utf8 flag in geth db get command
It is suppose to be convinient when observing internal state,
via constant keys like `SnapshotSyncStatus`, `SnapshotRecovery` etc.

Otherwise it's necessary to convert these strings to hex which might be inconvinient.

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
  • Loading branch information
zhiburt committed Oct 15, 2021
commit c48e22fc721fae827ac517d3f16b56d22dd47c4c
17 changes: 13 additions & 4 deletions cmd/geth/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ corruption if it is aborted during execution'!`,
utils.RopstenFlag,
utils.RinkebyFlag,
utils.GoerliFlag,
utils.UTF8Fag,
},
Description: "This command looks up the specified database key from the database.",
}
Expand Down Expand Up @@ -335,11 +336,19 @@ func dbGet(ctx *cli.Context) error {
db := utils.MakeChainDatabase(ctx, stack, true)
defer db.Close()

key, err := hexutil.Decode(ctx.Args().Get(0))
if err != nil {
log.Info("Could not decode the key", "error", err)
return err
var key []byte
if ctx.Bool(utils.UTF8Fag.Name) {
log.Info("Consider the key to be a UTF8 string")
key = []byte(ctx.Args().Get(0))
} else {
k, err := hexutil.Decode(ctx.Args().Get(0))
if err != nil {
log.Info("Could not decode the key", "error", err)
return err
}
key = k
}

data, err := db.Get(key)
if err != nil {
log.Info("Get operation failed", "error", err)
Expand Down
5 changes: 5 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,11 @@ var (
Name: "catalyst",
Usage: "Catalyst mode (eth2 integration testing)",
}

UTF8Fag = cli.BoolFlag{
Name: "utf8",
Usage: "Consider parameters to be in UTF8 rather then a hex string started from 0x",
}
)

// MakeDataDir retrieves the currently requested data directory, terminating
Expand Down