This repository has been archived by the owner on Mar 20, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Work towards #128.
This is mostly-complete support for serialization and deserialization in the runtime. The patch is not perfect, and some types still do not work, but I am posting it to begin review, and possibly to merge it to unblock others' work.
As discussed on the issue, we don't necessarily need to use bcs, and because the available bcs crates don't quite fulfill our needs, I have instead used borsh here, which is mature, compact, and has a stable spec. We can open another issue about finalizing the serialization format before a release.
For testing purposes this adds a native function that can be named as
std::bcs::test_from_bytes
. This function is not part of the standard library, but when declared correctly is accessible to move code.This required adding a second
U256
type, calledU256Placeholder
here, in order to deriveBorshSerialize
/Deserialize
against it. There are unsafe casts between vectors of the two u256 types. In the future we might use our ownU256
type everywhere instead of splitting uses betweenethnum::U256
and our own.The only cases not completed are:
vector<vector<T>>
,vector<struct>
, and reference. The vector cases I will complete soon. The reference case I imagine is unreachable and is marked as such.Some test cases fail because of other errors in the compiler. They are commented out with a fixme.