Skip to content
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

Update the rest of non-account linking docs to Cadence 1.0 #925

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/build/advanced-concepts/metadata-views.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ Each royalty view contains a fungible token receiver capability where royalties
```cadence
access(all) struct Royalty {

access(all) let receiver: Capability<&AnyResource{FungibleToken.Receiver}>
access(all) let receiver: Capability<&{FungibleToken.Receiver}>

access(all) let cut: UFix64
}
Expand Down Expand Up @@ -337,7 +337,8 @@ accepts the seller's desired fungible token by calling
the `receiver.getSupportedVaultTypes(): {Type: Bool}`
function via the `receiver` reference:
```cadence
let royaltyReceiverRef = royalty.receiver.borrow() ?? panic("Could not borrow a reference to the receiver")
let royaltyReceiverRef = royalty.receiver.borrow()
?? panic("Could not borrow a reference to the receiver")
let supportedTypes = receiverRef.getSupportedVaultTypes()
if supportedTypes[**royalty.getType()**] {
// The type is supported, so you can deposit
Expand Down Expand Up @@ -477,8 +478,8 @@ case Type<MetadataViews.NFTCollectionData>():
// where to borrow public capabilities from?
publicPath: ExampleNFT.CollectionPublicPath,
// Important types for how the collection should be linked
publicCollection: Type<&ExampleNFT.Collection{ExampleNFT.ExampleNFTCollectionPublic}>(),
publicLinkedType: Type<&ExampleNFT.Collection{ExampleNFT.ExampleNFTCollectionPublic,NonFungibleToken.CollectionPublic,NonFungibleToken.Receiver,MetadataViews.ResolverCollection}>(),
publicCollection: Type<&ExampleNFT.Collection>(),
publicLinkedType: Type<&ExampleNFT.Collection>(),
// function that can be accessed to create an empty collection for the project
createEmptyCollectionFunction: (fun(): @{NonFungibleToken.Collection} {
return <-ExampleNFT.createEmptyCollection(nftType: Type<@ExampleNFT.NFT>())
Expand Down
4 changes: 2 additions & 2 deletions docs/build/basics/transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ The script section contains instructions for transaction execution. This is a Ca

A transaction includes multiple optional phases `prepare`, `pre`, `execute`, and `post` phase. You can read more about it in the [Cadence reference document on transactions](https://cadence-lang.org/docs/language/transactions). Each phase has a purpose, the two most important phases are `prepare` and `execute`.

In the `prepare` phase, we have access to `AuthAccount` objects, which gives us the power to interact with those accounts. The accounts are called authorizers of transactions, so each account we want to interact with in the `prepare` phase must sign the transaction as an authorizer.
In the `prepare` phase, we have access to `&Account` objects, which gives us the power to interact with those accounts. The accounts are called authorizers of transactions, so each account we want to interact with in the `prepare` phase must sign the transaction as an authorizer.
The `execute` phase does exactly what it says, it executes the main logic of the transaction. This phase is optional, but it is a best practice to add your main transaction logic in the section, so it is explicit.

Again make sure to read Cadence [documentation on transactions](https://cadence-lang.org/docs/language/transactions)
Expand Down Expand Up @@ -70,7 +70,7 @@ A proposal key definition declares the address, key ID, and up-to-date sequence

Authorizers are accounts that authorize a transaction to read and mutate their state. A transaction can specify zero or more authorizers, depending on how many accounts the transaction needs to access.

The number of authorizers on the transaction must match the number of AuthAccount parameters declared in the prepare statement of the Cadence script.
The number of authorizers on the transaction must match the number of &Account parameters declared in the prepare statement of the Cadence script.

Example transaction with multiple authorizers:

Expand Down
16 changes: 10 additions & 6 deletions docs/build/core-contracts/10-nft-storefront.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,15 @@ Providing that a seller's NFT supports the [Royalty Metadata View](https://githu
```cadence
// Check whether the NFT implements the MetadataResolver or not.
if nft.getViews().contains(Type<MetadataViews.Royalties>()) {
// Resolve the royalty view
let royaltiesRef = nft.resolveView(Type<MetadataViews.Royalties>())?? panic("Unable to retrieve the royalties")
// Fetch the royalties.
let royalties = (royaltiesRef as! MetadataViews.Royalties).getRoyalties()
// Append the royalties as the salecut
// Resolve the royalty view
let royaltiesRef = nft.resolveView(Type<MetadataViews.Royalties>())
?? panic("Unable to retrieve the royalties view for the NFT with type "
.concat(nft.getType().identifier).concat(" and ID ")
.concat(nft.id.toString()).concat(".")
// Fetch the royalties.
let royalties = (royaltiesRef as! MetadataViews.Royalties).getRoyalties()

// Append the royalties as the salecut
for royalty in royalties {
self.saleCuts.append(NFTStorefrontV2.SaleCut(receiver: royalty.receiver, amount: royalty.cut * effectiveSaleItemPrice))
totalRoyaltyCut = totalRoyaltyCut + royalty.cut * effectiveSaleItemPrice
Expand Down Expand Up @@ -316,7 +320,7 @@ Cleanup the expired listing by iterating over the provided range of indexes.
**fun `borrowListing()`**

```cadence
fun borrowListing(listingResourceID UInt64): &Listing{ListingPublic}?
fun borrowListing(listingResourceID: UInt64): &{ListingPublic}?
```

borrowListing
Expand Down
23 changes: 23 additions & 0 deletions docs/build/core-contracts/14-burner.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: Flow Burner Contract Address
sidebar_position: 14
sidebar_label: Burner
---

# Contract

The [Burner](https://github.com/onflow/flow-ft/blob/master/contracts/utility/Burner.cdc) contract provides a way for resources to define
custom logic that is executed when the resource is destroyed.
Resources that want to utilize this functionality should implement
the `Burner.Burnable` interface which requires that they include
a `burnCallback()` function that includes the custom logic.

It is recommended that regardless of the resource, all users and developers
should use `Burner.burn()` when destroying a resource instead of `destroy`.

| Network | Contract Address |
| ------- | ------------------------------------------------------------------------------ |
| Cadence Testing Framework | `0x0000000000000001` |
| Emulator | `0xee82856bf20e2aa6` |
| Testnet | [`0x294e44e1ec6993c6`](https://contractbrowser.com/account/0x294e44e1ec6993c6) |
| Mainnet | [`0xd8a7e05a7ac670c0`](https://contractbrowser.com/account/0xd8a7e05a7ac670c0) |
17 changes: 12 additions & 5 deletions docs/build/differences-vs-evm/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import ExampleNFT from 0x2bd9d8989a3352a1
transaction(recipient: Address) {

/// Reference to the receiver's collection
let recipientCollectionRef: &{NonFungibleToken.CollectionPublic}
let recipientCollectionRef: &{NonFungibleToken.Collection}

/// Previous NFT ID before the transaction executes
let mintingIDBefore: UInt64
Expand All @@ -79,9 +79,12 @@ transaction(recipient: Address) {

// Borrow the recipient's public NFT collection reference
self.recipientCollectionRef = getAccount(recipient)
.capabilities.get<&{NonFungibleToken.CollectionPublic}>(ExampleNFT.CollectionPublicPath)
.capabilities.get<&{NonFungibleToken.Collection}>(ExampleNFT.CollectionPublicPath)
.borrow()
?? panic("Could not get receiver reference to the NFT Collection")
?? panic("The recipient does not have a NonFungibleToken Receiver at "
.concat(ExampleNFT.CollectionPublicPath.toString())
.concat(" that is capable of receiving an NFT.")
.concat("The recipient must initialize their account with this collection and receiver first!"))

}

Expand Down Expand Up @@ -127,9 +130,13 @@ access(all) fun main(address: Address, collectionPublicPath: PublicPath): [UInt6
let account = getAccount(address)

let collectionRef = account
.capabilities.get<&{NonFungibleToken.CollectionPublic}>(collectionPublicPath)
.capabilities.get<&{NonFungibleToken.Collection}>(collectionPublicPath)
.borrow()
?? panic("Could not borrow capability from public collection at specified path")
?? panic("The account with address "
.concat(address.toString())
.concat("does not have a NonFungibleToken Collection at "
.concat(ExampleNFT.CollectionPublicPath.toString())
.concat(". The account must initialize their account with this collection first!")))

return collectionRef.getIDs()

Expand Down
5 changes: 2 additions & 3 deletions docs/build/getting-started/quickstarts/flow-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ This will create a file called `ReadGreeting.cdc` in the `cadence/scripts` direc
```
import "HelloWorld"

access(all)
fun main(): String {
access(all) fun main(): String {
return HelloWorld.greeting
}
```
Expand Down Expand Up @@ -141,7 +140,7 @@ import "HelloWorld"

transaction(greeting: String) {

prepare(acct: AuthAccount) {
prepare(acct: &Account) {
log(acct.address)
}

Expand Down
32 changes: 16 additions & 16 deletions docs/build/guides/account-linking/child-accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ import "FlowToken"

transaction(pubKey: String, initialFundingAmt: UFix64) {

prepare(signer: AuthAccount) {
prepare(signer: &Account) {

/* --- Account Creation --- */
// **NOTE:** your app may choose to separate creation depending on your custodial model)
Expand All @@ -454,11 +454,11 @@ transaction(pubKey: String, initialFundingAmt: UFix64) {
// Fund the new account if specified
if initialFundingAmt > 0.0 {
// Get a vault to fund the new account
let fundingProvider = signer.borrow<&FlowToken.Vault{FungibleToken.Provider}>(
let fundingProvider = signer.borrow<&FlowToken.Vault>(
from: /storage/flowTokenVault
)!
// Fund the new account with the initialFundingAmount specified
newAccount.getCapability<&FlowToken.Vault{FungibleToken.Receiver}>(
newAccount.capabilities.get<&FlowToken.Vault>(
/public/flowTokenReceiver
).borrow()!
.deposit(
Expand Down Expand Up @@ -522,7 +522,7 @@ transaction(
filterAddress: Address
) {

prepare(parent: AuthAccount, app: AuthAccount) {
prepare(parent: auth(Storage) &Account, app: auth(Storage) &Account) {
/* --- Account Creation --- */
//
// Create the child account, funding via the signing app account
Expand All @@ -546,11 +546,11 @@ transaction(
// Fund the new account if specified
if initialFundingAmt > 0.0 {
// Get a vault to fund the new account
let fundingProvider = app.borrow<&FlowToken.Vault{FungibleToken.Provider}>(
let fundingProvider = app.borrow<&FlowToken.Vault}>(
from: /storage/flowTokenVault
)!
// Fund the new account with the initialFundingAmount specified
newAccount.getCapability<&FlowToken.Vault{FungibleToken.Receiver}>(/public/flowTokenReceiver)
newAccount.capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver)
.borrow()!
.deposit(
from: <-fundingProvider.withdraw(
Expand All @@ -572,14 +572,14 @@ transaction(

// Create a OwnedAccount & link Capabilities
let ownedAccount <- HybridCustody.createOwnedAccount(acct: acctCap)
newAccount.save(<-ownedAccount, to: HybridCustody.OwnedAccountStoragePath)
newAccount.storage.save(<-ownedAccount, to: HybridCustody.OwnedAccountStoragePath)
newAccount
.link<&HybridCustody.OwnedAccount{HybridCustody.BorrowableAccount, HybridCustody.OwnedAccountPublic, MetadataViews.Resolver}>(
.link<&HybridCustody.OwnedAccount>(
HybridCustody.OwnedAccountPrivatePath,
target: HybridCustody.OwnedAccountStoragePath
)
newAccount
.link<&HybridCustody.OwnedAccount{HybridCustody.OwnedAccountPublic}>(
.link<&HybridCustody.OwnedAccount>(
HybridCustody.OwnedAccountPublicPath,
target: HybridCustody.OwnedAccountStoragePath
)
Expand All @@ -589,13 +589,13 @@ transaction(

// Get the CapabilityFactory.Manager Capability
let factory = getAccount(factoryAddress)
.getCapability<&CapabilityFactory.Manager{CapabilityFactory.Getter}>(
.getCapability<&CapabilityFactory.Manager>(
CapabilityFactory.PublicPath
)
assert(factory.check(), message: "factory address is not configured properly")

// Get the CapabilityFilter.Filter Capability
let filter = getAccount(filterAddress).getCapability<&{CapabilityFilter.Filter}>(CapabilityFilter.PublicPath)
let filter = getAccount(filterAddress).capabilities.get<&{CapabilityFilter.Filter}>(CapabilityFilter.PublicPath)
assert(filter.check(), message: "capability filter is not configured properly")

// Configure access for the delegatee parent account
Expand All @@ -612,11 +612,11 @@ transaction(
// Link Capabilities
parent.unlink(HybridCustody.ManagerPublicPath)
parent.unlink(HybridCustody.ManagerPrivatePath)
parent.link<&HybridCustody.Manager{HybridCustody.ManagerPrivate, HybridCustody.ManagerPublic}>(
parent.link<&HybridCustody.Manager>(
HybridCustody.ManagerPrivatePath,
target: HybridCustody.ManagerStoragePath
)
parent.link<&HybridCustody.Manager{HybridCustody.ManagerPublic}>(
parent.link<&HybridCustody.Manager>(
HybridCustody.ManagerPublicPath,
target: HybridCustody.ManagerStoragePath
)
Expand All @@ -625,14 +625,14 @@ transaction(
let inboxName = HybridCustody.getChildAccountIdentifier(parent.address)
let cap = parent
.inbox
.claim<&HybridCustody.ChildAccount{HybridCustody.AccountPrivate, HybridCustody.AccountPublic, MetadataViews.Resolver}>(
.claim<&HybridCustody.ChildAccount>(
inboxName,
provider: newAccount.address
) ?? panic("child account cap not found")

// Get a reference to the Manager and add the account
let managerRef = parent.borrow<&HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath)
?? panic("manager no found")
let managerRef = parent.storage.borrow<&HybridCustody.Manager>(from: HybridCustody.ManagerStoragePath)
?? panic("manager not found")
managerRef.addAccount(cap: cap)
}
}
Expand Down
22 changes: 16 additions & 6 deletions docs/build/guides/fungible-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -929,12 +929,14 @@ import "FungibleTokenMetadataViews"

access(all) fun main(address: Address): UFix64 {
let vaultData = FooToken.resolveContractView(resourceType: nil, viewType: Type<FungibleTokenMetadataViews.FTVaultData>()) as! FungibleTokenMetadataViews.FTVaultData?
?? panic("Could not get vault data view for the contract")
?? panic("Could not get FTVaultData view for the FooToken contract")

return getAccount(address).capabilities.borrow<&{FungibleToken.Balance}>(
vaultData.metadataPath
)?.balance
?? panic("Could not borrow Balance reference to the Vault")
?? panic("Could not borrow a reference to the FooToken Vault in account "
.concat(address.toString()).concat(" at path ").concat(vaultData.metadataPath.toString())
.concat(". Make sure you are querying an address that has an FooToken Vault set up properly."))
}
```

Expand Down Expand Up @@ -979,10 +981,13 @@ transaction(recipient: Address, amount: UFix64) {

// Borrow a reference to the admin object
self.tokenMinter = signer.storage.borrow<&FooToken.Minter>(from: FooToken.MinterStoragePath)
?? panic("Signer is not the token admin")
?? panic("Cannot mint: Signer does not store the FooToken Minter in their account!")

self.tokenReceiver = getAccount(recipient).capabilities.borrow<&{FungibleToken.Receiver}>(FooToken.VaultPublicPath)
?? panic("Could not borrow receiver reference to the Vault")
?? panic("Could not borrow a Receiver reference to the FungibleToken Vault in account "
.concat(recipient.toString()).concat(" at path ").concat(FooToken.VaultPublicPath.toString())
.concat(". Make sure you are sending to an address that has ")
.concat("a FungibleToken Vault set up properly at the specified path."))
}

execute {
Expand Down Expand Up @@ -1039,7 +1044,9 @@ transaction(to: Address, amount: UFix64) {

// Get a reference to the signer's stored vault
let vaultRef = signer.storage.borrow<auth(FungibleToken.Withdraw) &FooToken.Vault>(from: FooToken.VaultStoragePath)
?? panic("Could not borrow reference to the owner's Vault!")
?? panic("The signer does not store an FooToken.Vault object at the path "
.concat(FooToken.VaultStoragePath.toString())
.concat(". The signer must initialize their account with this vault first!"))

// Withdraw tokens from the signer's stored vault
self.sentVault <- vaultRef.withdraw(amount: amount)
Expand All @@ -1052,7 +1059,10 @@ transaction(to: Address, amount: UFix64) {

// Get a reference to the recipient's Receiver
let receiverRef = recipient.capabilities.borrow<&{FungibleToken.Receiver}>(FooToken.VaultPublicPath)
?? panic("Could not borrow receiver reference to the recipient's Vault")
?? panic("Could not borrow a Receiver reference to the FooToken Vault in account "
.concat(recipient.toString()).concat(" at path ").concat(FooToken.VaultPublicPath.toString())
.concat(". Make sure you are sending to an address that has ")
.concat("a FooToken Vault set up properly at the specified path."))

// Deposit the withdrawn tokens in the recipient's receiver
receiverRef.deposit(from: <-self.sentVault)
Expand Down
Loading
Loading