Skip to content

Commit

Permalink
Merge pull request #6 from berty/fix/HasByAddress-crypto-Address
Browse files Browse the repository at this point in the history
fix: HasByAddress should take crypto.Address, like GetByAddress
  • Loading branch information
jefft0 authored Oct 30, 2023
2 parents 1f680a2 + b20bcc2 commit 4aa291d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
14 changes: 5 additions & 9 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 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 4aa291d

Please sign in to comment.