|
|
@ -18,6 +18,7 @@ package core |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"bufio" |
|
|
|
"bufio" |
|
|
|
|
|
|
|
"context" |
|
|
|
"encoding/json" |
|
|
|
"encoding/json" |
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"os" |
|
|
|
"os" |
|
|
@ -31,8 +32,9 @@ import ( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type CommandlineUI struct { |
|
|
|
type CommandlineUI struct { |
|
|
|
in *bufio.Reader |
|
|
|
in *bufio.Reader |
|
|
|
mu sync.Mutex |
|
|
|
mu sync.Mutex |
|
|
|
|
|
|
|
api *UIServerAPI |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func NewCommandlineUI() *CommandlineUI { |
|
|
|
func NewCommandlineUI() *CommandlineUI { |
|
|
@ -40,7 +42,7 @@ func NewCommandlineUI() *CommandlineUI { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (ui *CommandlineUI) RegisterUIServer(api *UIServerAPI) { |
|
|
|
func (ui *CommandlineUI) RegisterUIServer(api *UIServerAPI) { |
|
|
|
// noop
|
|
|
|
ui.api = api |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// readString reads a single line from stdin, trimming if from spaces, enforcing
|
|
|
|
// readString reads a single line from stdin, trimming if from spaces, enforcing
|
|
|
@ -241,9 +243,28 @@ func (ui *CommandlineUI) OnApprovedTx(tx ethapi.SignTransactionResult) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (ui *CommandlineUI) showAccounts() { |
|
|
|
|
|
|
|
accounts, err := ui.api.ListAccounts(context.Background()) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Error("Error listing accounts", "err", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if len(accounts) == 0 { |
|
|
|
|
|
|
|
fmt.Print("No accounts found\n") |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var out = new(strings.Builder) |
|
|
|
|
|
|
|
fmt.Fprint(out, "\n------- Available accounts -------\n") |
|
|
|
|
|
|
|
for i, account := range accounts { |
|
|
|
|
|
|
|
fmt.Fprintf(out, "%d. %s at %s\n", i, account.Address, account.URL) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
fmt.Print(out.String()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (ui *CommandlineUI) OnSignerStartup(info StartupInfo) { |
|
|
|
func (ui *CommandlineUI) OnSignerStartup(info StartupInfo) { |
|
|
|
fmt.Printf("------- Signer info -------\n") |
|
|
|
fmt.Print("\n------- Signer info -------\n") |
|
|
|
for k, v := range info.Info { |
|
|
|
for k, v := range info.Info { |
|
|
|
fmt.Printf("* %v : %v\n", k, v) |
|
|
|
fmt.Printf("* %v : %v\n", k, v) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
go ui.showAccounts() |
|
|
|
} |
|
|
|
} |
|
|
|