-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update PDS & PackNFT contracts & txs to Cadence 1.0 #47
Changes from 11 commits
3d559bc
797b5a9
180c8db
5e4effc
e795051
f6dff24
cc91459
befe7b2
6cb0bd4
2906ec6
e8e4a0e
0173052
d888633
43865c9
f5cbcb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,121 @@ | ||
import Crypto | ||
import NonFungibleToken from 0x{{.NonFungibleToken}} | ||
import NonFungibleToken from "NonFungibleToken" | ||
|
||
/// Contract interface for PackNFT contracts. | ||
/// | ||
access(all) contract interface IPackNFT{ | ||
|
||
/// Entitlement to perform operations on the PackNFT | ||
/// | ||
access(all) entitlement Operate | ||
|
||
pub contract interface IPackNFT{ | ||
/// StoragePath for Collection Resource | ||
/// | ||
pub let CollectionStoragePath: StoragePath | ||
access(all) let CollectionStoragePath: StoragePath | ||
|
||
/// PublicPath expected for deposit | ||
/// | ||
pub let CollectionPublicPath: PublicPath | ||
access(all) let CollectionPublicPath: PublicPath | ||
|
||
/// PublicPath for receiving PackNFT | ||
/// | ||
pub let CollectionIPackNFTPublicPath: PublicPath | ||
access(all) let CollectionIPackNFTPublicPath: PublicPath | ||
|
||
/// StoragePath for the PackNFT Operator Resource (issuer owns this) | ||
/// | ||
pub let OperatorStoragePath: StoragePath | ||
/// PrivatePath to share IOperator interfaces with Operator (typically with PDS account) | ||
/// | ||
pub let OperatorPrivPath: PrivatePath | ||
access(all) let OperatorStoragePath: StoragePath | ||
|
||
/// Request for Reveal | ||
/// | ||
pub event RevealRequest(id: UInt64, openRequest: Bool) | ||
access(all) event RevealRequest(id: UInt64, openRequest: Bool) | ||
|
||
/// Request for Open | ||
/// | ||
/// This is emitted when owner of a PackNFT request for the entitled NFT to be | ||
/// deposited to its account | ||
pub event OpenRequest(id: UInt64) | ||
access(all) event OpenRequest(id: UInt64) | ||
|
||
/// Burned | ||
/// | ||
/// Emitted when a PackNFT has been burned | ||
pub event Burned(id: UInt64 ) | ||
access(all) event Burned(id: UInt64 ) | ||
|
||
/// Opened | ||
/// | ||
/// Emitted when a packNFT has been opened | ||
pub event Opened(id: UInt64) | ||
access(all) event Opened(id: UInt64) | ||
|
||
pub enum Status: UInt8 { | ||
pub case Sealed | ||
pub case Revealed | ||
pub case Opened | ||
} | ||
// TODO: Clean up after enum handling/removal is clarified. | ||
// Enums cannot be declared anymore in interfaces in Cadence 1.0 | ||
// access(all) enum Status: UInt8 { | ||
// access(all) case Sealed | ||
// access(all) case Revealed | ||
// access(all) case Opened | ||
// } | ||
|
||
pub struct interface Collectible { | ||
pub let address: Address | ||
pub let contractName: String | ||
pub let id: UInt64 | ||
pub fun hashString(): String | ||
init(address: Address, contractName: String, id: UInt64) | ||
/// Struct interface for Collectible | ||
/// | ||
access(all) struct interface Collectible { | ||
access(all) let address: Address | ||
access(all) let contractName: String | ||
access(all) let id: UInt64 | ||
access(all) fun hashString(): String | ||
view init(address: Address, contractName: String, id: UInt64) | ||
} | ||
|
||
pub resource interface IPack { | ||
pub let issuer: Address | ||
pub var status: Status | ||
/// Resource interface for PackNFT | ||
/// | ||
access(all) resource interface IPack { | ||
access(all) let issuer: Address | ||
// access(all) var status: Status | ||
|
||
pub fun verify(nftString: String): Bool | ||
access(all) fun verify(nftString: String): Bool | ||
|
||
access(contract) fun reveal(id: UInt64, nfts: [{IPackNFT.Collectible}], salt: String) | ||
access(contract) fun open(id: UInt64, nfts: [{IPackNFT.Collectible}]) | ||
init(commitHash: String, issuer: Address) | ||
view init(commitHash: String, issuer: Address) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I was confused too initially but the |
||
} | ||
|
||
pub resource interface IOperator { | ||
pub fun mint(distId: UInt64, commitHash: String, issuer: Address): @NFT | ||
pub fun reveal(id: UInt64, nfts: [{Collectible}], salt: String) | ||
pub fun open(id: UInt64, nfts: [{IPackNFT.Collectible}]) | ||
} | ||
pub resource PackNFTOperator: IOperator { | ||
pub fun mint(distId: UInt64, commitHash: String, issuer: Address): @NFT | ||
pub fun reveal(id: UInt64, nfts: [{Collectible}], salt: String) | ||
pub fun open(id: UInt64, nfts: [{IPackNFT.Collectible}]) | ||
/// Resource interface for IOperator | ||
/// | ||
access(all) resource interface IOperator { | ||
access(Operate) fun mint(distId: UInt64, commitHash: String, issuer: Address): @{IPackNFT.NFT} | ||
access(Operate) fun reveal(id: UInt64, nfts: [{Collectible}], salt: String) | ||
access(Operate) fun open(id: UInt64, nfts: [{IPackNFT.Collectible}]) | ||
} | ||
|
||
pub resource interface IPackNFTToken { | ||
pub let id: UInt64 | ||
pub let issuer: Address | ||
} | ||
// Included for backwards compatibility | ||
access(all) resource interface PackNFTOperator: IOperator {} | ||
|
||
pub resource NFT: NonFungibleToken.INFT, IPackNFTToken, IPackNFTOwnerOperator{ | ||
pub let id: UInt64 | ||
pub let issuer: Address | ||
pub fun reveal(openRequest: Bool) | ||
pub fun open() | ||
} | ||
|
||
pub resource interface IPackNFTOwnerOperator{ | ||
pub fun reveal(openRequest: Bool) | ||
pub fun open() | ||
/// Resource interface for IPackNFTToken | ||
/// | ||
access(all) resource interface IPackNFTToken { | ||
access(all) let id: UInt64 | ||
access(all) let issuer: Address | ||
} | ||
|
||
pub resource interface IPackNFTCollectionPublic { | ||
pub fun deposit(token: @NonFungibleToken.NFT) | ||
pub fun getIDs(): [UInt64] | ||
pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT | ||
pub fun borrowPackNFT(id: UInt64): &IPackNFT.NFT? { | ||
// If the result isn't nil, the id of the returned reference | ||
// should be the same as the argument to the function | ||
post { | ||
(result == nil) || (result!.id == id): | ||
"Cannot borrow PackNFT reference: The ID of the returned reference is incorrect" | ||
} | ||
} | ||
|
||
/// Resource interface for NFT | ||
/// | ||
access(all) resource interface NFT: NonFungibleToken.NFT, IPackNFTToken, IPackNFTOwnerOperator { | ||
access(all) let id: UInt64 | ||
access(all) let issuer: Address | ||
access(NonFungibleToken.Update | NonFungibleToken.Owner) fun reveal(openRequest: Bool) | ||
access(NonFungibleToken.Update | NonFungibleToken.Owner) fun open() | ||
} | ||
|
||
// Included for backwards compatibility | ||
access(all) resource interface IPackNFTOwnerOperator{} | ||
access(all) resource interface IPackNFTCollectionPublic {} | ||
|
||
/// Emit a RevealRequest event to signal a Sealed Pack NFT should be revealed | ||
/// | ||
access(contract) fun revealRequest(id: UInt64, openRequest: Bool) | ||
|
||
/// Emit an OpenRequest event to signal a Revealed Pack NFT should be opened | ||
/// | ||
access(contract) fun openRequest(id: UInt64) | ||
pub fun publicReveal(id: UInt64, nfts: [{IPackNFT.Collectible}], salt: String) | ||
|
||
/// Reveal a Sealed Pack NFT | ||
/// | ||
access(all) fun publicReveal(id: UInt64, nfts: [{IPackNFT.Collectible}], salt: String) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Status
enum remain needed inPackNFT
contracts, but we remove it inIPackNFT
because concrete type declarations are not allowed in contract interfaces anymoreThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to know. We can just remove it then