mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
signer, ethapi: implement relay
This commit is contained in:
parent
f0146f25d8
commit
365c9016ce
10 changed files with 48 additions and 44 deletions
|
|
@ -1,6 +1,11 @@
|
||||||
### Changelog for external API
|
### Changelog for external API
|
||||||
|
|
||||||
|
|
||||||
|
### 3.0.0
|
||||||
|
|
||||||
|
* The external `accounts_List`-method was changed to not expose `url`, which contained information about the local machine. It now returns a set of addresses: `[]common.Address`.
|
||||||
|
* The method was also renamed into `accounts_listAccounts`.
|
||||||
|
|
||||||
|
|
||||||
#### 2.0.0
|
#### 2.0.0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,9 @@
|
||||||
### Changelog for internal API (ui-api)
|
### Changelog for internal API (ui-api)
|
||||||
|
|
||||||
|
### 3.0.0
|
||||||
|
|
||||||
|
* The external `accounts_List`-method was changed to not expose `url`, which contained information about the local machine. Thus, the internal method `approveListing` was changed correspondingly, to contain only a set of addresses: `[]common.Address`
|
||||||
|
|
||||||
### 2.0.0
|
### 2.0.0
|
||||||
|
|
||||||
* Modify how `call_info` on a transaction is conveyed. New format:
|
* Modify how `call_info` on a transaction is conveyed. New format:
|
||||||
|
|
|
||||||
|
|
@ -225,9 +225,7 @@ func (s *PrivateAccountAPI) ListAccounts() []common.Address {
|
||||||
addresses := make([]common.Address, 0) // return [] instead of nil if empty
|
addresses := make([]common.Address, 0) // return [] instead of nil if empty
|
||||||
if s.extapi != nil {
|
if s.extapi != nil {
|
||||||
if accounts, err := s.extapi.listAccounts(); err == nil {
|
if accounts, err := s.extapi.listAccounts(); err == nil {
|
||||||
for _, account := range accounts {
|
return accounts
|
||||||
addresses = append(addresses, account.Address)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return addresses
|
return addresses
|
||||||
}
|
}
|
||||||
|
|
@ -1553,9 +1551,9 @@ func (api *ExternalSignerAPI) signTransaction(ctx context.Context, args SendTxAr
|
||||||
}
|
}
|
||||||
return res.Tx, nil
|
return res.Tx, nil
|
||||||
}
|
}
|
||||||
func (api *ExternalSignerAPI) listAccounts() ([]accounts.Account, error) {
|
func (api *ExternalSignerAPI) listAccounts() ([]common.Address, error) {
|
||||||
var res []accounts.Account
|
var res []common.Address
|
||||||
if err := api.client.Call(&res, "account_list"); err != nil {
|
if err := api.client.Call(&res, "account_listAccounts"); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
|
|
|
||||||
|
|
@ -38,8 +38,8 @@ import (
|
||||||
|
|
||||||
// ExternalAPI defines the external API through which signing requests are made.
|
// ExternalAPI defines the external API through which signing requests are made.
|
||||||
type ExternalAPI interface {
|
type ExternalAPI interface {
|
||||||
// List available accounts
|
// ListAccounts lists available accounts (addresses)
|
||||||
List(ctx context.Context) (Accounts, error)
|
ListAccounts(ctx context.Context) ([]common.Address, error)
|
||||||
// New request to create a new account
|
// New request to create a new account
|
||||||
New(ctx context.Context) (accounts.Account, error)
|
New(ctx context.Context) (accounts.Account, error)
|
||||||
// SignTransaction request to sign the specified transaction
|
// SignTransaction request to sign the specified transaction
|
||||||
|
|
@ -66,7 +66,7 @@ type SignerUI interface {
|
||||||
ApproveImport(request *ImportRequest) (ImportResponse, error)
|
ApproveImport(request *ImportRequest) (ImportResponse, error)
|
||||||
// ApproveListing prompt the user for confirmation to list accounts
|
// ApproveListing prompt the user for confirmation to list accounts
|
||||||
// the list of accounts to list can be modified by the UI
|
// the list of accounts to list can be modified by the UI
|
||||||
ApproveListing(request *ListRequest) (ListResponse, error)
|
ApproveListing(request *ListAccountsRequest) (ListAccountsResponse, error)
|
||||||
// ApproveNewAccount prompt the user for confirmation to create new Account, and reveal to caller
|
// ApproveNewAccount prompt the user for confirmation to create new Account, and reveal to caller
|
||||||
ApproveNewAccount(request *NewAccountRequest) (NewAccountResponse, error)
|
ApproveNewAccount(request *NewAccountRequest) (NewAccountResponse, error)
|
||||||
// ShowError displays error message to user
|
// ShowError displays error message to user
|
||||||
|
|
@ -172,12 +172,12 @@ type (
|
||||||
Approved bool `json:"approved"`
|
Approved bool `json:"approved"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
}
|
}
|
||||||
ListRequest struct {
|
ListAccountsRequest struct {
|
||||||
Accounts []Account `json:"accounts"`
|
Accounts []common.Address `json:"accounts"`
|
||||||
Meta Metadata `json:"meta"`
|
Meta Metadata `json:"meta"`
|
||||||
}
|
}
|
||||||
ListResponse struct {
|
ListAccountsResponse struct {
|
||||||
Accounts []Account `json:"accounts"`
|
Accounts []common.Address `json:"accounts"`
|
||||||
}
|
}
|
||||||
Message struct {
|
Message struct {
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
|
|
@ -225,17 +225,16 @@ func NewSignerAPI(chainID int64, ksLocation string, noUSB bool, ui SignerUI, abi
|
||||||
return &SignerAPI{big.NewInt(chainID), accounts.NewManager(backends...), ui, NewValidator(abidb)}
|
return &SignerAPI{big.NewInt(chainID), accounts.NewManager(backends...), ui, NewValidator(abidb)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// List returns the set of wallet this signer manages. Each wallet can contain
|
// ListAccounts returns the set of wallet this signer manages. Each wallet can contain
|
||||||
// multiple accounts.
|
// multiple accounts.
|
||||||
func (api *SignerAPI) List(ctx context.Context) (Accounts, error) {
|
func (api *SignerAPI) ListAccounts(ctx context.Context) ([]common.Address, error) {
|
||||||
var accs []Account
|
addresses := make([]common.Address, 0) // return [] instead of nil if empty
|
||||||
for _, wallet := range api.am.Wallets() {
|
for _, wallet := range api.am.Wallets() {
|
||||||
for _, acc := range wallet.Accounts() {
|
for _, account := range wallet.Accounts() {
|
||||||
acc := Account{Typ: "Account", URL: wallet.URL(), Address: acc.Address}
|
addresses = append(addresses, account.Address)
|
||||||
accs = append(accs, acc)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result, err := api.UI.ApproveListing(&ListRequest{Accounts: accs, Meta: MetadataFromContext(ctx)})
|
result, err := api.UI.ApproveListing(&ListAccountsRequest{Accounts: addresses, Meta: MetadataFromContext(ctx)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,17 +80,17 @@ func (ui *HeadlessUI) ApproveImport(request *ImportRequest) (ImportResponse, err
|
||||||
}
|
}
|
||||||
return ImportResponse{false, "", ""}, nil
|
return ImportResponse{false, "", ""}, nil
|
||||||
}
|
}
|
||||||
func (ui *HeadlessUI) ApproveListing(request *ListRequest) (ListResponse, error) {
|
func (ui *HeadlessUI) ApproveListing(request *ListRequest) (ListAccountsResponse, error) {
|
||||||
|
|
||||||
switch <-ui.controller {
|
switch <-ui.controller {
|
||||||
case "A":
|
case "A":
|
||||||
return ListResponse{request.Accounts}, nil
|
return ListAccountsResponse{request.Accounts}, nil
|
||||||
case "1":
|
case "1":
|
||||||
l := make([]Account, 1)
|
l := make([]Account, 1)
|
||||||
l[0] = request.Accounts[1]
|
l[0] = request.Accounts[1]
|
||||||
return ListResponse{l}, nil
|
return ListAccountsResponse{l}, nil
|
||||||
default:
|
default:
|
||||||
return ListResponse{nil}, nil
|
return ListAccountsResponse{nil}, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func (ui *HeadlessUI) ApproveNewAccount(request *NewAccountRequest) (NewAccountResponse, error) {
|
func (ui *HeadlessUI) ApproveNewAccount(request *NewAccountRequest) (NewAccountResponse, error) {
|
||||||
|
|
|
||||||
|
|
@ -33,12 +33,10 @@ type AuditLogger struct {
|
||||||
api ExternalAPI
|
api ExternalAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *AuditLogger) List(ctx context.Context) (Accounts, error) {
|
func (l *AuditLogger) ListAccounts(ctx context.Context) ([]common.Address, error) {
|
||||||
l.log.Info("List", "type", "request", "metadata", MetadataFromContext(ctx).String())
|
l.log.Info("ListAccounts", "type", "request", "metadata", MetadataFromContext(ctx).String())
|
||||||
res, e := l.api.List(ctx)
|
res, e := l.api.ListAccounts(ctx)
|
||||||
|
l.log.Info("ListAccounts", "type", "response", "data", res)
|
||||||
l.log.Info("List", "type", "response", "data", res.String())
|
|
||||||
|
|
||||||
return res, e
|
return res, e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -190,7 +190,7 @@ func (ui *CommandlineUI) ApproveImport(request *ImportRequest) (ImportResponse,
|
||||||
|
|
||||||
// ApproveListing prompt the user for confirmation to list accounts
|
// ApproveListing prompt the user for confirmation to list accounts
|
||||||
// the list of accounts to list can be modified by the UI
|
// the list of accounts to list can be modified by the UI
|
||||||
func (ui *CommandlineUI) ApproveListing(request *ListRequest) (ListResponse, error) {
|
func (ui *CommandlineUI) ApproveListing(request *ListRequest) (ListAccountsResponse, error) {
|
||||||
|
|
||||||
ui.mu.Lock()
|
ui.mu.Lock()
|
||||||
defer ui.mu.Unlock()
|
defer ui.mu.Unlock()
|
||||||
|
|
@ -204,9 +204,9 @@ func (ui *CommandlineUI) ApproveListing(request *ListRequest) (ListResponse, err
|
||||||
fmt.Printf("-------------------------------------------\n")
|
fmt.Printf("-------------------------------------------\n")
|
||||||
showMetadata(request.Meta)
|
showMetadata(request.Meta)
|
||||||
if !ui.confirm() {
|
if !ui.confirm() {
|
||||||
return ListResponse{nil}, nil
|
return ListAccountsResponse{nil}, nil
|
||||||
}
|
}
|
||||||
return ListResponse{request.Accounts}, nil
|
return ListAccountsResponse{request.Accounts}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApproveNewAccount prompt the user for confirmation to create new Account, and reveal to caller
|
// ApproveNewAccount prompt the user for confirmation to create new Account, and reveal to caller
|
||||||
|
|
|
||||||
|
|
@ -73,8 +73,8 @@ func (ui *StdIOUI) ApproveImport(request *ImportRequest) (ImportResponse, error)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ui *StdIOUI) ApproveListing(request *ListRequest) (ListResponse, error) {
|
func (ui *StdIOUI) ApproveListing(request *ListRequest) (ListAccountsResponse, error) {
|
||||||
var result ListResponse
|
var result ListAccountsResponse
|
||||||
err := ui.dispatch("ApproveListing", request, &result)
|
err := ui.dispatch("ApproveListing", request, &result)
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,7 @@ func (r *rulesetUI) ApproveImport(request *core.ImportRequest) (core.ImportRespo
|
||||||
return r.next.ApproveImport(request)
|
return r.next.ApproveImport(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rulesetUI) ApproveListing(request *core.ListRequest) (core.ListResponse, error) {
|
func (r *rulesetUI) ApproveListing(request *core.ListRequest) (core.ListAccountsResponse, error) {
|
||||||
jsonreq, err := json.Marshal(request)
|
jsonreq, err := json.Marshal(request)
|
||||||
approved, err := r.checkApproval("ApproveListing", jsonreq, err)
|
approved, err := r.checkApproval("ApproveListing", jsonreq, err)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -202,9 +202,9 @@ func (r *rulesetUI) ApproveListing(request *core.ListRequest) (core.ListResponse
|
||||||
return r.next.ApproveListing(request)
|
return r.next.ApproveListing(request)
|
||||||
}
|
}
|
||||||
if approved {
|
if approved {
|
||||||
return core.ListResponse{Accounts: request.Accounts}, nil
|
return core.ListAccountsResponse{Accounts: request.Accounts}, nil
|
||||||
}
|
}
|
||||||
return core.ListResponse{}, err
|
return core.ListAccountsResponse{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rulesetUI) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) {
|
func (r *rulesetUI) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) {
|
||||||
|
|
|
||||||
|
|
@ -93,8 +93,8 @@ func (alwaysDenyUI) ApproveImport(request *core.ImportRequest) (core.ImportRespo
|
||||||
return core.ImportResponse{Approved: false, OldPassword: "", NewPassword: ""}, nil
|
return core.ImportResponse{Approved: false, OldPassword: "", NewPassword: ""}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (alwaysDenyUI) ApproveListing(request *core.ListRequest) (core.ListResponse, error) {
|
func (alwaysDenyUI) ApproveListing(request *core.ListRequest) (core.ListAccountsResponse, error) {
|
||||||
return core.ListResponse{Accounts: nil}, nil
|
return core.ListAccountsResponse{Accounts: nil}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (alwaysDenyUI) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) {
|
func (alwaysDenyUI) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) {
|
||||||
|
|
@ -220,9 +220,9 @@ func (d *dummyUI) ApproveImport(request *core.ImportRequest) (core.ImportRespons
|
||||||
return core.ImportResponse{}, core.ErrRequestDenied
|
return core.ImportResponse{}, core.ErrRequestDenied
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dummyUI) ApproveListing(request *core.ListRequest) (core.ListResponse, error) {
|
func (d *dummyUI) ApproveListing(request *core.ListRequest) (core.ListAccountsResponse, error) {
|
||||||
d.calls = append(d.calls, "ApproveListing")
|
d.calls = append(d.calls, "ApproveListing")
|
||||||
return core.ListResponse{}, core.ErrRequestDenied
|
return core.ListAccountsResponse{}, core.ErrRequestDenied
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dummyUI) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) {
|
func (d *dummyUI) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) {
|
||||||
|
|
@ -532,9 +532,9 @@ func (d *dontCallMe) ApproveImport(request *core.ImportRequest) (core.ImportResp
|
||||||
return core.ImportResponse{}, core.ErrRequestDenied
|
return core.ImportResponse{}, core.ErrRequestDenied
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dontCallMe) ApproveListing(request *core.ListRequest) (core.ListResponse, error) {
|
func (d *dontCallMe) ApproveListing(request *core.ListRequest) (core.ListAccountsResponse, error) {
|
||||||
d.t.Fatalf("Did not expect next-handler to be called")
|
d.t.Fatalf("Did not expect next-handler to be called")
|
||||||
return core.ListResponse{}, core.ErrRequestDenied
|
return core.ListAccountsResponse{}, core.ErrRequestDenied
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dontCallMe) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) {
|
func (d *dontCallMe) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue