Skip to content

Commit

Permalink
fix: HasByAddress should take crypto.Address, like GetByAddress
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Thompson <jeff@thefirst.org>
  • Loading branch information
jefft0 committed Oct 30, 2023
1 parent 1f680a2 commit 28b43bc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
16 changes: 6 additions & 10 deletions tm2/pkg/crypto/keys/keybase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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.
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tm2/pkg/crypto/keys/lazy_keybase.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tm2/pkg/crypto/keys/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 28b43bc

Please sign in to comment.