cmd/geth: fix stack trace when admin is missing

This commit is contained in:
Guillaume Ballet 2020-01-07 22:13:47 +01:00
parent fc082e6edf
commit 71b70f2eea
2 changed files with 11 additions and 9 deletions

View file

@ -139,7 +139,9 @@ func testAttachWelcome(t *testing.T, geth *testgeth, endpoint, apis string) {
attach.SetTemplateFunc("gover", runtime.Version)
attach.SetTemplateFunc("gethver", func() string { return params.VersionWithCommit("", "") })
attach.SetTemplateFunc("etherbase", func() string { return geth.Etherbase })
attach.SetTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) })
attach.SetTemplateFunc("niltime", func() string {
return time.Unix(0, 0).Format("Mon Jan 02 2006 15:04:05 GMT-0700 (MST)")
})
attach.SetTemplateFunc("ipc", func() bool { return strings.HasPrefix(endpoint, "ipc") })
attach.SetTemplateFunc("datadir", func() string { return geth.Datadir })
attach.SetTemplateFunc("apis", func() string { return apis })

View file

@ -206,14 +206,14 @@ func (c *Console) init(preload []string) error {
}
}
// The admin.sleep and admin.sleepBlocks are offered by the console and not by the RPC layer.
admin := c.jsre.Get("admin")
if admin == nil {
return fmt.Errorf("could not find admin")
}
if obj := admin.ToObject(c.runtime); obj != nil { // make sure the admin api is enabled over the interface
obj.Set("sleepBlocks", bridge.SleepBlocks)
obj.Set("sleep", bridge.Sleep)
obj.Set("clearHistory", c.clearHistory)
admin := c.jsre.Get("admin") // Could be `nil`
if admin != nil {
// make sure the admin api is enabled over the interface
if obj := admin.ToObject(c.runtime); obj != nil {
obj.Set("sleepBlocks", bridge.SleepBlocks)
obj.Set("sleep", bridge.Sleep)
obj.Set("clearHistory", c.clearHistory)
}
}
// Preload any JavaScript files before starting the console
for _, path := range preload {