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

Implement ctx.Identity for C# #2091

Merged
merged 8 commits into from
Jan 7, 2025
Merged

Implement ctx.Identity for C# #2091

merged 8 commits into from
Jan 7, 2025

Conversation

RReverser
Copy link
Contributor

Description of Changes

Fixes #2089.

Since C# doesn't have fixed-size arrays available to safe code, I decided it's simpler to accept a pointer to Identity itself. It's stored as little-endian anyway, so the only change that was necessary is to mark the struct as FFI-compatible. The actual FFI declaration for identity looks a bit different from others for .NET reasons - see comment on the declaration for more details, but the code itself is still pretty simply.

Marking the struct as FFI-compatible also allowed to remove a bunch of helpers, casts and intermediate allocations, since we can now read/write Identity and Address directly instead of reaching into their internal representation.

For testing, I moved the Rust-specific integration test from smoketests to our "standalone integration test" which runs for both Rust and C#, and implemented C# counterpart to it.

API and ABI breaking changes

If this is an API or ABI breaking change, please apply the
corresponding GitHub label.

Expected complexity level and risk

1

How complicated do you think these changes are? Grade on a scale from 1 to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex change.

This complexity rating applies not only to the complexity apparent in the diff,
but also to its interactions with existing and future code.

If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning ways.

Testing

Describe any testing you've done, and any testing you'd like your reviewers to do,
so that you're confident that all the changes work as expected!

  • Ran relevant standalone integration tests and fixed the issues.

Now that Identity and Address are FFI-safe structs, we can simplify read/write operations to work on them directly rather than on the underlying U128/U256 structs.

This allows to remove some wrappers, helpers and allocations.
This is now covered by integration tests for both Rust and C#.
@RReverser RReverser requested review from kazimuth and gefjon January 7, 2025 16:59
We need to always go through the same checks as FromBigEndian anyway, so might as well reuse it.
Copy link
Contributor

@gefjon gefjon left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for calling out that you moved the test in your PR description; that saved me a lot of confusion.

@RReverser RReverser added this pull request to the merge queue Jan 7, 2025
Merged via the queue into master with commit 40faad6 Jan 7, 2025
7 of 8 checks passed
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.

Implement ctx.Identity getter in C# modules
2 participants