diff --git a/docs/language/accounts/capabilities.mdx b/docs/language/accounts/capabilities.mdx index 5dee7cc..66adab6 100644 --- a/docs/language/accounts/capabilities.mdx +++ b/docs/language/accounts/capabilities.mdx @@ -23,14 +23,15 @@ struct Capabilities { let account: Account.AccountCapabilities /// Returns the capability at the given public path. - /// Returns nil if the capability does not exist, - /// or if the given type is not a supertype of the capability's borrow type. + /// If the capability does not exist, + /// or if the given type is not a supertype of the capability's borrow type, + /// returns an "invalid" capability with ID 0 that will always fail to `check` or `borrow` access(all) - view fun get(_ path: PublicPath): Capability? + view fun get(_ path: PublicPath): Capability /// Borrows the capability at the given public path. /// Returns nil if the capability does not exist, or cannot be borrowed using the given type. - /// The function is equivalent to `get(path)?.borrow()`. + /// The function is equivalent to `get(path).borrow()`. access(all) view fun borrow(_ path: PublicPath): T? @@ -80,15 +81,15 @@ that was [published](#publishing-capabilities) before. ```cadence access(all) -view fun get(_ path: PublicPath): Capability? +view fun get(_ path: PublicPath): Capability ``` If the account has a capability with the given type published under the given path, -the function returns it as an optional. +the function returns it. If the account has no capability published under the given path, -or the requested type, via the type parameter `T`, does not match the published capability, -the function returns `nil`. +or if the given type is not a supertype of the capability's borrow type, +the function returns an "invalid" capability with ID 0 that will always fail to `check` or `borrow`. The convenience function `capabilities.borrow` obtains and borrows a public capability that was [published](#publishing-capabilities) before, in one step. @@ -136,6 +137,10 @@ struct StorageCapabilities { access(Capabilities | StorageCapabilities | IssueStorageCapabilityController) fun issue(_ path: StoragePath): Capability + /// Issue/create a new storage capability. + access(Capabilities | StorageCapabilities | IssueStorageCapabilityController) + fun issueWithType(_ path: StoragePath, type: Type): Capability + /// Get the storage capability controller for the capability with the specified ID. /// /// Returns nil if the ID does not reference an existing storage capability. @@ -170,6 +175,10 @@ struct AccountCapabilities { access(Capabilities | AccountCapabilities | IssueAccountCapabilityController) fun issue(): Capability + /// Issue/create a new account capability. + access(Capabilities | AccountCapabilities | IssueAccountCapabilityController) + fun issueWithType(_ type: Type): Capability + /// Get capability controller for capability with the specified ID. /// /// Returns nil if the ID does not reference an existing account capability.