Skip to content

Commit

Permalink
re-add royalties to mint and address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahannan committed Apr 1, 2024
1 parent 1b8384e commit 067c816
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 50 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,16 @@ If you want to test out these contracts, we recommend either testing them
with the [Flow Playground](https://play.flow.com)
or with the [Visual Studio Code Extension](https://github.com/onflow/flow/blob/master/docs/vscode-extension.md#cadence-visual-studio-code-extension).

The steps to follow are:
If you are not making/testing any modifications to the standard contracts,
they are already deployed to the addresses listed above and you can just import
from those directly instead of deploying them yourself.

If you want to test changes to the standards, the steps to follow are:

1. Deploy `ViewResolver.cdc`
2. Deploy `NonFungibleToken.cdc`, importing `ViewResolver`.
3. Deploy `ExampleNFT.cdc`, importing `NonFungibleToken`.

If you are not making any modifications to the standard contracts,
they are already deployed to the addresses listed above and you can just import
from those directly instead of deploying them yourself.

Then you can experiment with some of the other transactions and scripts in `transactions/`
or even write your own. You'll need to replace some of the import address placeholders with addresses that you deploy to, as well as some of the transaction arguments.

Expand Down
4 changes: 2 additions & 2 deletions contracts/MetadataViews.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ access(all) contract MetadataViews {
/// Helper to get License in a typesafe way
///
/// @param viewResolver: A reference to the resolver resource
/// @return A optional License struct
/// @return An optional License struct
///
access(all) fun getLicense(_ viewResolver: &{ViewResolver.Resolver}) : License? {
if let view = viewResolver.resolveView(Type<License>()) {
Expand All @@ -212,7 +212,7 @@ access(all) contract MetadataViews {
/// Helper to get ExternalURL in a typesafe way
///
/// @param viewResolver: A reference to the resolver resource
/// @return A optional ExternalURL struct
/// @return An optional ExternalURL struct
///
access(all) fun getExternalURL(_ viewResolver: &{ViewResolver.Resolver}) : ExternalURL? {
if let view = viewResolver.resolveView(Type<ExternalURL>()) {
Expand Down
6 changes: 3 additions & 3 deletions lib/go/contracts/internal/assets/assets.go

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions lib/go/templates/internal/assets/assets.go

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions tests/test_example_nft.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ fun testSetupAccount() {

access(all)
fun testMintNFT() {
// var txResult = executeTransaction(
// "../transactions/setup_account_to_receive_royalty.cdc",
// [/storage/flowTokenVault],
// admin
// )
// Test.expect(txResult, Test.beSucceeded())
var txResult = executeTransaction(
"../transactions/setup_account_to_receive_royalty.cdc",
[/storage/flowTokenVault],
admin
)
Test.expect(txResult, Test.beSucceeded())

txResult = executeTransaction(
"../transactions/mint_nft.cdc",
[
recipient.address,
Expand Down
16 changes: 8 additions & 8 deletions tests/nft_forwarding_tests.cdc → tests/test_nft_forwarding.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ access(all) fun testMintNFT() {

let expectedCollectionLength: Int = 1

// let royaltySetupSuccess: Bool = txExecutor(
// "setup_account_to_receive_royalty.cdc",
// [admin],
// [/storage/flowTokenVault],
// nil,
// nil
// )
// Test.assertEqual(true, royaltySetupSuccess)
let royaltySetupSuccess: Bool = txExecutor(
"setup_account_to_receive_royalty.cdc",
[admin],
[/storage/flowTokenVault],
nil,
nil
)
Test.assertEqual(true, royaltySetupSuccess)

// Minting to forwarder should forward minted NFT to recipient
let mintSuccess: Bool = txExecutor(
Expand Down
38 changes: 20 additions & 18 deletions transactions/mint_nft.cdc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/// This script uses the NFTMinter resource to mint a new NFT
/// It must be run with the account that has the minter resource
/// stored in /storage/NFTMinter
///
/// The royalty arguments indicies must be aligned
import "NonFungibleToken"
import "ExampleNFT"
Expand Down Expand Up @@ -44,32 +46,32 @@ transaction(

execute {

// // Create the royalty details
// var count = 0
// var royalties: [MetadataViews.Royalty] = []
// while royaltyBeneficiaries.length > count {
// let beneficiary = royaltyBeneficiaries[count]
// let beneficiaryCapability = getAccount(beneficiary).capabilities.get<&{FungibleToken.Receiver}>(
// MetadataViews.getRoyaltyReceiverPublicPath()
// ) ?? panic("Beneficiary does not have Receiver configured at RoyaltyReceiverPublicPath")
// Create the royalty details
var count = 0
var royalties: [MetadataViews.Royalty] = []
while royaltyBeneficiaries.length > count {
let beneficiary = royaltyBeneficiaries[count]
let beneficiaryCapability = getAccount(beneficiary).capabilities.get<&{FungibleToken.Receiver}>(
MetadataViews.getRoyaltyReceiverPublicPath()
) ?? panic("Beneficiary does not have Receiver configured at RoyaltyReceiverPublicPath")

// royalties.append(
// MetadataViews.Royalty(
// receiver: beneficiaryCapability,
// cut: cuts[count],
// description: royaltyDescriptions[count]
// )
// )
// count = count + 1
// }
royalties.append(
MetadataViews.Royalty(
receiver: beneficiaryCapability,
cut: cuts[count],
description: royaltyDescriptions[count]
)
)
count = count + 1
}


// Mint the NFT and deposit it to the recipient's collection
let mintedNFT <- self.minter.mintNFT(
name: name,
description: description,
thumbnail: thumbnail,
royalties: [] //royalties
royalties: royalties
)
self.recipientCollectionRef.deposit(token: <-mintedNFT)
}
Expand Down
6 changes: 5 additions & 1 deletion transactions/setup_account_to_receive_royalty.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ transaction(vaultPath: StoragePath) {
prepare(signer: auth(BorrowValue, IssueStorageCapabilityController, PublishCapability, UnpublishCapability) &Account) {

// Return early if the account doesn't have a FungibleToken Vault
if signer.storage.borrow<&{FungibleToken.Receiver}>(from: vaultPath) == nil {
// if !signer.storage.check<&{FungibleToken.Vault}>(from: vaultPath) {
// panic("A vault for the specified fungible token path does not exist")
// }
if signer.storage.type(at: vaultPath) == nil {
panic("A vault for the specified fungible token path does not exist")
}

Expand Down

0 comments on commit 067c816

Please sign in to comment.