Skip to content

Commit

Permalink
fix withdrawCap type
Browse files Browse the repository at this point in the history
  • Loading branch information
loic1 committed Mar 29, 2024
1 parent 6cb0bd4 commit 2906ec6
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pds/contracts/IPackNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ access(all) contract interface IPackNFT{

/// Resource interface for NFT
///
access(all) resource interface NFT: NonFungibleToken.INFT, IPackNFTToken, IPackNFTOwnerOperator {
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)
Expand Down
16 changes: 8 additions & 8 deletions pds/contracts/PDS.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import IPackNFT from "IPackNFT"
access(all) contract PDS{
/// Entitlement that grants the ability to create a distribution.
///
access(all) entitlement DistCreation
access(all) entitlement CreateDist

access(all) var version: String
access(all) let PackIssuerStoragePath: StoragePath
Expand Down Expand Up @@ -105,7 +105,7 @@ access(all) contract PDS{
access(all) resource SharedCapabilities {
/// Capability to withdraw NFTs from the issuer.
///
access(self) let withdrawCap: Capability<auth(NonFungibleToken.Withdraw | NonFungibleToken.Owner) &{NonFungibleToken.Provider}>
access(self) let withdrawCap: Capability<auth(NonFungibleToken.Withdraw, NonFungibleToken.Owner) &{NonFungibleToken.Provider}>

/// Capability to mint, reveal, and open Pack NFTs.
///
Expand Down Expand Up @@ -155,7 +155,7 @@ access(all) contract PDS{
/// SharedCapabilities resource initializer.
///
view init(
withdrawCap: Capability<auth(NonFungibleToken.Withdraw | NonFungibleToken.Owner) &{NonFungibleToken.Provider}>,
withdrawCap: Capability<auth(NonFungibleToken.Withdraw, NonFungibleToken.Owner) &{NonFungibleToken.Provider}>,
operatorCap: Capability<auth(IPackNFT.Operatable) &{IPackNFT.IOperator}>
) {
self.withdrawCap = withdrawCap
Expand All @@ -170,16 +170,16 @@ access(all) contract PDS{
/// Resource that defines the issuer of a pack.
///
access(all) resource PackIssuer: PackIssuerCapReciever {
access(self) var cap: Capability<auth(DistCreation) &DistributionCreator>?
access(self) var cap: Capability<&DistributionCreator>?

access(all) fun setDistCap(cap: Capability<auth(DistCreation) &DistributionCreator>) {
access(all) fun setDistCap(cap: Capability<&DistributionCreator>) {
pre {
cap.borrow() != nil: "Invalid capability"
}
self.cap = cap
}

access(DistCreation) fun createDist(sharedCap: @SharedCapabilities, title: String, metadata: {String: String}) {
access(CreateDist) fun createDist(sharedCap: @SharedCapabilities, title: String, metadata: {String: String}) {
assert(title.length > 0, message: "Title must not be empty")
let c = self.cap!.borrow()!
c.createNewDist(sharedCap: <- sharedCap, title: title, metadata: metadata)
Expand All @@ -198,7 +198,7 @@ access(all) contract PDS{
/// Resource that defines the creator of a distribution.
///
access(all) resource DistributionCreator: IDistCreator {
access(DistCreation) fun createNewDist(sharedCap: @SharedCapabilities, title: String, metadata: {String: String}) {
access(all) fun createNewDist(sharedCap: @SharedCapabilities, title: String, metadata: {String: String}) {
let currentId = PDS.nextDistId
PDS.DistSharedCap[currentId] <-! sharedCap
PDS.Distributions[currentId] = DistInfo(title: title, metadata: metadata)
Expand Down Expand Up @@ -308,7 +308,7 @@ access(all) contract PDS{
/// Create a SharedCapabilities resource and return it to the caller.
///
access(all) fun createSharedCapabilities(
withdrawCap: Capability<auth(NonFungibleToken.Withdraw | NonFungibleToken.Owner) &{NonFungibleToken.Provider}>,
withdrawCap: Capability<auth(NonFungibleToken.Withdraw, NonFungibleToken.Owner) &{NonFungibleToken.Provider}>,
operatorCap: Capability<auth(IPackNFT.Operatable) &{IPackNFT.IOperator}>
): @SharedCapabilities {
return <- create SharedCapabilities(
Expand Down
6 changes: 3 additions & 3 deletions pds/lib/go/contracts/internal/assets/assets.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pds/lib/go/templates/internal/assets/assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pds/transactions/pds/create_distribution.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import NonFungibleToken from "NonFungibleToken"
transaction(title: String, metadata: {String: String}) {
prepare (issuer: auth(BorrowValue, Capabilities) &Account) {

let i = issuer.storage.borrow<auth(PDS.DistCreation) &PDS.PackIssuer>(from: PDS.PackIssuerStoragePath)
let i = issuer.storage.borrow<auth(PDS.CreateDist) &PDS.PackIssuer>(from: PDS.PackIssuerStoragePath)
?? panic ("issuer does not have PackIssuer resource")

// issuer must have a PackNFT collection
let withdrawCap = issuer.capabilities.storage.issue<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider}>(StoragePath(identifier: "cadenceExampleNFTCollection")!);
let withdrawCap = issuer.capabilities.storage.issue<auth(NonFungibleToken.Withdraw, NonFungibleToken.Owner) &{NonFungibleToken.Provider}>(StoragePath(identifier: "cadenceExampleNFTCollection")!);
let operatorCap = issuer.capabilities.storage.issue<auth(IPackNFT.Operatable) &{IPackNFT.IOperator}>({{.PackNFTName}}.OperatorStoragePath);
assert(withdrawCap.check(), message: "cannot borrow withdraw capability")
assert(operatorCap.check(), message: "cannot borrow operator capability")
Expand Down
2 changes: 1 addition & 1 deletion pds/transactions/pds/set_pack_issuer_cap.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import PDS from "PDS"

transaction (issuer: Address) {
prepare(pds: auth(Capabilities) &Account) {
let cap = pds.capabilities.storage.issue<auth(PDS.DistCreation) &PDS.DistributionCreator>(PDS.DistCreatorStoragePath)
let cap = pds.capabilities.storage.issue<auth(PDS.CreateDist) &PDS.DistributionCreator>(PDS.DistCreatorStoragePath)
if !cap.check() {
panic("cannot borrow such capability")
}
Expand Down

0 comments on commit 2906ec6

Please sign in to comment.