-
Notifications
You must be signed in to change notification settings - Fork 8
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(abi)!: add a readme and some quality of life code changes to abi #219
base: main
Are you sure you want to change the base?
Conversation
Code Coverage SummaryClick to see the summary
Click to see the extended report
|
move/abi/sources/abi.move
Outdated
self.head = head; | ||
|
||
var | ||
} | ||
|
||
public fun read_bytes_raw(self: &mut AbiReader): vector<u8> { |
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.
can you add this in a separate PR? The code refactor and feature addition are independent. Code refactor can be reviewed and merged in quicker, while the new methods can require further review
move/abi/sources/abi.move
Outdated
public fun read_bytes_raw(self: &mut AbiReader): vector<u8> { | ||
// Move position to the start of the bytes | ||
let offset = self.read_u256() as u64; | ||
let length = self.bytes.length() - offset; |
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 reading the full bytes until the end. What if you there are multiple encoded structs?
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.
if it's only meant to support a single one, then it should consume the reader so it can't be used again
maybe it can return the new reader itself
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.
It is not supposed to include only one, but there is no way for us to know up to what point the raw bytes are actually the struct the user needs. For example, assume someone encodes a struct
{var1:u256
, var2:u256
} followed by some data: bytes
. The encoded data will look like this: [offset1 = 64, offset2=128, var1, var2, data.length, data]
. There is no way to know where the struct
ends and where the data
begins. If however the struct is the last variable length variable encoded, then it will take up all of the remaining bytes. This is why we return everything and expect the user to decode only as much as they need (knowing the format of the data is required, and it will tell the user where to stop.)
move/abi/sources/abi.move
Outdated
writer.write_bytes_raw(struct_writer.into_bytes()); | ||
|
||
let bytes = writer.into_bytes(); | ||
|
||
let mut reader = new_reader(bytes); | ||
|
||
let struct_bytes = reader.read_bytes_raw(); | ||
|
||
let mut struct_reader = new_reader(struct_bytes); |
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.
write_bytes_raw(..)
-> new_writer_wrapper(struct_writer)
something like this? new_writer_from_writer
, new_writer_nested
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.
not always the case unfortunately: for structs another writer would be desirable, since the raw bytes are just some abi encoded bytes. For vectors on the other hand the raw bytes consist of the length, followed by some encoded bytes (where the encoding starts matters for offsets).
add missing coverage as well
|
Co-authored-by: Milap Sheth <[email protected]>
Co-authored-by: Milap Sheth <[email protected]>
Co-authored-by: Milap Sheth <[email protected]>
Co-authored-by: Milap Sheth <[email protected]>
Co-authored-by: Milap Sheth <[email protected]>
Co-authored-by: Milap Sheth <[email protected]>
This was caused by changes you made, please add coverage yourself before merging. |
AXE-6765