-
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
feat(keeper): handle JSON arguments in MsgCall
#1776
base: master
Are you sure you want to change the base?
Conversation
Call
method.MsgCall
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
f6cf7fc
to
e3e3d10
Compare
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1776 +/- ##
==========================================
+ Coverage 47.78% 48.43% +0.64%
==========================================
Files 393 409 +16
Lines 61602 62355 +753
==========================================
+ Hits 29437 30202 +765
+ Misses 29695 29615 -80
- Partials 2470 2538 +68 ☔ View full report in Codecov by Sentry. |
I prefer to use a JSON string instead of an array of strings for input. Because when types overlap, the sequence in the array might unintentionally change the assignment of keys, leading to an incorrect order of values (I'm not sure if this can actually happen). However, the main issue with using JSON strings is that they are more complex and need to be validated to ensure proper format. Nonetheless, the current method is seems quite effective for encoding and decoding. I attempted to implement marshaling and unmarshaling in |
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
I agree with @notJoon -- one string per argument, with that string being JSON for non-primitive types. Here are two other things I noticed while playing around with this:
|
Hmm nice catch, but I think it should be possible if you use a single quote or manually escape double quotes within the double quotes, but that can be a bit tedious.
As I mentioned in the body of this PR, I wasn't able to use Amino for the reply because I have to register the Reply 'Type' dynamically to Amino, and I didn’t find a way to do that (yet). If anybody knows how to do that, it would be awesome. |
@gfanton I was just referring to how it is odd that if I have a struct type arg: type S struct {
A int
} I can't pass in a string like |
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
MsgCall
MsgCall
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
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. The only thing I wonder is: How are we serializing byte arrays? how do we know the real number field type (int8 or int64)?
After the review meeting, the team decided that need to implement dedicated amino (Un)Marshaling before merging this. This PR will be on hold until the feature is implemented. |
Signed-off-by: gfanton <8671905+gfanton@users.noreply.github.com>
By the way, having this amino marshaller will be helpful for std.Emit as well (#1653 or a newer version). |
potentially related to #473 |
Depends on #2113 |
depends on:
gnoland.TypedValue
#2029This is an initial PR to initiate a discussion on a potential approach for managing JSON arguments in
MsgCall
.I achieve this using
Go2GnoValue
andGno2GoValue
methods, along withUnmarshalJSON
andMarshalJSON(need to find a way to make this work) methods fromamino
package.This PR still
WIP
but I have set it to Ready For Review
to discuss some points:Should we use named arguments in a single JSON string request or an array of (JSON) strings or handle both.For example, for a method like:func(argsA []int, argsB string)
, we would have:single string:Args: string(`{"ArgsA": ["2", "3"], "ArgsB": "hello"}`)
vsarray of strings:Args: []string{["2", "3"], "hello"}`?
EDIT: using array of args is best suited, named argument can be done on the client side
Gno2GoValue
to panic because reflect cannot set unexported fields. Ignoring these fields should be the logical approach,but we will need to find a way to avoid reflection on unexported fields inI've updatedGno2GoValue
.gno2GoValue
to skip unexported fields. Not sure if that's the best approach.UPDATE:
amino.Marshal
on unregistered struct. if anybody have a workaround, I can to put it backUnmarshal
method if a method returns one.runMsg
so that when multiple messages are sent, the response data is now split by a new line (\n
) for each message reply.Call
to return only its value without including CPU cycles. This change aligns with expectations, and CPU cycles should be returned in the upper response if really needed.Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description