diff --git a/tm2/pkg/crypto/keys/keybase.go b/tm2/pkg/crypto/keys/keybase.go index 2bc7f64cb25..2e3dd94dc41 100644 --- a/tm2/pkg/crypto/keys/keybase.go +++ b/tm2/pkg/crypto/keys/keybase.go @@ -170,11 +170,11 @@ func (kb dbKeybase) List() ([]Info, error) { // HasByNameOrAddress checks if a key with the name or bech32 string address is in the keybase. func (kb dbKeybase) HasByNameOrAddress(nameOrBech32 string) (bool, error) { - has, err := kb.HasByAddress(nameOrBech32) + address, err := crypto.AddressFromBech32(nameOrBech32) if err != nil { return kb.HasByName(nameOrBech32) } else { - return has, nil + return kb.HasByAddress(address) } } @@ -183,13 +183,9 @@ func (kb dbKeybase) HasByName(name string) (bool, error) { return kb.db.Has(infoKey(name)), nil } -// HasByAddress checks if a key with the bech32 string address is in the keybase. -func (kb dbKeybase) HasByAddress(bech32Address string) (bool, error) { - addr, err := crypto.AddressFromBech32(bech32Address) - if err != nil { - return false, err - } - return kb.db.Has(addrKey(addr)), nil +// HasByAddress checks if a key with the address is in the keybase. +func (kb dbKeybase) HasByAddress(address crypto.Address) (bool, error) { + return kb.db.Has(addrKey(address)), nil } // Get returns the public information about one key. @@ -213,7 +209,7 @@ func (kb dbKeybase) GetByName(name string) (Info, error) { func (kb dbKeybase) GetByAddress(address crypto.Address) (Info, error) { ik := kb.db.Get(addrKey(address)) if len(ik) == 0 { - return nil, keyerror.NewErrKeyNotFound(fmt.Sprintf("key with address %s not found", address)) + return nil, fmt.Errorf("key with address %s not found", address) } bs := kb.db.Get(ik) return readInfo(bs) diff --git a/tm2/pkg/crypto/keys/lazy_keybase.go b/tm2/pkg/crypto/keys/lazy_keybase.go index 3edd3381d52..62e88d9a8e2 100644 --- a/tm2/pkg/crypto/keys/lazy_keybase.go +++ b/tm2/pkg/crypto/keys/lazy_keybase.go @@ -57,14 +57,14 @@ func (lkb lazyKeybase) HasByName(name string) (bool, error) { return NewDBKeybase(db).HasByName(name) } -func (lkb lazyKeybase) HasByAddress(bech32Address string) (bool, error) { +func (lkb lazyKeybase) HasByAddress(address crypto.Address) (bool, error) { db, err := db.NewDB(lkb.name, dbBackend, lkb.dir) if err != nil { return false, err } defer db.Close() - return NewDBKeybase(db).HasByAddress(bech32Address) + return NewDBKeybase(db).HasByAddress(address) } func (lkb lazyKeybase) GetByNameOrAddress(nameOrBech32 string) (Info, error) { diff --git a/tm2/pkg/crypto/keys/types.go b/tm2/pkg/crypto/keys/types.go index a6669af9210..c5d33023a0a 100644 --- a/tm2/pkg/crypto/keys/types.go +++ b/tm2/pkg/crypto/keys/types.go @@ -15,7 +15,7 @@ type Keybase interface { List() ([]Info, error) HasByNameOrAddress(nameOrBech32 string) (bool, error) HasByName(name string) (bool, error) - HasByAddress(bech32Address string) (bool, error) + HasByAddress(address crypto.Address) (bool, error) GetByNameOrAddress(nameOrBech32 string) (Info, error) GetByName(name string) (Info, error) GetByAddress(address crypto.Address) (Info, error)