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

Implementing proper generics for ABI encoding/decoding #738

Open
JeneaVranceanu opened this issue Jan 22, 2023 · 0 comments
Open

Implementing proper generics for ABI encoding/decoding #738

JeneaVranceanu opened this issue Jan 22, 2023 · 0 comments
Labels
4.0 enhancement New feature or request

Comments

@JeneaVranceanu
Copy link
Collaborator

What context is your feature request related to?

Implementing proper generics across the library instead of using Any for encoding and decoding functions. This task is based on discussions from #725

What solution would you like?

An example of using multiple types for encoding is RLP.encode function. This function accepts an array that can hold by itself single values like Data but also nested arrays.

For example lets imagine this solution:

internal static func encode<T: Web3DataType>(_ elements: [T?]) -> Data? {
    ...
}

Where Web3DataType is the protocol that has:

/// Binary representation. Used in the ABI encoding process.
func serialize() -> Data

But we still must account for nested arrays, like in the case of RLP.encode. It can legally be [T, T, [T, [T]]] and we must be able to encode it.

@yaroslavyaroslav has suggested using the feature added in Swift 5.7:

also worth to say that swift 5.7 provides a solution for exact that cases (scroll to the "Unlock existentials for all protocols"), but I'd suggest to not belongs on it yet, since it's not having backward capability. But in 5.7 the following code are legal:

let tvShow: [any Equatable] = ["Brooklyn", 99]

I've got a post right about that https://yaroslavyaroslav.github.io/posts/generic-protocol-workaround/ based on the solution that I've implemented whithin 3.0.0 release.

Any additional context?

No response

@JeneaVranceanu JeneaVranceanu added enhancement New feature or request 4.0 labels Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.0 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant