F
Flow•12mo ago
joshua

joshua | Flow (2024-01-02)

In Cadence 1.0, how do I get a storage capability that is typed as the type that I set it as? details in 🧵
8 Replies
Needle
Needle•12mo ago
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-cadence
joshua
joshuaOP•12mo ago
in one transaction, I issued a storage capability:
let tokenManagerCapability = sharedAccount
.capabilities.storage.issue<auth(FungibleToken.Withdrawable) &LockedTokens.LockedTokenManager>(
LockedTokens.LockedTokenManagerStoragePath)
let tokenManagerCapability = sharedAccount
.capabilities.storage.issue<auth(FungibleToken.Withdrawable) &LockedTokens.LockedTokenManager>(
LockedTokens.LockedTokenManagerStoragePath)
then in a different transaction, I am trying to get that capability from storage as the type
Capability<auth(FungibleToken.Withdrawable) &LockedTokens.LockedTokenManager>
Capability<auth(FungibleToken.Withdrawable) &LockedTokens.LockedTokenManager>
so I get the controller for it and get the capability from the controller:
let tokenManagerCapabilityController = signer.capabilities.storage.getControllers(forPath: LockedTokens.LockedTokenManagerStoragePath)[0]!
let tokenManagerCapability = tokenManagerCapabilityController.capability
let tokenManagerCapabilityController = signer.capabilities.storage.getControllers(forPath: LockedTokens.LockedTokenManagerStoragePath)[0]!
let tokenManagerCapability = tokenManagerCapabilityController.capability
but the type of the capability is just Capability I need it to be a capability of the type that I issued it as. I can get that type from the controller and I can get the Capability, but I don't know how to combine them
Unknown User
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
joshua
joshuaOP•12mo ago
they are the same signer @sainati | Cadence Do you know? Or do you need more clarification?
Unknown User
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
joshua
joshuaOP•12mo ago
what is the syntax there?
let tokenManagerCapability = tokenManagerCapabilityController.capability as Capability<auth(FungibleToken.Withdrawable) &LockedTokens.LockedTokenManager>
let tokenManagerCapability = tokenManagerCapabilityController.capability as Capability<auth(FungibleToken.Withdrawable) &LockedTokens.LockedTokenManager>
Is that correct? I tried that and still got an error
error: mismatched types
--> 7f4a4e497420d88303fad3865d0a37d3be56ea0a1645b4e91d6a52f9dd8581d3:26:37
|
26 | let tokenManagerCapability = tokenManagerCapabilityController.capability as Capability<auth(FungibleToken.Withdrawable) &LockedTokens.LockedTokenManager>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Capability<auth(FungibleToken.Withdrawable) &LockedTokens.LockedTokenManager>`, got `Capability`
error: mismatched types
--> 7f4a4e497420d88303fad3865d0a37d3be56ea0a1645b4e91d6a52f9dd8581d3:26:37
|
26 | let tokenManagerCapability = tokenManagerCapabilityController.capability as Capability<auth(FungibleToken.Withdrawable) &LockedTokens.LockedTokenManager>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Capability<auth(FungibleToken.Withdrawable) &LockedTokens.LockedTokenManager>`, got `Capability`
Unknown User
Unknown User•12mo ago
Message Not Public
Sign In & Join Server To View
joshua
joshuaOP•12mo ago
okay, that looks like it worked. Thank you!
Want results from more Discord servers?
Add your server