Skip to content

Commit

Permalink
update interface conformance
Browse files Browse the repository at this point in the history
  • Loading branch information
loic1 committed Mar 19, 2024
1 parent 180c8db commit 5e4effc
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 47 deletions.
29 changes: 11 additions & 18 deletions pds/contracts/IPackNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -62,41 +62,34 @@ access(all) contract interface IPackNFT{
}

access(all) resource interface IOperator {
access(Operatable) fun mint(distId: UInt64, commitHash: String, issuer: Address): @{NFT}
access(Operatable) fun mint(distId: UInt64, commitHash: String, issuer: Address): @{IPackNFT.INFT}
access(Operatable) fun reveal(id: UInt64, nfts: [{Collectible}], salt: String)
access(Operatable) fun open(id: UInt64, nfts: [{IPackNFT.Collectible}])
}

/// Deprecated
access(all) resource interface PackNFTOperator: IOperator {
// access(Operatable) fun mint(distId: UInt64, commitHash: String, issuer: Address): @{NFT}
// access(Operatable) fun reveal(id: UInt64, nfts: [{Collectible}], salt: String)
// access(Operatable) fun open(id: UInt64, nfts: [{IPackNFT.Collectible}])
}
// Included for backwards compatibility
access(all) resource interface PackNFTOperator: IOperator {}

access(all) resource interface IPackNFTToken {
access(all) let id: UInt64
access(all) let issuer: Address
}

access(all) resource interface NFT: NonFungibleToken.NFT, IPackNFTToken, IPackNFTOwnerOperator{
access(all) resource interface INFT: NonFungibleToken.NFT, IPackNFTToken {
access(all) let id: UInt64
access(all) let issuer: Address
access(NonFungibleToken.Owner) fun reveal(openRequest: Bool)
access(NonFungibleToken.Owner) fun open()
access(NonFungibleToken.Update | NonFungibleToken.Owner) fun reveal(openRequest: Bool)
access(NonFungibleToken.Update | NonFungibleToken.Owner) fun open()
}

/// Deprecated
access(all) resource interface IPackNFTOwnerOperator{
// access(all) fun reveal(openRequest: Bool)
// access(all) fun open()
}
// Included for backwards compatibility
access(all) resource interface IPackNFTOwnerOperator{}

access(all) resource interface IPackNFTCollectionPublic {
access(all) fun deposit(token: @{NonFungibleToken.NFT})
access(all) fun getIDs(): [UInt64]
access(all) fun borrowNFT(id: UInt64): &{NonFungibleToken.NFT}
access(all) fun borrowPackNFT(id: UInt64): &{IPackNFT.NFT}? {
view access(all) fun getIDs(): [UInt64]
view access(all) fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}?
view access(all) fun borrowPackNFT(id: UInt64): &{IPackNFT.INFT}? {
// If the result isn't nil, the id of the returned reference
// should be the same as the argument to the function
post {
Expand Down
17 changes: 7 additions & 10 deletions pds/contracts/PDS.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import NonFungibleToken from "NonFungibleToken"
import IPackNFT from "IPackNFT"

access(all) contract PDS{
/// Entitlement that grants the ability to create a distribution
access(all) entitlement DistCreation

/// The collection to hold all escrowed NFT
/// Original collection created from PackNFT
access(all) var version: String
Expand Down Expand Up @@ -126,12 +129,8 @@ access(all) contract PDS{
}


access(all) resource interface PackIssuerCapReciever {
// access(all) fun setDistCap(cap: Capability<&{IDistCreator}>)
}

/// Entitlement that grants the ability to create a distribution (replacement for PackIssuerCapReciever resource interface)
access(all) entitlement DistCreation
// Included for backwards compatibility
access(all) resource interface PackIssuerCapReciever {}

access(all) resource PackIssuer: PackIssuerCapReciever {
access(self) var cap: Capability<auth(DistCreation) &DistributionCreator>?
Expand All @@ -153,10 +152,8 @@ access(all) contract PDS{
}
}

// DistCap to be shared
access(all) resource interface IDistCreator {
// access(all) fun createNewDist(sharedCap: @SharedCapabilities, title: String, metadata: {String: String})
}
// Included for backwards compatibility
access(all) resource interface IDistCreator {}

access(all) resource DistributionCreator: IDistCreator {
access(DistCreation) fun createNewDist(sharedCap: @SharedCapabilities, title: String, metadata: {String: String}) {
Expand Down
24 changes: 17 additions & 7 deletions pds/contracts/PackNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {

access(all) resource PackNFTOperator: IPackNFT.IOperator {

access(IPackNFT.Operatable) fun mint(distId: UInt64, commitHash: String, issuer: Address): @{IPackNFT.NFT} {
access(IPackNFT.Operatable) fun mint(distId: UInt64, commitHash: String, issuer: Address): @{IPackNFT.INFT} {
let nft <- create NFT(commitHash: commitHash, issuer: issuer)
PackNFT.totalSupply = PackNFT.totalSupply + 1
let p <-create Pack(commitHash: commitHash, issuer: issuer)
Expand Down Expand Up @@ -110,7 +110,13 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {
}
}

access(all) resource NFT: NonFungibleToken.NFT, IPackNFT.NFT, IPackNFT.IPackNFTOwnerOperator {
access(all) resource NFT:
NonFungibleToken.INFT,
IPackNFT.IPackNFTToken,
IPackNFT.IPackNFTOwnerOperator,
NonFungibleToken.NFT,
IPackNFT.INFT
{
access(all) let id: UInt64
access(all) let hash: [UInt8]
access(all) let issuer: Address
Expand Down Expand Up @@ -157,7 +163,13 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {
}
}

access(all) resource Collection: NonFungibleToken.Collection {
access(all) resource Collection:
NonFungibleToken.Provider,
NonFungibleToken.Receiver,
NonFungibleToken.CollectionPublic,
IPackNFT.IPackNFTCollectionPublic,
NonFungibleToken.Collection
{
// dictionary of NFT conforming tokens
// NFT is a resource type with an `UInt64` ID field
access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
Expand Down Expand Up @@ -222,8 +234,8 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {
return &self.ownedNFTs[id]
}

access(all) fun borrowPackNFT(id: UInt64): &{IPackNFT.NFT}? {
return self.borrowNFT(id) as! &{IPackNFT.NFT}?
view access(all) fun borrowPackNFT(id: UInt64): &{IPackNFT.INFT}? {
return self.borrowNFT(id) as! &{IPackNFT.INFT}?
}

/// createEmptyCollection creates an empty Collection of the same type
Expand Down Expand Up @@ -340,7 +352,5 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {
let operator <- create PackNFTOperator()
self.account.storage.save(<-operator, to: self.OperatorStoragePath)
self.account.capabilities.storage.issue<&{IPackNFT.IOperator}>(self.OperatorStoragePath)

}

}
20 changes: 13 additions & 7 deletions pds/contracts/PackNFT_AllDay.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {

access(all) resource PackNFTOperator: IPackNFT.IOperator {

access(IPackNFT.Operatable) fun mint(distId: UInt64, commitHash: String, issuer: Address): @{IPackNFT.NFT}{
access(IPackNFT.Operatable) fun mint(distId: UInt64, commitHash: String, issuer: Address): @{IPackNFT.INFT}{
let nft <- create NFT(commitHash: commitHash, issuer: issuer)
PackNFT.totalSupply = PackNFT.totalSupply + 1
let p <-create Pack(commitHash: commitHash, issuer: issuer)
Expand Down Expand Up @@ -111,7 +111,7 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {
}
}

access(all) resource NFT: NonFungibleToken.INFT, IPackNFT.NFT, IPackNFT.IPackNFTOwnerOperator {
access(all) resource NFT: NonFungibleToken.INFT, IPackNFT.IPackNFTToken, IPackNFT.IPackNFTOwnerOperator, NonFungibleToken.NFT, IPackNFT.INFT {
access(all) let id: UInt64
access(all) let commitHash: String
access(all) let issuer: Address
Expand Down Expand Up @@ -194,7 +194,7 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {
})
)
case Type<MetadataViews.NFTCollectionDisplay>():
let bannerImage = MetadataViews.Media(
let bannerImage = MetadataViews.Media(
file: MetadataViews.HTTPFile(
url: "https://assets.nflallday.com/flow/catalogue/NFLAD_BANNER.png"
),
Expand All @@ -218,7 +218,7 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {
"discord": MetadataViews.ExternalURL("https://discord.com/invite/5K6qyTzj2k")
}
)
case Type<MetadataViews.Royalties>():
case Type<MetadataViews.Royalties>():
let royaltyReceiver: Capability<&{FungibleToken.Receiver}> =
getAccount({{.RoyaltyAddress}}).capabilities.get<&{FungibleToken.Receiver}>(MetadataViews.getRoyaltyReceiverPublicPath())!
return MetadataViews.Royalties(
Expand All @@ -245,7 +245,13 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {
}
}

access(all) resource Collection: NonFungibleToken.Collection {
access(all) resource Collection:
NonFungibleToken.Provider,
NonFungibleToken.Receiver,
NonFungibleToken.CollectionPublic,
IPackNFT.IPackNFTCollectionPublic,
// MetadataViews.ResolverCollection
NonFungibleToken.Collection {
// dictionary of NFT conforming tokens
// NFT is a resource type with an `UInt64` ID field
access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
Expand Down Expand Up @@ -310,8 +316,8 @@ access(all) contract PackNFT: NonFungibleToken, IPackNFT {
return &self.ownedNFTs[id]
}

access(all) fun borrowPackNFT(id: UInt64): &{IPackNFT.NFT}? {
return self.borrowNFT(id) as! &{IPackNFT.NFT}?
view access(all) fun borrowPackNFT(id: UInt64): &{IPackNFT.INFT}? {
return self.borrowNFT(id) as! &{IPackNFT.INFT}?
}

/// createEmptyCollection creates an empty Collection of the same type
Expand Down
22 changes: 21 additions & 1 deletion pds/flow.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,27 @@
"deployments": {
"emulator": {
"emulator-account": [

"IPackNFT",
{
"name": "PDS",
"args": [
{"type": "Path","value": {"domain": "storage", "identifier": "PackIssuer"}},
{"type": "Path","value": {"domain": "public", "identifier": "PackIssuer"}},
{"type": "Path","value": {"domain": "storage", "identifier": "DistCreator"}},
{"type": "Path","value": {"domain": "storage", "identifier": "DistManager"}},
{"type": "String","value": "0.1"}
]
},
{
"name": "PackNFT",
"args": [
{"type": "Path","value": {"domain": "storage", "identifier": "PackNFT"}},
{"type": "Path","value": {"domain": "public", "identifier": "PackNFT"}},
{"type": "Path","value": {"domain": "public", "identifier": "IPackNFT"}},
{"type": "Path","value": {"domain": "storage", "identifier": "PackNFTOperator"}},
{"type": "String","value": "0.1"}
]
}
]
}
}
Expand Down
Loading

0 comments on commit 5e4effc

Please sign in to comment.