-
Notifications
You must be signed in to change notification settings - Fork 69
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
Boxes: Add convenience methods for encoding Box names #346
Boxes: Add convenience methods for encoding Box names #346
Conversation
How do we feel about supplying this method as a member in AppBoxReference abr = AppBoxReference(123, someBytes);
// Submit transaction with abr
Response<Box> boxResp = clients.v2Client.GetApplicationBoxByName(appId).name(abr.queryEncoding()).execute(); where the member method can convert the box object's byte name to a goal app-arg encoding. |
@algochoi It's a reasonable question. @algoidurovic raised a similar question in go-algorand-sdk.
|
@michaeldiamant I think only the |
@algochoi e05aa04 applies the feedback - let me know what you think. A point of context: Generally, I view moving serialization/encoding into a domain object as a lack of separation of concerns. Since preferred alternatives (e.g. defining an encoding type class) are limited by the generated code, I'm willing to go down the path for |
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.
Nice, the implementation and the tests LGTM.
Wondering what your thoughts are on naming BoxQueryEncoding
something more general, like GoalEncoding
, since this is a goal app-arg convention. I think this would make the class name more future proof if we want to use it in other APIs and provide additional convenience methods for it (e.g. encode to different prefixes like str
and `int).
My 2c is to keep as is though if you'd like to discuss further, I'll happily have a verbal. Rationale:
|
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.
Sounds good, LGTM 📦
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.
I'm slightly concerned about users not being aware of this method when calling the API but I don't see a perfect solution to it. Documentation and the locality of having the method available in the class like you're doing here is probably sufficient. Maybe more of an issue in go because of how easy it easy to convert between strings and bytes, making it pretty tempting for the user to call the endpoint with string(box.name)
. This PR LGTM though, just putting some thoughts out there in case you find them relevant.
@algoidurovic Planning to merge though I share the concern. I don't see a better alternative with today's tooling. I think any alternative (e.g. defining specific types) that addresses the concern conflicts with the code generation strategy. |
Adds convenience methods to ensure proper Box name encoding when querying Boxes.
Details:
com.algorand.algosdk.v2.client.common.AlgodClient
is auto-generated, it's not possible to provide manual extensions (e.g. expose another route). So, the PR opts to provide utility methods that can be used by the library user.BoxQueryEncoding
inutil
package following the repo's prevailing convenience method location.