-
Notifications
You must be signed in to change notification settings - Fork 492
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
Add ABI encoding support #2807
Add ABI encoding support #2807
Conversation
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.
This is really, really big, but I don't know what actually changed in the goal
interface. Could you write up what has been added?
I also would expect to see some very, very concise tests that take a string, and show the proper decoding / encoding. One after another, with edge cases described in comments.
Got it, ok.
…On Fri, Aug 27, 2021 at 12:17 PM Hang Su ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In cmd/goal/abi/abi.go
<#2807 (comment)>:
> + bigIntBytes := bigIntValue.Bytes()
+ buffer := make([]byte, v.valueType.typeSize/8-uint16(len(bigIntBytes)))
+ buffer = append(buffer, bigIntBytes...)
+ return buffer, nil
FillBytes is introduced in 1.15 (ref
<https://pkg.go.dev/math/big#Int.FillBytes>), I have to manually fill
bytes to work with old golang that go-algorand and go-algorand-sdk
support...
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#2807 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADL7T6SWJQ62RRJAYQXYO3T663C5ANCNFSM5C2A5QUA>
.
|
Yes, I agree, our messages were out of sync.
…On Fri, Aug 27, 2021 at 12:25 PM Hang Su ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In cmd/goal/abi/abi.go
<#2807 (comment)>:
> + bigIntBytes := bigIntValue.Bytes()
+ buffer := make([]byte, v.valueType.typeSize/8-uint16(len(bigIntBytes)))
+ buffer = append(buffer, bigIntBytes...)
+ return buffer, nil
Yes, you are correct about using GetUint for size checking, but the point
I am trying to make is, this project supports Golang 1.14, where FillBytes
is not supported, so this is just an ugly work-around that I do not like
too.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub
<#2807 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADL7T5P244DANNPIHZZHRTT664ANANCNFSM5C2A5QUA>
.
|
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 just reviewed abi.go
. That file is really big, could you break it into multiple files?
Codecov Report
@@ Coverage Diff @@
## master #2807 +/- ##
==========================================
+ Coverage 47.08% 47.37% +0.28%
==========================================
Files 349 352 +3
Lines 56401 57044 +643
==========================================
+ Hits 26558 27024 +466
- Misses 26865 26982 +117
- Partials 2978 3038 +60
Continue to review full report at Codecov.
|
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.
Thank you for breaking up the code into multiple files, this was much easier to review
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.
Great, this looks good to me
case Byte: | ||
return "byte" | ||
case Ufixed: | ||
return "ufixed" + strconv.Itoa(int(t.bitSize)) + "x" + strconv.Itoa(int(t.precision)) |
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.
No need to change, but I fmt.Sprintf("ufixed%dx%d", t.bitSize, t.precision)
might be easier on the eyes.
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.
Modified.
staticArrayRegexp, err = regexp.Compile(`^([a-z\d\[\](),]+)\[([1-9][\d]*)]$`) | ||
if err != nil { | ||
panic(err.Error()) | ||
} | ||
ufixedRegexp, err = regexp.Compile(`^ufixed([1-9][\d]*)x([1-9][\d]*)$`) | ||
if err != nil { | ||
panic(err.Error()) |
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.
Simplify with https://pkg.go.dev/regexp#MustCompile ? I suppose that could even make it doable outside init() at global level.
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 removed the init function, put the regexp compile to global level.
Corresponding implementation to algorand/go-algorand#2807 - serialization/deserialization of ABI types (and the corresponding testing) - Encoding/Decoding of JAVA values with ABI type schemes (with tests)
Summary
This PR provides a prototype implementation that closes #2348:
Test Plan
For both ABI Type serialization/deserialization and ABI Value Encoding/Decoding: