-
Notifications
You must be signed in to change notification settings - Fork 374
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add Keybase HasByNameOrAddress, HasByName and HasByAddress (#1313
) The Keybase [interface has](https://github.com/gnolang/gno/blob/7105d00e10209003ea41fbae7a4d7c463c4167c3/tm2/pkg/crypto/keys/types.go#L16C2-L18) `GetByNameOrAddress`, `GetByName` and `GetByAddress`. If an application simply wants to check if the key is in the key base, it must use one of these and check for an error, as is done [in the gnokey command line](https://github.com/gnolang/gno/blob/7105d00e10209003ea41fbae7a4d7c463c4167c3/tm2/pkg/crypto/keys/client/add.go#L159-L160). ``` _, err = kb.GetByName(name) if err == nil { // account exists, ask for user confirmation ... } ``` A GnoMobile app also needs to check for the key. But it's expensive to return the entire key info. The byte buffer must be copies multiple times, in the Keybase and in the gRPC interface, and the key info structure must be reformatted to Protobuf and then to the application's language. And not preferable to generate errors to pass information in normal program flow. In the underlying `DB` interface, there is already a [Has function](https://github.com/gnolang/gno/blob/7105d00e10209003ea41fbae7a4d7c463c4167c3/tm2/pkg/db/types.go#L13). This PR updates the `Keybase` with the related functions `HasByNameOrAddress`, `HasByName` and `HasByAddress` which use `Has` to inexpensively return a simple bool. It also updates the gnokey command line to use `HasByName` to be more clear: ``` if has, err := kb.HasByName(name); err == nil && has { // account exists, ask for user confirmation ... } ``` --------- Signed-off-by: Jeff Thompson <jeff@thefirst.org> Co-authored-by: Morgan Bazalgette <morgan@morganbaz.com>
- Loading branch information
Showing
5 changed files
with
72 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters