-
Notifications
You must be signed in to change notification settings - Fork 138
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
Add functionality to view all public declarations in a contract and introspect Type values for interface conformance #2201
Comments
This is a blocker for the implementation of the NFT V2 spec, due to the fact that it replaces the proposed requirement that contract developers manually export a list of all NFT's. |
Maybe split this issue into two, e.g. by making this an epic and creating two sub-issues, as two separate features are proposed:
|
Re: introspection for types of a contract: Those new definitions can be computed fields, e.g. |
I'm not sure we need I'd be inclined to start with a single function that returns the publicly defined types (structs and resources). Over time, I'm sure we'll add additional introspection functionality, but the MVP can be a simple list of data types, I think. (My hunch is that it's inappropriate to be able to query privately declared types, even in some future version of introspection. But I could probably be convinced otherwise!) FWIW- My preference is a function that returns an array vs. a global field, since a global field "looks" mutable (and attempts to modify that array will only fail dynamically, I believe). |
Nice change! |
yeah, I go over the subtype thing a little bit. But my personal opinion is that adding a specific function for checking interface conformance is more clear than using a dummy restricted type. There's also some talks of overhauling/removing restricted types entirely with the proposed |
I love the snappy title of this EPIC |
#2233 is nice to have, not blocking new FT/NFT standards |
Old Zenhub EPIC, closing, just keeping the #2233 issue open |
Issue To Be Solved
Per an internal conversation with Dete, the new NFT proposal requires developers to add a method on their contract that returns all the NFT types defined in the contract. This is error-prone and manual, so it would be nice to include some introspection mechanism in Cadence to save developers from having to enumerate these by hand.
Suggested Solution
We currently expose
.contracts.names: [String]
onAuthAccount
andPublicAccount
, but not much else. This issue proposes an extension method on{Auth,Public}Account.contracts
:that returns a list of all decls (functions, structs, interfaces, resources, etc.) in the contract. Alternatively, we could split each of those different declaration types into their own getters (this example uses dictionaries, but we could simply return an array instead since
Type
s carry theidentifier
s of their proxied types):By adding these features, developers can query a contract for all its declared structs. The second part of the problem is filtering through these declarations to find out which types actually conform to the NFT interface.
Currently,
Type
values only have two members:identifer: String
andfun isSubType(of otherType: Type): Bool
. In order to simplify the NFT V2 spec,Type
values should have a methodthat performs a runtime interface check on the type. This is doable in Cadence itself, e.g.
but ideally, a way should be provided for an interface type to be provided directly. Currently, attempting to instantiate a
Type
object with an interface givesInterfaces exist in the type namespace, so a new proxy type
Interface
could serve as the equivalent for interfaces whatType
is to types.With this,
conformsToInterface
could have the signatureThe text was updated successfully, but these errors were encountered: