Skip to content
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

Merged
merged 29 commits into from
Sep 25, 2021
Merged

Add ABI encoding support #2807

merged 29 commits into from
Sep 25, 2021

Conversation

ahangsu
Copy link
Contributor

@ahangsu ahangsu commented Aug 25, 2021

Summary

This PR provides a prototype implementation that closes #2348:

  • Encoding/Decoding method for ABI Values.
  • Serialization/Deserialization of ABI Types.
  • Make/Get methods for ABI Types/Values.
  • Basic testcases for Encoding/Decoding.

Test Plan

For both ABI Type serialization/deserialization and ABI Value Encoding/Decoding:

  • Valid test cases are provided to see if it returns expected values.
  • Invalid test cases are also provided to see if it can catch error and return err.

@ahangsu ahangsu changed the title Feature/abi encoding Add ABI encoding support to goal Aug 25, 2021
Copy link
Contributor

@jannotti jannotti left a 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.

@jannotti
Copy link
Contributor

jannotti commented Aug 27, 2021 via email

@jannotti
Copy link
Contributor

jannotti commented Aug 27, 2021 via email

Copy link
Contributor

@jasonpaulos jasonpaulos left a 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-commenter
Copy link

codecov-commenter commented Aug 30, 2021

Codecov Report

Merging #2807 (5b60ae6) into master (bd5a000) will increase coverage by 0.28%.
The diff coverage is 71.22%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
data/abi/abi_value.go 38.29% <38.29%> (ø)
data/abi/abi_encode.go 71.63% <71.63%> (ø)
data/abi/abi_type.go 91.81% <91.81%> (ø)
catchup/peerSelector.go 98.95% <0.00%> (-1.05%) ⬇️
catchup/service.go 69.35% <0.00%> (ø)
data/transactions/verify/txn.go 45.08% <0.00%> (ø)
network/wsPeer.go 75.20% <0.00%> (+0.83%) ⬆️
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bd5a000...5b60ae6. Read the comment docs.

@ahangsu ahangsu changed the title Add ABI encoding support to goal Add ABI encoding support Sep 1, 2021
Copy link
Contributor

@jasonpaulos jasonpaulos left a 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

jasonpaulos
jasonpaulos previously approved these changes Sep 22, 2021
Copy link
Contributor

@jasonpaulos jasonpaulos left a 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))
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified.

Comment on lines +119 to +125
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())
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@jannotti jannotti merged commit 7451e3e into master Sep 25, 2021
ahangsu added a commit to algorand/java-algorand-sdk that referenced this pull request Oct 11, 2021
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ABI encoding support to goal
6 participants