-
Notifications
You must be signed in to change notification settings - Fork 131
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
Support Equatable
or HashableStruct
subtypes
#3246
Comments
Equatable
or HashablStruct
subtypesEquatable
or HashableStruct
subtypes
This was a previously proposed feature: d3191a3#diff-75060942f377544ff403d04b6d3691f7cfeca9f76fea62c8b5c8b1a858a6f555L555-L707 Adding Exposing |
I think this is very very hard, if not impossible. |
One other aspect I can think of is the type changing / being updated |
@bluesign How so? Because of the type input requirement I noted above, or because of something else? |
same problem stays if we give some data as hashInput on Cadence side too, what happens if I change the hashInput function. |
@bluesign good point, this isn't possible with any of the current features of Cadence. What if we had a function modifier called Returning to the concrete case of the access(all) struct EVMAddress: Addressable, HashableStruct {
access(all) let bytes: [UInt8; 20]
// ...
access(all) immutable fun hash(): String {
return self.bytes.toVariableSizedArray().encodeHex()
}
} I don't know if the effort required to implement the |
Issue to be solved
Dictionary values must be hashable and equatable. With Cadence 1.0, there was the introduction of the
HashableStruct
super type, however the implementation ofHashableStruct
is limited to a subset of primitive types.It would be very helpful for anyone to be able to define a type that conforms to
HashableStruct
or at leastEquatableStruct
if it existed. One such use case is theEVMAddress
type. In both Solidity and Cadence, it's a common pattern to index mappings on addresses. With the introduction of Flow EVM, it would be very useful to also index mappings onEVMAddress
but this is not possible at the moment as the type is not hashable or equatable.More broadly, it would be even more useful to leverage the implementation of
HashableStruct
to define custom comparators, but that might be too broad of a scope for this single issue.Suggested Solution
Perhaps
HashableStruct
could be a native interface or an FVM contract (likeCrypto
) could be introduced to house similar interfaces which a type could implement with a single method, such as:In the concrete use case mentioned above of
EVMAddress
, this would look like:The text was updated successfully, but these errors were encountered: