Skip to content

Commit

Permalink
use correct public linked types and get most tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahannan committed Feb 5, 2024
1 parent ebdb001 commit e8c999a
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- name: Install Flow CLI
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.9.2-stable-cadence.1
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)" -- v1.12.0-cadence-v1.0.0-M4-2
- name: Flow CLI Version
run: flow version
- name: Update PATH
Expand Down
9 changes: 3 additions & 6 deletions contracts/ExampleNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,9 @@ access(all) contract ExampleNFT: NonFungibleToken {
access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
switch viewType {
case Type<MetadataViews.NFTCollectionData>():
let collectionRef = self.account.storage.borrow<&ExampleNFT.Collection>(
from: /storage/cadenceExampleNFTCollection
) ?? panic("Could not borrow a reference to the stored collection")
let collectionData = MetadataViews.NFTCollectionData(
storagePath: collectionRef.storagePath,
publicPath: collectionRef.publicPath,
storagePath: /storage/cadenceExampleNFTCollection,
publicPath: /public/cadenceExampleNFTCollection,
publicCollection: Type<&ExampleNFT.Collection>(),
publicLinkedType: Type<&ExampleNFT.Collection>(),
createEmptyCollectionFunction: (fun(): @{NonFungibleToken.Collection} {
Expand Down Expand Up @@ -312,7 +309,7 @@ access(all) contract ExampleNFT: NonFungibleToken {
self.account.storage.save(<-collection, to: defaultStoragePath)

// create a public capability for the collection
let collectionCap = self.account.capabilities.storage.issue<&{NonFungibleToken.Receiver, NonFungibleToken.Collection}>(defaultStoragePath)
let collectionCap = self.account.capabilities.storage.issue<&ExampleNFT.Collection>(defaultStoragePath)
self.account.capabilities.publish(collectionCap, at: defaultPublicPath)

// Create a Minter resource and save it to storage
Expand Down
2 changes: 1 addition & 1 deletion contracts/MetadataViews.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ access(all) contract MetadataViews {
createEmptyCollectionFunction: fun(): @{NonFungibleToken.Collection}
) {
pre {
publicLinkedType.isSubtype(of: Type<&{NonFungibleToken.Receiver}>()): "Public type must include NonFungibleToken.Receiver interface."
publicLinkedType.isSubtype(of: Type<&{NonFungibleToken.Collection}>()): "Public type must be a subtype of NonFungibleToken.Collection interface."
}
self.storagePath=storagePath
self.publicPath=publicPath
Expand Down
6 changes: 1 addition & 5 deletions contracts/NonFungibleToken.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ access(all) contract interface NonFungibleToken: ViewResolver {
/// Requirement for the concrete resource type
/// to be declared in the implementing contract
///
access(all) resource interface Collection: Provider, Receiver, CollectionPublic {
access(all) resource interface Collection: Provider, Receiver, CollectionPublic, ViewResolver.ResolverCollection {

/// deposit takes a NFT as an argument and stores it in the collection
/// @param token: The NFT to deposit into the collection
Expand All @@ -198,10 +198,6 @@ access(all) contract interface NonFungibleToken: ViewResolver {
/// @return An integer indicating the size of the collection
access(all) view fun getLength(): Int

/// Gets a list of all the IDs in the collection
/// @return An array of NFT IDs in the collection
access(all) view fun getIDs(): [UInt64]

/// Borrows a reference to an NFT stored in the collection
/// If the NFT with the specified ID is not in the collection,
/// the function should return `nil` and not panic.
Expand Down
31 changes: 24 additions & 7 deletions contracts/utility/NFTForwarding.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ access(all) contract NFTForwarding {

access(all) entitlement Mutable

access(all) event ForwardedNFTDeposit(id: UInt64, uuid: UInt64, from: Address?, fromUUID: UInt64, to: Address, toUUID: UInt64)
access(all) event UpdatedNFTForwarderRecipient(forwarderAddress: Address?, forwarderUUID: UInt64, newRecipientAddress: Address, newRecipientUUID: UInt64)
access(all) event ForwardedNFTDeposit(id: UInt64, uuid: UInt64, from: Address?, fromUUID: UInt64, to: Address?, toUUID: UInt64)
access(all) event UpdatedNFTForwarderRecipient(forwarderAddress: Address?, forwarderUUID: UInt64, newRecipientAddress: Address?, newRecipientUUID: UInt64)

/// Canonical Storage and Public paths
///
Expand All @@ -32,6 +32,23 @@ access(all) contract NFTForwarding {
///
access(self) var recipient: Capability<&{NonFungibleToken.Collection}>

/// getSupportedNFTTypes returns a list of NFT types that this receiver accepts
access(all) view fun getSupportedNFTTypes(): {Type: Bool} {
let recipientRef = self.borrowRecipientCollection()
?? panic("Could not borrow reference to recipient's Collection!")
return recipientRef.getSupportedNFTTypes()
}

/// Returns whether or not the given type is accepted by the collection
/// A collection that can accept any type should just return true by default
access(all) view fun isSupportedNFTType(type: Type): Bool {
let types = self.getSupportedNFTTypes()
if let supported = types[type] {
return supported
}
return false
}

/// Allows for deposits of NFT resources, forwarding
/// passed deposits to the designated recipient
///
Expand All @@ -56,7 +73,7 @@ access(all) contract NFTForwarding {
///
/// @return a reference to the recipient's Collection or nil if the Capability is no longer valid
///
access(all) fun borrowRecipientCollection(): &{NonFungibleToken.Collection}? {
access(all) view fun borrowRecipientCollection(): &{NonFungibleToken.Collection}? {
return self.recipient.borrow() ?? nil
}

Expand All @@ -71,17 +88,17 @@ access(all) contract NFTForwarding {
}

self.recipient = newRecipient
let recipientRef = self.recipientRef.borrow()!
emit UpdatedNFTForwarderRecipient(forwarderAddress: self.owner?.address, forwardarUUID: self.uuid, newRecipientAddress: recipientRef.owner?.address, newRecipientUUID: recipientRef.uuid)
let recipientRef = self.recipient.borrow()!
emit UpdatedNFTForwarderRecipient(forwarderAddress: self.owner?.address, forwarderUUID: self.uuid, newRecipientAddress: recipientRef.owner?.address, newRecipientUUID: recipientRef.uuid)
}

init(_ recipient: Capability<&{NonFungibleToken.Collection}>) {
pre {
recipient.check(): "Could not borrow Collection reference from the given Capability"
}
self.recipient = recipient
let recipientRef = self.recipientRef.borrow()!
emit UpdatedNFTForwarderRecipient(forwarderAddress: self.owner?.address, forwardarUUID: self.uuid, newRecipientAddress: recipientRef.owner?.address, newRecipientUUID: recipientRef.uuid)
let recipientRef = self.recipient.borrow()!
emit UpdatedNFTForwarderRecipient(forwarderAddress: self.owner?.address, forwarderUUID: self.uuid, newRecipientAddress: recipientRef.owner?.address, newRecipientUUID: recipientRef.uuid)
}
}

Expand Down
Loading

0 comments on commit e8c999a

Please sign in to comment.