@@ -11,7 +11,7 @@ pub contract PDS{
1111 pub let distCreatorPrivPath : PrivatePath
1212 pub let distManagerStoragePath : StoragePath
1313
14- pub var DistId : UInt64
14+ pub var nextDistId : UInt64
1515 access (contract ) let Distributions : @{UInt64 : SharedCapabilities }
1616
1717 pub struct Collectible : IPackNFT .Collectible {
@@ -57,14 +57,14 @@ pub contract PDS{
5757 return <- c .withdraw (withdrawID : withdrawID )
5858 }
5959
60- // TODO: maybe we do not need to specify the issuer here, should be the creator of the SharedCapabilities
61- // this is also used in storing inside the NFT though
62- pub fun mintPackNFT (distId : UInt64 , commitHashes : [String ], issuer : Address ){
60+ pub fun mintPackNFT (distId : UInt64 , commitHashes : [String ], issuer : Address , recvCap : &{NonFungibleToken .CollectionPublic } ){
6361 var i = 0
6462 let c = self .operatorCap .borrow () ?? panic (" no such cap" )
6563 while i < commitHashes .length {
66- c .mint (distId : distId , commitHash : commitHashes [i ], issuer : issuer )
64+ let nft <- c .mint (distId : distId , commitHash : commitHashes [i ], issuer : issuer )
6765 i = i + 1
66+ let n <- nft as ! @NonFungibleToken.NFT
67+ recvCap .deposit (token : <- n )
6868 }
6969 }
7070
@@ -73,11 +73,11 @@ pub contract PDS{
7373 c .reveal (id : packId , nfts : nfts , salt : salt )
7474 }
7575
76- pub fun openPackNFT (packId : UInt64 , nftIds : [UInt64 ], owner : Address , collectionProviderPath : PrivatePath , recvCollectionPublicPath : PublicPath ) {
76+ pub fun openPackNFT (packId : UInt64 , nftIds : [UInt64 ], recvCap : &{ NonFungibleToken . CollectionPublic } , collectionProviderPath : PrivatePath ) {
7777 let c = self .operatorCap .borrow () ?? panic (" no such cap" )
7878 // This checks and sets the status of the pack before releasing escrow
7979 c .open (id : packId )
80- PDS .releaseEscrow (nftIds : nftIds , owner : owner , collectionProviderPath : collectionProviderPath , recvCollectionPublicPath : recvCollectionPublicPath )
80+ PDS .releaseEscrow (nftIds : nftIds , recvCap : recvCap , collectionProviderPath : collectionProviderPath )
8181 }
8282
8383
@@ -125,9 +125,9 @@ pub contract PDS{
125125
126126 pub resource DistributionCreator : IDistCreator {
127127 pub fun createNewDist (sharedCap : @SharedCapabilities ) {
128- let currentId = PDS .DistId
128+ let currentId = PDS .nextDistId
129129 PDS .Distributions [currentId ] <- ! sharedCap
130- PDS .DistId = currentId + 1
130+ PDS .nextDistId = currentId + 1
131131 emit DistributionCreated (DistId : currentId )
132132 }
133133 }
@@ -146,10 +146,10 @@ pub contract PDS{
146146 PDS .Distributions [distId ] <- ! d
147147 }
148148
149- pub fun mintPackNFT (distId : UInt64 , commitHashes : [String ], issuer : Address ){
149+ pub fun mintPackNFT (distId : UInt64 , commitHashes : [String ], issuer : Address , recvCap : &{ NonFungibleToken . CollectionPublic } ){
150150 assert (PDS .Distributions .containsKey (distId ), message : " No such distribution" )
151151 let d <- PDS .Distributions .remove (key : distId )!
152- d .mintPackNFT (distId : distId , commitHashes : commitHashes , issuer : issuer )
152+ d .mintPackNFT (distId : distId , commitHashes : commitHashes , issuer : issuer , recvCap : recvCap )
153153 PDS .Distributions [distId ] <- ! d
154154 }
155155
@@ -172,35 +172,27 @@ pub contract PDS{
172172 PDS .Distributions [distId ] <- ! d
173173 }
174174
175- pub fun openPackNFT (distId : UInt64 , packId : UInt64 , nftIds : [UInt64 ], owner : Address , collectionProviderPath : PrivatePath , recvCollectionPublicPath : PublicPath ){
175+ pub fun openPackNFT (distId : UInt64 , packId : UInt64 , nftIds : [UInt64 ], recvCap : &{ NonFungibleToken . CollectionPublic } , collectionProviderPath : PrivatePath ){
176176 assert (PDS .Distributions .containsKey (distId ), message : " No such distribution" )
177177 let d <- PDS .Distributions .remove (key : distId )!
178- d .openPackNFT (packId : packId , nftIds : nftIds , owner : owner , collectionProviderPath : collectionProviderPath , recvCollectionPublicPath : recvCollectionPublicPath )
178+ d .openPackNFT (packId : packId , nftIds : nftIds , recvCap : recvCap , collectionProviderPath : collectionProviderPath )
179179 PDS .Distributions [distId ] <- ! d
180180 }
181181
182182 }
183183
184184 access (contract ) fun getManagerCollectionCap (escrowCollectionPublic : PublicPath ): Capability <&{NonFungibleToken .CollectionPublic }> {
185185 let pdsCollection = self .account .getCapability <&{NonFungibleToken .CollectionPublic }>(escrowCollectionPublic )
186- if ! pdsCollection .check (){
187- panic (" Please ensure PDS has created and linked a Collection for recieving escrows" )
188- }
186+ assert (pdsCollection .check (), message : " Please ensure PDS has created and linked a Collection for recieving escrows" )
189187 return pdsCollection
190188 }
191189
192- access (contract ) fun releaseEscrow (nftIds : [UInt64 ], owner : Address , collectionProviderPath : PrivatePath , recvCollectionPublicPath : PublicPath ) {
190+ access (contract ) fun releaseEscrow (nftIds : [UInt64 ], recvCap : &{ NonFungibleToken . CollectionPublic } , collectionProviderPath : PrivatePath ) {
193191 let pdsCollection = self .account .getCapability (collectionProviderPath ).borrow <&{NonFungibleToken .Provider }>()
194192 ?? panic (" Unable to borrow PDS collection provider capability from private path" )
195- let recvAcct = getAccount (owner )
196- let recv = recvAcct .getCapability (recvCollectionPublicPath ).borrow <&{NonFungibleToken .CollectionPublic }>()
197- ?? panic (" Unable to borrow Collection Public reference for recipient" )
198- log (" releasing escrow" )
199- log (nftIds )
200193 var i = 0
201194 while i < nftIds .length {
202- log (nftIds [i ])
203- recv .deposit (token : <- pdsCollection .withdraw (withdrawID : nftIds [i ]))
195+ recvCap .deposit (token : <- pdsCollection .withdraw (withdrawID : nftIds [i ]))
204196 i = i + 1
205197 }
206198 }
@@ -221,15 +213,14 @@ pub contract PDS{
221213
222214
223215 init (
224- adminAccount : AuthAccount ,
225216 packIssuerStoragePath : StoragePath ,
226217 packIssuerCapRecv : PublicPath ,
227218 distCreatorStoragePath : StoragePath ,
228219 distCreatorPrivPath : PrivatePath ,
229220 distManagerStoragePath : StoragePath ,
230221 version : String
231222 ) {
232- self .DistId = 0
223+ self .nextDistId = 0
233224 self .Distributions <- {}
234225 self .packIssuerStoragePath = packIssuerStoragePath
235226 self .packIssuerCapRecv = packIssuerCapRecv
@@ -240,11 +231,11 @@ pub contract PDS{
240231
241232 // Create a distributionCreator to share create capability with PackIssuer
242233 let d <- create DistributionCreator ()
243- adminAccount .save (<- d , to : self .distCreatorStoragePath )
244- adminAccount .link <&DistributionCreator {PDS .IDistCreator }>(self .distCreatorPrivPath , target : self .distCreatorStoragePath )
234+ self . account .save (<- d , to : self .distCreatorStoragePath )
235+ self . account .link <&DistributionCreator {PDS .IDistCreator }>(self .distCreatorPrivPath , target : self .distCreatorStoragePath )
245236
246237 // Create a distributionManager to manager distributions (withdraw for escrow, mint PackNFT todo: reveal / transfer)
247238 let m <- create DistributionManager ()
248- adminAccount .save (<- m , to : self .distManagerStoragePath )
239+ self . account .save (<- m , to : self .distManagerStoragePath )
249240 }
250241}
0 commit comments