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/clef: list accounts at startup #26082

Merged
merged 11 commits into from
Nov 7, 2022
3 changes: 0 additions & 3 deletions cmd/clef/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@ func signer(c *cli.Context) error {

// Establish the bidirectional communication, by creating a new UI backend and registering
// it with the UI.

ui.RegisterUIServer(core.NewUIServerAPI(apiImpl))
api = apiImpl

Expand Down Expand Up @@ -701,12 +700,10 @@ func signer(c *cli.Context) error {
log.Info("IPC endpoint closed", "url", ipcapiURL)
}()
}

if c.Bool(testFlag.Name) {
log.Info("Performing UI test")
go testExternalUI(apiImpl)
}

ui.OnSignerStartup(core.StartupInfo{
Info: map[string]interface{}{
"intapi_version": core.InternalAPIVersion,
Expand Down
21 changes: 13 additions & 8 deletions signer/core/cliui.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,25 +243,30 @@ func (ui *CommandlineUI) OnApprovedTx(tx ethapi.SignTransactionResult) {
}
}

func (ui *CommandlineUI) OnSignerStartup(info StartupInfo) {
func (ui *CommandlineUI) ShowAccounts() string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Myeah, sure, that's one way of doing it. If you do this, then you should make it lowercase - so it's a non-public method showAccounts.

But the primary thing I wanted was to make it async. So instead of just calling

	addresses := ui.ShowAccounts()
	fmt.Print("Accounts known to Clef:\n\n")
	fmt.Printf("%s", addresses)

You would do

	go fun(){
		addresses := ui.ShowAccounts()
		fmt.Print("Accounts known to Clef:\n\n")
		fmt.Printf("%s", addresses)
	}()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, yes ok: c1dbc02

accounts, err := ui.api.ListAccounts(context.Background())
if err != nil {
fmt.Print("error listing accounts", err)
}
var resp string
if len(accounts) == 0 {
fmt.Println("No accounts known to Clef")
resp = "No accounts known to Clef"
} else {
// account info to string for nicer printing
var addresses string = "\n"
fmt.Println("Accounts known to Clef:")
var addresses string = ""
for i, account := range accounts {
// concat string to avoid repeating "INFO" on terminal
addresses += fmt.Sprintf("Account %v: %s at %s", i, account.Address, account.URL)
addresses += "\n"
addresses += fmt.Sprintf("Account %v: %s at %s\n", i, account.Address, account.URL)
}
fmt.Print(addresses)
fmt.Println()
resp = addresses
}
return resp
}

func (ui *CommandlineUI) OnSignerStartup(info StartupInfo) {
addresses := ui.ShowAccounts()
fmt.Print("Accounts known to Clef:\n\n")
fmt.Printf("%s", addresses)
fmt.Printf("------- Signer info -------\n")
for k, v := range info.Info {
fmt.Printf("* %v : %v\n", k, v)
Expand Down