signer: fix golint errors (#16653)

* signer/*: golint fixes

Specifically naming and comment formatting for documentation

* signer/*: fixed naming error crashing build

* signer/*: corrected error

* signer/core: fix tiny error whitespace

* signer/rules: fix test refactor
This commit is contained in:
Eli 2018-05-04 01:04:17 -07:00 committed by Péter Szilágyi
parent 5b3af4c3d1
commit 16f3c31773
8 changed files with 78 additions and 79 deletions

View File

@ -94,14 +94,13 @@ func parseCallData(calldata []byte, abidata string) (*decodedCallData, error) {
for n, argument := range method.Inputs { for n, argument := range method.Inputs {
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed to decode argument %d (signature %v): %v", n, method.Sig(), err) return nil, fmt.Errorf("Failed to decode argument %d (signature %v): %v", n, method.Sig(), err)
} else { }
decodedArg := decodedArgument{ decodedArg := decodedArgument{
soltype: argument, soltype: argument,
value: v[n], value: v[n],
} }
decoded.inputs = append(decoded.inputs, decodedArg) decoded.inputs = append(decoded.inputs, decodedArg)
} }
}
// We're finished decoding the data. At this point, we encode the decoded data to see if it matches with the // We're finished decoding the data. At this point, we encode the decoded data to see if it matches with the
// original data. If we didn't do that, it would e.g. be possible to stuff extra data into the arguments, which // original data. If we didn't do that, it would e.g. be possible to stuff extra data into the arguments, which
@ -240,7 +239,7 @@ func (db *AbiDb) saveCustomAbi(selector, signature string) error {
return err return err
} }
// Adds a signature to the database, if custom database saving is enabled. // AddSignature to the database, if custom database saving is enabled.
// OBS: This method does _not_ validate the correctness of the data, // OBS: This method does _not_ validate the correctness of the data,
// it is assumed that the caller has already done so // it is assumed that the caller has already done so
func (db *AbiDb) AddSignature(selector string, data []byte) error { func (db *AbiDb) AddSignature(selector string, data []byte) error {

View File

@ -474,7 +474,7 @@ func (api *SignerAPI) Export(ctx context.Context, addr common.Address) (json.Raw
return ioutil.ReadFile(wallet.URL().Path) return ioutil.ReadFile(wallet.URL().Path)
} }
// Imports tries to import the given keyJSON in the local keystore. The keyJSON data is expected to be // Import tries to import the given keyJSON in the local keystore. The keyJSON data is expected to be
// in web3 keystore format. It will decrypt the keyJSON with the given passphrase and on successful // in web3 keystore format. It will decrypt the keyJSON with the given passphrase and on successful
// decryption it will encrypt the key with the given newPassphrase and store it in the keystore. // decryption it will encrypt the key with the given newPassphrase and store it in the keystore.
func (api *SignerAPI) Import(ctx context.Context, keyJSON json.RawMessage) (Account, error) { func (api *SignerAPI) Import(ctx context.Context, keyJSON json.RawMessage) (Account, error) {

View File

@ -13,6 +13,7 @@
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
package core package core
import ( import (

View File

@ -73,8 +73,8 @@ type SendTxArgs struct {
Input *hexutil.Bytes `json:"input"` Input *hexutil.Bytes `json:"input"`
} }
func (t SendTxArgs) String() string { func (args SendTxArgs) String() string {
s, err := json.Marshal(t) s, err := json.Marshal(args)
if err == nil { if err == nil {
return string(s) return string(s)
} }

View File

@ -128,7 +128,7 @@ func (v *Validator) validate(msgs *ValidationMessages, txargs *SendTxArgs, metho
if len(data) == 0 { if len(data) == 0 {
if txargs.Value.ToInt().Cmp(big.NewInt(0)) > 0 { if txargs.Value.ToInt().Cmp(big.NewInt(0)) > 0 {
// Sending ether into black hole // Sending ether into black hole
return errors.New(`Tx will create contract with value but empty code!`) return errors.New("Tx will create contract with value but empty code!")
} }
// No value submitted at least // No value submitted at least
msgs.crit("Tx will create contract with empty code!") msgs.crit("Tx will create contract with empty code!")

View File

@ -46,17 +46,17 @@ func consoleOutput(call otto.FunctionCall) otto.Value {
return otto.Value{} return otto.Value{}
} }
// rulesetUi provides an implementation of SignerUI that evaluates a javascript // rulesetUI provides an implementation of SignerUI that evaluates a javascript
// file for each defined UI-method // file for each defined UI-method
type rulesetUi struct { type rulesetUI struct {
next core.SignerUI // The next handler, for manual processing next core.SignerUI // The next handler, for manual processing
storage storage.Storage storage storage.Storage
credentials storage.Storage credentials storage.Storage
jsRules string // The rules to use jsRules string // The rules to use
} }
func NewRuleEvaluator(next core.SignerUI, jsbackend, credentialsBackend storage.Storage) (*rulesetUi, error) { func NewRuleEvaluator(next core.SignerUI, jsbackend, credentialsBackend storage.Storage) (*rulesetUI, error) {
c := &rulesetUi{ c := &rulesetUI{
next: next, next: next,
storage: jsbackend, storage: jsbackend,
credentials: credentialsBackend, credentials: credentialsBackend,
@ -66,11 +66,11 @@ func NewRuleEvaluator(next core.SignerUI, jsbackend, credentialsBackend storage.
return c, nil return c, nil
} }
func (r *rulesetUi) Init(javascriptRules string) error { func (r *rulesetUI) Init(javascriptRules string) error {
r.jsRules = javascriptRules r.jsRules = javascriptRules
return nil return nil
} }
func (r *rulesetUi) execute(jsfunc string, jsarg interface{}) (otto.Value, error) { func (r *rulesetUI) execute(jsfunc string, jsarg interface{}) (otto.Value, error) {
// Instantiate a fresh vm engine every time // Instantiate a fresh vm engine every time
vm := otto.New() vm := otto.New()
@ -115,7 +115,7 @@ func (r *rulesetUi) execute(jsfunc string, jsarg interface{}) (otto.Value, error
return vm.Run(call) return vm.Run(call)
} }
func (r *rulesetUi) checkApproval(jsfunc string, jsarg []byte, err error) (bool, error) { func (r *rulesetUI) checkApproval(jsfunc string, jsarg []byte, err error) (bool, error) {
if err != nil { if err != nil {
return false, err return false, err
} }
@ -139,7 +139,7 @@ func (r *rulesetUi) checkApproval(jsfunc string, jsarg []byte, err error) (bool,
return false, fmt.Errorf("Unknown response") return false, fmt.Errorf("Unknown response")
} }
func (r *rulesetUi) ApproveTx(request *core.SignTxRequest) (core.SignTxResponse, error) { func (r *rulesetUI) ApproveTx(request *core.SignTxRequest) (core.SignTxResponse, error) {
jsonreq, err := json.Marshal(request) jsonreq, err := json.Marshal(request)
approved, err := r.checkApproval("ApproveTx", jsonreq, err) approved, err := r.checkApproval("ApproveTx", jsonreq, err)
if err != nil { if err != nil {
@ -158,11 +158,11 @@ func (r *rulesetUi) ApproveTx(request *core.SignTxRequest) (core.SignTxResponse,
return core.SignTxResponse{Approved: false}, err return core.SignTxResponse{Approved: false}, err
} }
func (r *rulesetUi) lookupPassword(address common.Address) string { func (r *rulesetUI) lookupPassword(address common.Address) string {
return r.credentials.Get(strings.ToLower(address.String())) return r.credentials.Get(strings.ToLower(address.String()))
} }
func (r *rulesetUi) ApproveSignData(request *core.SignDataRequest) (core.SignDataResponse, error) { func (r *rulesetUI) ApproveSignData(request *core.SignDataRequest) (core.SignDataResponse, error) {
jsonreq, err := json.Marshal(request) jsonreq, err := json.Marshal(request)
approved, err := r.checkApproval("ApproveSignData", jsonreq, err) approved, err := r.checkApproval("ApproveSignData", jsonreq, err)
if err != nil { if err != nil {
@ -175,7 +175,7 @@ func (r *rulesetUi) ApproveSignData(request *core.SignDataRequest) (core.SignDat
return core.SignDataResponse{Approved: false, Password: ""}, err return core.SignDataResponse{Approved: false, Password: ""}, err
} }
func (r *rulesetUi) ApproveExport(request *core.ExportRequest) (core.ExportResponse, error) { func (r *rulesetUI) ApproveExport(request *core.ExportRequest) (core.ExportResponse, error) {
jsonreq, err := json.Marshal(request) jsonreq, err := json.Marshal(request)
approved, err := r.checkApproval("ApproveExport", jsonreq, err) approved, err := r.checkApproval("ApproveExport", jsonreq, err)
if err != nil { if err != nil {
@ -188,13 +188,13 @@ func (r *rulesetUi) ApproveExport(request *core.ExportRequest) (core.ExportRespo
return core.ExportResponse{Approved: false}, err return core.ExportResponse{Approved: false}, err
} }
func (r *rulesetUi) ApproveImport(request *core.ImportRequest) (core.ImportResponse, error) { func (r *rulesetUI) ApproveImport(request *core.ImportRequest) (core.ImportResponse, error) {
// This cannot be handled by rules, requires setting a password // This cannot be handled by rules, requires setting a password
// dispatch to next // dispatch to next
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.ListResponse, 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 {
@ -207,22 +207,22 @@ func (r *rulesetUi) ApproveListing(request *core.ListRequest) (core.ListResponse
return core.ListResponse{}, err return core.ListResponse{}, err
} }
func (r *rulesetUi) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) { func (r *rulesetUI) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) {
// This cannot be handled by rules, requires setting a password // This cannot be handled by rules, requires setting a password
// dispatch to next // dispatch to next
return r.next.ApproveNewAccount(request) return r.next.ApproveNewAccount(request)
} }
func (r *rulesetUi) ShowError(message string) { func (r *rulesetUI) ShowError(message string) {
log.Error(message) log.Error(message)
r.next.ShowError(message) r.next.ShowError(message)
} }
func (r *rulesetUi) ShowInfo(message string) { func (r *rulesetUI) ShowInfo(message string) {
log.Info(message) log.Info(message)
r.next.ShowInfo(message) r.next.ShowInfo(message)
} }
func (r *rulesetUi) OnSignerStartup(info core.StartupInfo) { func (r *rulesetUI) OnSignerStartup(info core.StartupInfo) {
jsonInfo, err := json.Marshal(info) jsonInfo, err := json.Marshal(info)
if err != nil { if err != nil {
log.Warn("failed marshalling data", "data", info) log.Warn("failed marshalling data", "data", info)
@ -235,7 +235,7 @@ func (r *rulesetUi) OnSignerStartup(info core.StartupInfo) {
} }
} }
func (r *rulesetUi) OnApprovedTx(tx ethapi.SignTransactionResult) { func (r *rulesetUI) OnApprovedTx(tx ethapi.SignTransactionResult) {
jsonTx, err := json.Marshal(tx) jsonTx, err := json.Marshal(tx)
if err != nil { if err != nil {
log.Warn("failed marshalling transaction", "tx", tx) log.Warn("failed marshalling transaction", "tx", tx)

View File

@ -72,49 +72,49 @@ func mixAddr(a string) (*common.MixedcaseAddress, error) {
return common.NewMixedcaseAddressFromString(a) return common.NewMixedcaseAddressFromString(a)
} }
type alwaysDenyUi struct{} type alwaysDenyUI struct{}
func (alwaysDenyUi) OnSignerStartup(info core.StartupInfo) { func (alwaysDenyUI) OnSignerStartup(info core.StartupInfo) {
} }
func (alwaysDenyUi) ApproveTx(request *core.SignTxRequest) (core.SignTxResponse, error) { func (alwaysDenyUI) ApproveTx(request *core.SignTxRequest) (core.SignTxResponse, error) {
return core.SignTxResponse{Transaction: request.Transaction, Approved: false, Password: ""}, nil return core.SignTxResponse{Transaction: request.Transaction, Approved: false, Password: ""}, nil
} }
func (alwaysDenyUi) ApproveSignData(request *core.SignDataRequest) (core.SignDataResponse, error) { func (alwaysDenyUI) ApproveSignData(request *core.SignDataRequest) (core.SignDataResponse, error) {
return core.SignDataResponse{Approved: false, Password: ""}, nil return core.SignDataResponse{Approved: false, Password: ""}, nil
} }
func (alwaysDenyUi) ApproveExport(request *core.ExportRequest) (core.ExportResponse, error) { func (alwaysDenyUI) ApproveExport(request *core.ExportRequest) (core.ExportResponse, error) {
return core.ExportResponse{Approved: false}, nil return core.ExportResponse{Approved: false}, nil
} }
func (alwaysDenyUi) ApproveImport(request *core.ImportRequest) (core.ImportResponse, error) { func (alwaysDenyUI) ApproveImport(request *core.ImportRequest) (core.ImportResponse, error) {
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.ListResponse, error) {
return core.ListResponse{Accounts: nil}, nil return core.ListResponse{Accounts: nil}, nil
} }
func (alwaysDenyUi) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) { func (alwaysDenyUI) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) {
return core.NewAccountResponse{Approved: false, Password: ""}, nil return core.NewAccountResponse{Approved: false, Password: ""}, nil
} }
func (alwaysDenyUi) ShowError(message string) { func (alwaysDenyUI) ShowError(message string) {
panic("implement me") panic("implement me")
} }
func (alwaysDenyUi) ShowInfo(message string) { func (alwaysDenyUI) ShowInfo(message string) {
panic("implement me") panic("implement me")
} }
func (alwaysDenyUi) OnApprovedTx(tx ethapi.SignTransactionResult) { func (alwaysDenyUI) OnApprovedTx(tx ethapi.SignTransactionResult) {
panic("implement me") panic("implement me")
} }
func initRuleEngine(js string) (*rulesetUi, error) { func initRuleEngine(js string) (*rulesetUI, error) {
r, err := NewRuleEvaluator(&alwaysDenyUi{}, storage.NewEphemeralStorage(), storage.NewEphemeralStorage()) r, err := NewRuleEvaluator(&alwaysDenyUI{}, storage.NewEphemeralStorage(), storage.NewEphemeralStorage())
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to create js engine: %v", err) return nil, fmt.Errorf("failed to create js engine: %v", err)
} }
@ -196,59 +196,59 @@ func TestSignTxRequest(t *testing.T) {
} }
} }
type dummyUi struct { type dummyUI struct {
calls []string calls []string
} }
func (d *dummyUi) ApproveTx(request *core.SignTxRequest) (core.SignTxResponse, error) { func (d *dummyUI) ApproveTx(request *core.SignTxRequest) (core.SignTxResponse, error) {
d.calls = append(d.calls, "ApproveTx") d.calls = append(d.calls, "ApproveTx")
return core.SignTxResponse{}, core.ErrRequestDenied return core.SignTxResponse{}, core.ErrRequestDenied
} }
func (d *dummyUi) ApproveSignData(request *core.SignDataRequest) (core.SignDataResponse, error) { func (d *dummyUI) ApproveSignData(request *core.SignDataRequest) (core.SignDataResponse, error) {
d.calls = append(d.calls, "ApproveSignData") d.calls = append(d.calls, "ApproveSignData")
return core.SignDataResponse{}, core.ErrRequestDenied return core.SignDataResponse{}, core.ErrRequestDenied
} }
func (d *dummyUi) ApproveExport(request *core.ExportRequest) (core.ExportResponse, error) { func (d *dummyUI) ApproveExport(request *core.ExportRequest) (core.ExportResponse, error) {
d.calls = append(d.calls, "ApproveExport") d.calls = append(d.calls, "ApproveExport")
return core.ExportResponse{}, core.ErrRequestDenied return core.ExportResponse{}, core.ErrRequestDenied
} }
func (d *dummyUi) ApproveImport(request *core.ImportRequest) (core.ImportResponse, error) { func (d *dummyUI) ApproveImport(request *core.ImportRequest) (core.ImportResponse, error) {
d.calls = append(d.calls, "ApproveImport") d.calls = append(d.calls, "ApproveImport")
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.ListResponse, error) {
d.calls = append(d.calls, "ApproveListing") d.calls = append(d.calls, "ApproveListing")
return core.ListResponse{}, core.ErrRequestDenied return core.ListResponse{}, core.ErrRequestDenied
} }
func (d *dummyUi) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) { func (d *dummyUI) ApproveNewAccount(request *core.NewAccountRequest) (core.NewAccountResponse, error) {
d.calls = append(d.calls, "ApproveNewAccount") d.calls = append(d.calls, "ApproveNewAccount")
return core.NewAccountResponse{}, core.ErrRequestDenied return core.NewAccountResponse{}, core.ErrRequestDenied
} }
func (d *dummyUi) ShowError(message string) { func (d *dummyUI) ShowError(message string) {
d.calls = append(d.calls, "ShowError") d.calls = append(d.calls, "ShowError")
} }
func (d *dummyUi) ShowInfo(message string) { func (d *dummyUI) ShowInfo(message string) {
d.calls = append(d.calls, "ShowInfo") d.calls = append(d.calls, "ShowInfo")
} }
func (d *dummyUi) OnApprovedTx(tx ethapi.SignTransactionResult) { func (d *dummyUI) OnApprovedTx(tx ethapi.SignTransactionResult) {
d.calls = append(d.calls, "OnApprovedTx") d.calls = append(d.calls, "OnApprovedTx")
} }
func (d *dummyUi) OnSignerStartup(info core.StartupInfo) { func (d *dummyUI) OnSignerStartup(info core.StartupInfo) {
} }
//TestForwarding tests that the rule-engine correctly dispatches requests to the next caller //TestForwarding tests that the rule-engine correctly dispatches requests to the next caller
func TestForwarding(t *testing.T) { func TestForwarding(t *testing.T) {
js := "" js := ""
ui := &dummyUi{make([]string, 0)} ui := &dummyUI{make([]string, 0)}
jsBackend := storage.NewEphemeralStorage() jsBackend := storage.NewEphemeralStorage()
credBackend := storage.NewEphemeralStorage() credBackend := storage.NewEphemeralStorage()
r, err := NewRuleEvaluator(ui, jsBackend, credBackend) r, err := NewRuleEvaluator(ui, jsBackend, credBackend)

View File

@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
// //
package storage package storage
import ( import (
@ -106,10 +107,8 @@ func (s *AESEncryptedStorage) readEncryptedStorage() (map[string]storedCredentia
if os.IsNotExist(err) { if os.IsNotExist(err) {
// Doesn't exist yet // Doesn't exist yet
return creds, nil return creds, nil
} else {
log.Warn("Failed to read encrypted storage", "err", err, "file", s.filename)
} }
log.Warn("Failed to read encrypted storage", "err", err, "file", s.filename)
} }
if err = json.Unmarshal(raw, &creds); err != nil { if err = json.Unmarshal(raw, &creds); err != nil {
log.Warn("Failed to unmarshal encrypted storage", "err", err, "file", s.filename) log.Warn("Failed to unmarshal encrypted storage", "err", err, "file", s.filename)