Skip to content
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
8 changes: 4 additions & 4 deletions nft-provider-aggregator/contracts/NFTProviderAggregator.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ access(all) contract NFTProviderAggregator {

/// Borrow the collection of an NFT located in one of multiple collections through iterating over each collection
///
access(all) view fun borrowNFTCollection(id: UInt64): &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic} {
access(all) view fun borrowNFTCollection(id: UInt64): &{NonFungibleToken.Provider, NonFungibleToken.CollectionPublic}? {
for collectionUUID in self.nftProviderCapabilities.keys {
// Check capabilities can still be borrowed since a NFT provider capability may pass the
// pre-condition checks at the time of being added with the addNFTWithdrawCapability method but
Expand All @@ -204,7 +204,7 @@ access(all) contract NFTProviderAggregator {
}
}
}
panic("missing NFT")
return nil
}

/// Withdraw an NFT located in one of multiple collections through iterating over each collection
Expand All @@ -215,8 +215,8 @@ access(all) contract NFTProviderAggregator {

/// Borrow an NFT located in one of multiple collections through iterating over each collection
///
access(all) view fun borrowNFT(id: UInt64): &{NonFungibleToken.NFT} {
return self.borrowNFTCollection(id: id).borrowNFT(id)!
access(all) view fun borrowNFT(id: UInt64): &{NonFungibleToken.NFT}? {
return self.borrowNFTCollection(id: id)?.borrowNFT(id) ?? nil
}

/// Create and return a Supplier resource
Expand Down
16 changes: 16 additions & 0 deletions nft-provider-aggregator/scripts/aggregator_borrow_nft.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import NFTProviderAggregator from "NFTProviderAggregator"
import NonFungibleToken from "NonFungibleToken"

// Tries to borrow an NFT by ID from the Aggregator resource stored in `address`.
// Returns the NFT's Type identifier if found, nil otherwise.

access(all) fun main(address: Address, nftID: UInt64): &{NonFungibleToken.NFT}? {
let account = getAuthAccount<auth(BorrowValue) &Account>(address)

let aggregator = account.storage.borrow<&NFTProviderAggregator.Aggregator>(
from: NFTProviderAggregator.AggregatorStoragePath
) ?? panic("Aggregator resource not found at ".concat(NFTProviderAggregator.AggregatorStoragePath.toString()))

let nft = aggregator.borrowNFT(id: nftID)
return nft
}
Loading