File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -180,7 +180,7 @@ access(all) contract NFTProviderAggregator {
180180
181181 /// Borrow the collection of an NFT located in one of multiple collections through iterating over each collection
182182 ///
183- access (all ) view fun borrowNFTCollection (id : UInt64 ): &{NonFungibleToken .Provider , NonFungibleToken .CollectionPublic } {
183+ access (all ) view fun borrowNFTCollection (id : UInt64 ): &{NonFungibleToken .Provider , NonFungibleToken .CollectionPublic }? {
184184 for collectionUUID in self .nftProviderCapabilities .keys {
185185 // Check capabilities can still be borrowed since a NFT provider capability may pass the
186186 // pre-condition checks at the time of being added with the addNFTWithdrawCapability method but
@@ -204,7 +204,7 @@ access(all) contract NFTProviderAggregator {
204204 }
205205 }
206206 }
207- panic ( " missing NFT " )
207+ return nil
208208 }
209209
210210 /// Withdraw an NFT located in one of multiple collections through iterating over each collection
@@ -215,8 +215,8 @@ access(all) contract NFTProviderAggregator {
215215
216216 /// Borrow an NFT located in one of multiple collections through iterating over each collection
217217 ///
218- access (all ) view fun borrowNFT (id : UInt64 ): &{NonFungibleToken .NFT } {
219- return self .borrowNFTCollection (id : id ).borrowNFT (id )!
218+ access (all ) view fun borrowNFT (id : UInt64 ): &{NonFungibleToken .NFT }? {
219+ return self .borrowNFTCollection (id : id )? .borrowNFT (id ) ?? nil
220220 }
221221
222222 /// Create and return a Supplier resource
Original file line number Diff line number Diff line change 1+ import NFTProviderAggregator from " NFTProviderAggregator"
2+ import NonFungibleToken from " NonFungibleToken"
3+
4+ // Tries to borrow an NFT by ID from the Aggregator resource stored in `address`.
5+ // Returns the NFT's Type identifier if found, nil otherwise.
6+
7+ access (all ) fun main (address : Address , nftID : UInt64 ): &{NonFungibleToken .NFT }? {
8+ let account = getAuthAccount <auth (BorrowValue ) &Account >(address )
9+
10+ let aggregator = account .storage .borrow <&NFTProviderAggregator.Aggregator >(
11+ from : NFTProviderAggregator .AggregatorStoragePath
12+ ) ?? panic (" Aggregator resource not found at " .concat (NFTProviderAggregator .AggregatorStoragePath .toString ()))
13+
14+ let nft = aggregator .borrowNFT (id : nftID )
15+ return nft
16+ }
You can’t perform that action at this time.
0 commit comments