From 74d17abd01226a8af4a04d607504b1ed7323cf47 Mon Sep 17 00:00:00 2001 From: Monkey Date: Tue, 11 Jun 2024 11:05:20 +0800 Subject: [PATCH] signer/core: solving the problem of unused variables --- signer/core/uiapi.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/signer/core/uiapi.go b/signer/core/uiapi.go index b8c3acfb4d..7d1639424b 100644 --- a/signer/core/uiapi.go +++ b/signer/core/uiapi.go @@ -55,6 +55,9 @@ func NewUIServerAPI(extapi *SignerAPI) *UIServerAPI { func (s *UIServerAPI) ListAccounts(ctx context.Context) ([]accounts.Account, error) { var accs []accounts.Account for _, wallet := range s.am.Wallets() { + if err := ctx.Err(); err != nil { + return accs, err + } accs = append(accs, wallet.Accounts()...) } return accs, nil @@ -127,7 +130,7 @@ func (s *UIServerAPI) ImportRawKey(privkey string, password string) (accounts.Ac if err != nil { return accounts.Account{}, err } - if err := ValidatePasswordFormat(password); err != nil { + if err = ValidatePasswordFormat(password); err != nil { return accounts.Account{}, fmt.Errorf("password requirements not met: %v", err) } // No error @@ -170,7 +173,7 @@ func (s *UIServerAPI) SetChainId(id math.HexOrDecimal64) math.HexOrDecimal64 { // Export returns encrypted private key associated with the given address in web3 keystore format. // Example // {"jsonrpc":"2.0","method":"clef_export","params":["0x19e7e376e7c213b7e7e7e46cc70a5dd086daff2a"], "id":4} -func (s *UIServerAPI) Export(ctx context.Context, addr common.Address) (json.RawMessage, error) { +func (s *UIServerAPI) Export(_ context.Context, addr common.Address) (json.RawMessage, error) { // Look up the wallet containing the requested signer wallet, err := s.am.Find(accounts.Account{Address: addr}) if err != nil { @@ -187,8 +190,8 @@ func (s *UIServerAPI) Export(ctx context.Context, addr common.Address) (json.Raw // decryption it will encrypt the key with the given newPassphrase and store it in the keystore. // Example (the address in question has privkey `11...11`): // {"jsonrpc":"2.0","method":"clef_import","params":[{"address":"19e7e376e7c213b7e7e7e46cc70a5dd086daff2a","crypto":{"cipher":"aes-128-ctr","ciphertext":"33e4cd3756091d037862bb7295e9552424a391a6e003272180a455ca2a9fb332","cipherparams":{"iv":"b54b263e8f89c42bb219b6279fba5cce"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"e4ca94644fd30569c1b1afbbc851729953c92637b7fe4bb9840bbb31ffbc64a5"},"mac":"f4092a445c2b21c0ef34f17c9cd0d873702b2869ec5df4439a0c2505823217e7"},"id":"216c7eac-e8c1-49af-a215-fa0036f29141","version":3},"test","yaddayadda"], "id":4} -func (api *UIServerAPI) Import(ctx context.Context, keyJSON json.RawMessage, oldPassphrase, newPassphrase string) (accounts.Account, error) { - be := api.am.Backends(keystore.KeyStoreType) +func (s *UIServerAPI) Import(_ context.Context, keyJSON json.RawMessage, oldPassphrase, newPassphrase string) (accounts.Account, error) { + be := s.am.Backends(keystore.KeyStoreType) if len(be) == 0 { return accounts.Account{}, errors.New("password based accounts not supported") @@ -205,8 +208,8 @@ func (api *UIServerAPI) Import(ctx context.Context, keyJSON json.RawMessage, old // This method is the same as New on the external API, the difference being that // this implementation does not ask for confirmation, since it's initiated by // the user -func (api *UIServerAPI) New(ctx context.Context) (common.Address, error) { - return api.extApi.newAccount() +func (s *UIServerAPI) New(_ context.Context) (common.Address, error) { + return s.extApi.newAccount() } // Other methods to be added, not yet implemented are: