joshua | Flow (2023-11-21)
Anyone know where the documentation for authorized references to primitive types in Cadence 1.0 is? I'm working on updating the latest changes to the epoch smart contracts to Cadence 1.0 and running into a lot of issues that I'm very confused about, like references needing to be
auth (Insert, Mutate, or Remove)
13 Replies
I've created a thread for your message. Please continue any relevant discussion in this thread.
You can rename this thread using
/title <new title>
If this is a technical question that others may benefit from, considering also asking it on Stackoverflow: https://stackoverflow.com/questions/ask?tags=onflow-cadenceThe documentation moved to the website, https://cadence-lang.org, and you can select 1.0 from the top-right
The documentation for built-in entitlements can be found here: https://cadence-lang.org/docs/1.0/language/access-control#built-in-mutability-entitlements
and (authorized) references are documented here: https://cadence-lang.org/docs/1.0/language/references
what kinds of issues are you running into? what are you confused about?
please let the team know if you find gaps in the documentation, or have suggestions!
There's also a vision document explaining how the individual FLIPs tie in with each other: https://github.com/onflow/flips/blob/main/cadence/vision/mutability-restrictions.md
thank you! I guess I missed that there was a 1.0 section of the docs site now.
Is a dictionary considered a primitive type?
I'm trying to borrow references to dictionaries of dictionaries (
&{String: {UInt32: Bool}}
) that are stored in account storage. I understand I have to borrow them as auth(Insert, Mutate, Remove)
, but when I try to access a value in the inner dictionary, it returns a reference to it, but it isn't an entitled reference, so I can't do anything do it, but I'm not sure how I can create an entitled reference to it. it looks like normally I would use entitlement mappings, but I haven't figured out how to use an entitlement mapping on a dictionary type that I store in account storage instead of a field on a composite type
this is an example of what I'm trying to do:
But I get the error that I can't assign to the non-auth reference, since existingDelegatorList
is a reference to a dictionary now instead of just a dictionary
but I don't think I can do this, right?
since only the owner can create authorized references?
so if I can't create the authorized reference there, then it seems like an entitlement mapping is the way to go, but I don't know how to specify or create that for a value in account storageUnknown User•13mo ago
Message Not Public
Sign In & Join Server To View
that is way too expensive though
Or do you mean copy the inner dictionary?
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
How?
Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View
I'll try
remove
, that might work
yeah, seems like the built in entitlements for built in types should apply to child dictionaries and arrays
it looks like remove
works for now, but it still would be good to know if what I am trying to do with only references worksUnknown User•13mo ago
Message Not Public
Sign In & Join Server To View
thank you! So is there no way to get around this with the current behavior, like with using entitlement mappings?
or is the only way to just use
.remove
?Unknown User•13mo ago
Message Not Public
Sign In & Join Server To View