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

[EVM] Add EVMAddress de/serialization methods #5422

Closed
sisyphusSmiling opened this issue Feb 20, 2024 · 0 comments · Fixed by #5892
Closed

[EVM] Add EVMAddress de/serialization methods #5422

sisyphusSmiling opened this issue Feb 20, 2024 · 0 comments · Fixed by #5892
Labels
enhancement New feature or request Flow EVM

Comments

@sisyphusSmiling
Copy link
Contributor

sisyphusSmiling commented Feb 20, 2024

Problem Definition

Currently, EVMAddress is constructed from a 20 byte array ([UInt8; 20]) which is handled as a different type than a variable length array. This can present difficulty when working with the struct, especially when deserializing an address hex string to an EVMAddress.

Proposed Solution

Implement serialization & deserialization methods in the EVMAddress struct. Consider something like

access(all) struct EVMAddress {
  // ...
  /// Returns the EVM address as a hex string
  access(all) view fun toString(): String
  // ...
}

/// Returns an EVMAddress from the given string or nil if it is not a valid address
access(all) view fun getEVMAddress(from hex: String): EVMAddress?

These are importantly view methods as the values are helpful to include in events and pre- and post-conditions.

Definition of Done

A developer can deserialize an EVMAddress from a string & back

Context

This functionality has impacts for things like running transactions & scripts via CLI. For example, given the simple task of querying an EVM address's balance, a developer would have to create custom serialization (lots of boilerplate, efforts, and error-prone), pass an EVMAddress (not easy to do using CLI), or pass a byte array (not user friendly).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Flow EVM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant