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

New supporting functions for eth-sn-contracts #11

Merged
merged 6 commits into from
Apr 18, 2024

Conversation

Doy-lee
Copy link
Collaborator

@Doy-lee Doy-lee commented Apr 17, 2024

Various tid-bits and fixes for new functionality in the eth-sn-contracts tests

  • Provider::callReadFunction now thunks into Provider::callReadFunctionJSON, the latter which returns the original nlohmann::json object which is more optimal because it allows grabbing the result string by reference saving an allocation.
  • Rename addressFromPrivateKey to secretKeyToAddress[String] and add a version that preserves the binary representation of the address.
  • Update fromHexString and co. to use string_views. This means APIs can take string literals without requiring an allocation, but also allows slices of strings. Some of the C++ hex APIs don't accept string_view and would require an allocation to reconvert it back. I've avoided this by introducing our own hex conversion function.
  • Add some helper string trimming functions
  • Fix padToNBytes not rounding a 0-sized string to N and avoid various allocations in the function by reusing the string object we construct.

Using operator= for the LHS means the string is reassigned instead
of potentially using available capacity in the pre-existing string.
You can use the `insert` or `append` calls to reuse the internal
buffer where possible.
Allow returning of the original JSON object which allows the caller
avoid a memory allocation and compute cost of automatically
converting the JSON to a string. It also the caller to preserve
the JSON structure for lookup. Additionally, the caller can get
references to the underlying data avoiding additional allocations.
Additionally rename the functions to be the format <A>to<B> which
allows parsing of intent from left-to-right.
- Take in string_view where possible to avoid allocations where
  possible
- Since we take string_views, the previous functions used from
  the standard library only worked with strings/or required cstrings
  which are null-terminated, hence we have to transform our
  functions to support length denoted strings as not all
  string_view's are null-terminated.
@darcys22 darcys22 merged commit 9a914dc into oxen-io:master Apr 18, 2024
1 check 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.

2 participants