diff options
author | Martin Holst Swende <martin@swende.se> | 2019-03-07 17:56:08 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-03-07 17:56:08 +0800 |
commit | 5f94f8c7e7cfc6d037accfad379ce2ab0df6bf47 (patch) | |
tree | ac9db4d11def29b0c7fbd638567e05797d929678 /signer/rules/rules.go | |
parent | eb199f1fc2fc91e40431c5acce61227a95d476bb (diff) | |
download | go-tangerine-5f94f8c7e7cfc6d037accfad379ce2ab0df6bf47.tar go-tangerine-5f94f8c7e7cfc6d037accfad379ce2ab0df6bf47.tar.gz go-tangerine-5f94f8c7e7cfc6d037accfad379ce2ab0df6bf47.tar.bz2 go-tangerine-5f94f8c7e7cfc6d037accfad379ce2ab0df6bf47.tar.lz go-tangerine-5f94f8c7e7cfc6d037accfad379ce2ab0df6bf47.tar.xz go-tangerine-5f94f8c7e7cfc6d037accfad379ce2ab0df6bf47.tar.zst go-tangerine-5f94f8c7e7cfc6d037accfad379ce2ab0df6bf47.zip |
signer: change the stdio jsonrpc to use legacy namespace conventions (#19047)
This PR will will break existing UIs, since it changes all calls like ApproveSignTransaction to be on the form ui_approveSignTransaction.
This is to make it possible for the UI to reuse the json-rpc library from go-ethereum, which uses this convention.
Also, this PR removes some unused structs, after import/export were removed from the external api (so no longer needs internal methods for approval)
One more breaking change is introduced, removing passwords from the ApproveSignTxResponse and the likes. This makes the manual interface more like the rulebased interface, and integrates nicely with the credential storage. Thus, the way it worked before, it would be tempting for the UI to implement 'remember password' functionality. The way it is now, it will be easy instead to tell clef to store passwords and use them.
If a pw is not found in the credential store, the user is prompted to provide the password.
Diffstat (limited to 'signer/rules/rules.go')
-rw-r--r-- | signer/rules/rules.go | 50 |
1 files changed, 11 insertions, 39 deletions
diff --git a/signer/rules/rules.go b/signer/rules/rules.go index 1f81e21bd..5ebffa3af 100644 --- a/signer/rules/rules.go +++ b/signer/rules/rules.go @@ -22,7 +22,6 @@ import ( "os" "strings" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/signer/core" @@ -42,25 +41,23 @@ func consoleOutput(call otto.FunctionCall) otto.Value { for _, argument := range call.ArgumentList { output = append(output, fmt.Sprintf("%v", argument)) } - fmt.Fprintln(os.Stdout, strings.Join(output, " ")) + fmt.Fprintln(os.Stderr, strings.Join(output, " ")) return otto.Value{} } // rulesetUI provides an implementation of UIClientAPI that evaluates a javascript // file for each defined UI-method type rulesetUI struct { - next core.UIClientAPI // The next handler, for manual processing - storage storage.Storage - credentials storage.Storage - jsRules string // The rules to use + next core.UIClientAPI // The next handler, for manual processing + storage storage.Storage + jsRules string // The rules to use } -func NewRuleEvaluator(next core.UIClientAPI, jsbackend, credentialsBackend storage.Storage) (*rulesetUI, error) { +func NewRuleEvaluator(next core.UIClientAPI, jsbackend storage.Storage) (*rulesetUI, error) { c := &rulesetUI{ - next: next, - storage: jsbackend, - credentials: credentialsBackend, - jsRules: "", + next: next, + storage: jsbackend, + jsRules: "", } return c, nil @@ -153,18 +150,12 @@ func (r *rulesetUI) ApproveTx(request *core.SignTxRequest) (core.SignTxResponse, if approved { return core.SignTxResponse{ Transaction: request.Transaction, - Approved: true, - Password: r.lookupPassword(request.Transaction.From.Address()), - }, + Approved: true}, nil } return core.SignTxResponse{Approved: false}, err } -func (r *rulesetUI) lookupPassword(address common.Address) string { - return r.credentials.Get(strings.ToLower(address.String())) -} - func (r *rulesetUI) ApproveSignData(request *core.SignDataRequest) (core.SignDataResponse, error) { jsonreq, err := json.Marshal(request) approved, err := r.checkApproval("ApproveSignData", jsonreq, err) @@ -173,28 +164,9 @@ func (r *rulesetUI) ApproveSignData(request *core.SignDataRequest) (core.SignDat return r.next.ApproveSignData(request) } if approved { - return core.SignDataResponse{Approved: true, Password: r.lookupPassword(request.Address.Address())}, nil - } - return core.SignDataResponse{Approved: false, Password: ""}, err -} - -func (r *rulesetUI) ApproveExport(request *core.ExportRequest) (core.ExportResponse, error) { - jsonreq, err := json.Marshal(request) - approved, err := r.checkApproval("ApproveExport", jsonreq, err) - if err != nil { - log.Info("Rule-based approval error, going to manual", "error", err) - return r.next.ApproveExport(request) - } - if approved { - return core.ExportResponse{Approved: true}, nil + return core.SignDataResponse{Approved: true}, nil } - return core.ExportResponse{Approved: false}, err -} - -func (r *rulesetUI) ApproveImport(request *core.ImportRequest) (core.ImportResponse, error) { - // This cannot be handled by rules, requires setting a password - // dispatch to next - return r.next.ApproveImport(request) + return core.SignDataResponse{Approved: false}, err } // OnInputRequired not handled by rules |