Skip to content

Commit

Permalink
fixes to get OpenEdition drops to work (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
austinkline authored Aug 25, 2024
1 parent 20d74e9 commit 5f9abbd
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 23 deletions.
4 changes: 4 additions & 0 deletions contracts/DropTypes.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ access(all) contract DropTypes {
phaseSummaries.append(summary)
}

if CompositeType(dropDetails.nftType) == nil {
continue
}

summaries.append(DropSummary(
id: drop!.uuid,
display: dropDetails.display,
Expand Down
11 changes: 8 additions & 3 deletions contracts/FlowtyDrops.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ access(all) contract FlowtyDrops {
access(all) let ContainerStoragePath: StoragePath
access(all) let ContainerPublicPath: PublicPath

access(all) event DropAdded(address: Address, id: UInt64, name: String, description: String, imageUrl: String, start: UInt64?, end: UInt64?)
access(all) event DropAdded(address: Address, id: UInt64, name: String, description: String, imageUrl: String, start: UInt64?, end: UInt64?, nftType: String)
access(all) event Minted(address: Address, dropID: UInt64, phaseID: UInt64, nftID: UInt64, nftType: String)
access(all) event PhaseAdded(dropID: UInt64, dropAddress: Address, id: UInt64, index: Int, switcherType: String, pricerType: String, addressVerifierType: String)
access(all) event PhaseRemoved(dropID: UInt64, dropAddress: Address, id: UInt64)
Expand Down Expand Up @@ -203,6 +203,10 @@ access(all) contract FlowtyDrops {
}

init(display: MetadataViews.Display, medias: MetadataViews.Medias?, commissionRate: UFix64, nftType: String) {
pre {
nftType != "": "nftType should be a composite type identifier"
}

self.display = display
self.medias = medias
self.totalMinted = 0
Expand Down Expand Up @@ -372,7 +376,8 @@ access(all) contract FlowtyDrops {
description: details.display.description,
imageUrl: details.display.thumbnail.uri(),
start: firstPhaseDetails.switcher.getStart(),
end: firstPhaseDetails.switcher.getEnd()
end: firstPhaseDetails.switcher.getEnd(),
nftType: details.nftType
)
destroy self.drops.insert(key: drop.uuid, <-drop)
}
Expand Down Expand Up @@ -416,7 +421,7 @@ access(all) contract FlowtyDrops {

access(all) fun getMinterStoragePath(type: Type): StoragePath {
let segments = type.identifier.split(separator: ".")
let identifier = "FlowtyDrops_Minter_".concat(segments[1]).concat(segments[2])
let identifier = "FlowtyDrops_Minter_".concat(segments[1]).concat("_").concat(segments[2])
return StoragePath(identifier: identifier)!
}

Expand Down
29 changes: 14 additions & 15 deletions contracts/initializers/OpenEditionInitializer.cdc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import "ContractInitializer"
import "NFTMetadata"
import "FlowtyDrops"
import "NonFungibleToken"
import "UniversalCollection"

access(all) contract OpenEditionInitializer: ContractInitializer {
access(all) fun initialize(contractAcct: auth(Storage, Contracts, Keys, Inbox, Capabilities) &Account, params: {String: AnyStruct}): NFTMetadata.InitializedCaps {
Expand All @@ -9,18 +11,15 @@ access(all) contract OpenEditionInitializer: ContractInitializer {
params["data"]!.getType() == Type<NFTMetadata.Metadata>(): "data param must be of type NFTMetadata.Metadata"
params["collectionInfo"] != nil: "missing param collectionInfo"
params["collectionInfo"]!.getType() == Type<NFTMetadata.CollectionInfo>(): "collectionInfo param must be of type NFTMetadata.CollectionInfo"
params["type"] != nil: "missing param type"
params["type"]!.getType() == Type<Type>(): "type param must be of type Type"
}

let data = params["data"]! as! NFTMetadata.Metadata
let collectionInfo = params["collectionInfo"]! as! NFTMetadata.CollectionInfo

let acct: auth(Storage, Contracts, Keys, Inbox, Capabilities) &Account = Account(payer: contractAcct)
let cap = acct.capabilities.account.issue<auth(Storage, Contracts, Keys, Inbox, Capabilities) &Account>()

let t = self.getType()
let contractName = t.identifier.split(separator: ".")[2]

contractAcct.storage.save(cap, to: StoragePath(identifier: "metadataAuthAccount_".concat(contractName))!)
let nftType = params["type"]! as! Type
let contractName = nftType.identifier.split(separator: ".")[2]

// do we have information to setup a drop as well?
if params.containsKey("dropDetails") && params.containsKey("phaseDetails") && params.containsKey("minterController") {
Expand All @@ -30,29 +29,29 @@ access(all) contract OpenEditionInitializer: ContractInitializer {
let phaseDetails = params["phaseDetails"]! as! [FlowtyDrops.PhaseDetails]

assert(minterCap.check(), message: "invalid minter capability")

assert(CompositeType(dropDetails.nftType) != nil, message: "dropDetails.nftType must be a valid CompositeType")

let phases: @[FlowtyDrops.Phase] <- []
for p in phaseDetails {
phases.append(<- FlowtyDrops.createPhase(details: p))
}

let drop <- FlowtyDrops.createDrop(details: dropDetails, minterCap: minterCap, phases: <- phases)
if acct.storage.borrow<&AnyResource>(from: FlowtyDrops.ContainerStoragePath) == nil {
acct.storage.save(<- FlowtyDrops.createContainer(), to: FlowtyDrops.ContainerStoragePath)
if contractAcct.storage.borrow<&AnyResource>(from: FlowtyDrops.ContainerStoragePath) == nil {
contractAcct.storage.save(<- FlowtyDrops.createContainer(), to: FlowtyDrops.ContainerStoragePath)

acct.capabilities.unpublish(FlowtyDrops.ContainerPublicPath)
acct.capabilities.publish(
acct.capabilities.storage.issue<&{FlowtyDrops.ContainerPublic}>(FlowtyDrops.ContainerStoragePath),
contractAcct.capabilities.unpublish(FlowtyDrops.ContainerPublicPath)
contractAcct.capabilities.publish(
contractAcct.capabilities.storage.issue<&{FlowtyDrops.ContainerPublic}>(FlowtyDrops.ContainerStoragePath),
at: FlowtyDrops.ContainerPublicPath
)
}

let container = acct.storage.borrow<auth(FlowtyDrops.Owner) &FlowtyDrops.Container>(from: FlowtyDrops.ContainerStoragePath)
let container = contractAcct.storage.borrow<auth(FlowtyDrops.Owner) &FlowtyDrops.Container>(from: FlowtyDrops.ContainerStoragePath)
?? panic("drops container not found")
container.addDrop(<- drop)
}

return NFTMetadata.initialize(acct: acct, collectionInfo: collectionInfo, collectionType: self.getType())
return NFTMetadata.initialize(acct: contractAcct, collectionInfo: collectionInfo, nftType: nftType)
}
}
4 changes: 2 additions & 2 deletions contracts/nft/NFTMetadata.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ access(all) contract NFTMetadata {
return <- create Container(collectionInfo: collectionInfo)
}

access(all) fun initialize(acct: auth(Storage, Capabilities) &Account, collectionInfo: CollectionInfo, collectionType: Type): InitializedCaps {
let storagePath = self.getCollectionStoragePath(type: collectionType)
access(all) fun initialize(acct: auth(Storage, Capabilities) &Account, collectionInfo: CollectionInfo, nftType: Type): InitializedCaps {
let storagePath = self.getCollectionStoragePath(type: nftType)
let container <- self.createContainer(collectionInfo: collectionInfo)
acct.storage.save(<-container, to: storagePath)
let pubCap = acct.capabilities.storage.issue<&Container>(storagePath)
Expand Down
1 change: 1 addition & 0 deletions contracts/nft/OpenEditionNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ access(all) contract OpenEditionNFT: BaseCollection {
self.totalSupply = 0
self.account.storage.save(<- create NFTMinter(), to: FlowtyDrops.getMinterStoragePath(type: self.getType()))
params["minterController"] = self.account.capabilities.storage.issue<&{FlowtyDrops.Minter}>(FlowtyDrops.getMinterStoragePath(type: self.getType()))
params["type"] = Type<@NFT>()

self.MetadataCap = ContractBorrower.borrowInitializer(typeIdentifier: initializeIdentifier).initialize(contractAcct: self.account, params: params).pubCap
}
Expand Down
1 change: 1 addition & 0 deletions contracts/nft/OpenEditionTemplate.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ access(all) contract OpenEditionTemplate: ContractFactoryTemplate {
.concat(" let minter <- create NFTMinter()\n")
.concat(" self.account.storage.save(<-minter, to: FlowtyDrops.getMinterStoragePath(type: self.getType()))\n")
.concat(" params[\"minterController\"] = self.account.capabilities.storage.issue<&{FlowtyDrops.Minter}>(FlowtyDrops.getMinterStoragePath(type: self.getType()))\n")
.concat(" params[\"type\"] = Type<@NFT>()\n")
.concat("\n\n")
.concat(" self.MetadataCap = ContractBorrower.borrowInitializer(typeIdentifier: initializeIdentifier).initialize(contractAcct: self.account, params: params).pubCap\n")
.concat(" }\n")
Expand Down
7 changes: 4 additions & 3 deletions tests/test_helpers.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,16 @@ access(all) fun deployAll() {
deploy("StringUtils", "../node_modules/@flowtyio/flow-contracts/contracts/flow-utils/StringUtils.cdc", [])
deploy("AddressUtils", "../node_modules/@flowtyio/flow-contracts/contracts/flow-utils/AddressUtils.cdc", [])

deploy("ContractManager", "../contracts/ContractManager.cdc", [])
deploy("FlowtyDrops", "../contracts/FlowtyDrops.cdc", [])
deploy("NFTMetadata", "../contracts/nft/NFTMetadata.cdc", [])
deploy("BaseCollection", "../contracts/nft/BaseCollection.cdc", [])

deploy("ContractManager", "../contracts/ContractManager.cdc", [])
deploy("UniversalCollection", "../contracts/nft/UniversalCollection.cdc", [])
deploy("ContractInitializer", "../contracts/initializers/ContractInitializer.cdc", [])
deploy("ContractBorrower", "../contracts/initializers/ContractBorrower.cdc", [])
deploy("OpenEditionInitializer", "../contracts/initializers/OpenEditionInitializer.cdc", [])

deploy("BaseCollection", "../contracts/nft/BaseCollection.cdc", [])
deploy("UniversalCollection", "../contracts/nft/UniversalCollection.cdc", [])
deploy("BaseNFT", "../contracts/nft/BaseNFT.cdc", [])
deploy("FlowtySwitchers", "../contracts/FlowtySwitchers.cdc", [])
deploy("FlowtyPricers", "../contracts/FlowtyPricers.cdc", [])
Expand Down

0 comments on commit 5f9abbd

Please sign in to comment.