-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Add Keybase HasByNameOrAddress, HasByName and HasByAddress #1313
chore: Add Keybase HasByNameOrAddress, HasByName and HasByAddress #1313
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #1313 +/- ##
==========================================
+ Coverage 47.87% 55.11% +7.24%
==========================================
Files 372 421 +49
Lines 63019 67456 +4437
==========================================
+ Hits 30168 37179 +7011
+ Misses 30384 27369 -3015
- Partials 2467 2908 +441
☔ View full report in Codecov by Sentry. |
c3f6354
to
e8c2917
Compare
Signed-off-by: Jeff Thompson <jeff@thefirst.org>
e8c2917
to
21e9172
Compare
…if possible Signed-off-by: Jeff Thompson <jeff@thefirst.org>
c6d0075
to
17e247b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, makes sense.
Signed-off-by: Jeff Thompson <jeff@thefirst.org>
…olang#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>
The Keybase interface has
GetByNameOrAddress
,GetByName
andGetByAddress
. 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.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. This PR updates theKeybase
with the related functionsHasByNameOrAddress
,HasByName
andHasByAddress
which useHas
to inexpensively return a simple bool. It also updates the gnokey command line to useHasByName
to be more clear: