Skip to content

Commit

Permalink
get deployment transaction sample working
Browse files Browse the repository at this point in the history
  • Loading branch information
austinkline committed May 31, 2024
1 parent f1b127f commit ab0047a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 29 deletions.
2 changes: 1 addition & 1 deletion args/create_open_edition_contract.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"type": "String","value": "MyCollection"},{"type": "Dictionary","value": [{"key": {"type": "String","value": "collectionDisplay"},"value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.MetadataViews.NFTCollectionDisplay","fields": [{"name": "name","value": {"type": "String","value": "My Collection"}},{"name": "description","value": {"type": "String","value": "This is a test collection made by Flowty's contract factory!"}},{"name": "externalURL","value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.MetadataViews.ExternalURL","fields": [{"name": "url","value": {"type": "String","value": "https://flowty.io"}}]}}},{"name": "squareImage","value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.MetadataViews.Media","fields": [{"name": "file","value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.MetadataViews.IPFSFile","fields": [{"name": "cid","value": {"type": "String","value": "QmWWLhnkPR3ejavNtzeJcdG9fwcBHKwBVEP4pZ9rGbdHEM"}},{"name": "path","value": {"type": "Optional","value": null}}]}}},{"name": "mediaType","value": {"type": "String","value": "image/png"}}]}}},{"name": "bannerImage","value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.MetadataViews.Media","fields": [{"name": "file","value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.MetadataViews.IPFSFile","fields": [{"name": "cid","value": {"type": "String","value": "QmYD8e5s59qYFFQXref1YzyqW1WKYUMPxfqVDEis2s23BF"}},{"name": "path","value": {"type": "Optional","value": null}}]}}},{"name": "mediaType","value": {"type": "String","value": "image/png"}}]}}},{"name": "socials","value": {"type": "Dictionary","value": [{"key": {"type": "String","value": "twitter"},"value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.MetadataViews.ExternalURL","fields": [{"name": "url","value": {"type": "String","value": "https://x.com/flowty_io"}}]}}}]}}]}}},{"key": {"type": "String","value": "data"},"value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.NFTMetadata.Metadata","fields": [{"name": "name","value": {"type": "String","value": "Fluid"}},{"name": "description","value": {"type": "String","value": "Fluid is an open edition collection generated by the Flowty contract factory!"}},{"name": "thumbnail","value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.MetadataViews.IPFSFile","fields": [{"name": "cid","value": {"type": "String","value": "QmWWLhnkPR3ejavNtzeJcdG9fwcBHKwBVEP4pZ9rGbdHEM"}},{"name": "path","value": {"type": "Optional","value": null}}]}}},{"name": "traits","value": {"type": "Optional","value": null}},{"name": "editions","value": {"type": "Optional","value": null}},{"name": "externalURL","value": {"type": "Optional","value": null}},{"name": "data","value": {"type": "Dictionary","value": []}}]}}}]}]
[{"type": "String","value": "MyCollection"},{"type": "Dictionary","value": [{"key": {"type": "String","value": "collectionInfo"},"value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.NFTMetadata.CollectionInfo","fields": [{"name": "collectionDisplay","value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.MetadataViews.NFTCollectionDisplay","fields": [{"name": "name","value": {"type": "String","value": "The Open Edition Collection"}},{"name": "description","value": {"type": "String","value": "This collection is used as an example to help you develop your next Open Edition Flow NFT"}},{"name": "externalURL","value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.MetadataViews.ExternalURL","fields": [{"name": "url","value": {"type": "String","value": "https://flowty.io"}}]}}},{"name": "squareImage","value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.MetadataViews.Media","fields": [{"name": "file","value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.MetadataViews.IPFSFile","fields": [{"name": "cid","value": {"type": "String","value": "QmWWLhnkPR3ejavNtzeJcdG9fwcBHKwBVEP4pZ9rGbdHEM"}},{"name": "path","value": {"type": "Optional","value": null}}]}}},{"name": "mediaType","value": {"type": "String","value": "image/png"}}]}}},{"name": "bannerImage","value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.MetadataViews.Media","fields": [{"name": "file","value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.MetadataViews.IPFSFile","fields": [{"name": "cid","value": {"type": "String","value": "QmYD8e5s59qYFFQXref1YzyqW1WKYUMPxfqVDEis2s23BF"}},{"name": "path","value": {"type": "Optional","value": null}}]}}},{"name": "mediaType","value": {"type": "String","value": "image/png"}}]}}},{"name": "socials","value": {"type": "Dictionary","value": [{"key": {"type": "String","value": "twitter"},"value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.MetadataViews.ExternalURL","fields": [{"name": "url","value": {"type": "String","value": "https://x.com/flowty_io"}}]}}}]}}]}}}]}}},{"key": {"type": "String","value": "data"},"value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.NFTMetadata.Metadata","fields": [{"name": "name","value": {"type": "String","value": "Fluid"}},{"name": "description","value": {"type": "String","value": "Fluid is an open edition collection generated by the Flowty contract factory!"}},{"name": "thumbnail","value": {"type": "Struct","value": {"id": "A.f8d6e0586b0a20c7.MetadataViews.IPFSFile","fields": [{"name": "cid","value": {"type": "String","value": "QmWWLhnkPR3ejavNtzeJcdG9fwcBHKwBVEP4pZ9rGbdHEM"}},{"name": "path","value": {"type": "Optional","value": null}}]}}},{"name": "traits","value": {"type": "Optional","value": null}},{"name": "editions","value": {"type": "Optional","value": null}},{"name": "externalURL","value": {"type": "Optional","value": null}},{"name": "data","value": {"type": "Dictionary","value": []}}]}}}]}]
4 changes: 2 additions & 2 deletions contracts/nft/ContractFactory.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import "ContractFactoryTemplate"
import "AddressUtils"

access(all) contract ContractFactory {
access(all) fun createContract(templateType: Type, acct: auth(AddContract) &Account, name: String, params: {String: AnyStruct}) {
access(all) fun createContract(templateType: Type, acct: auth(AddContract) &Account, name: String, params: {String: AnyStruct}, initializeIdentifier: String) {
let templateAddr = AddressUtils.parseAddress(templateType)!
let contractName = templateType.identifier.split(separator: ".")[2]
let templateContract = getAccount(templateAddr).contracts.borrow<&{ContractFactoryTemplate}>(name: contractName)
?? panic("provided type is not a ContractTemplateFactory")

templateContract.createContract(acct: acct, name: name, params: params)
templateContract.createContract(acct: acct, name: name, params: params, initializeIdentifier: initializeIdentifier)
}
}
6 changes: 4 additions & 2 deletions contracts/nft/ContractFactoryTemplate.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import "BaseNFT"
import "BaseCollection"
import "NFTMetadata"
import "UniversalCollection"
import "ContractBorrower"

import "AddressUtils"

access(all) contract interface ContractFactoryTemplate {
access(all) fun createContract(acct: auth(AddContract) &Account, name: String, params: {String: AnyStruct})
access(all) fun createContract(acct: auth(AddContract) &Account, name: String, params: {String: AnyStruct}, initializeIdentifier: String)

access(all) fun getContractAddresses(): {String: Address} {
let d: {String: Address} = {
Expand All @@ -24,7 +25,8 @@ access(all) contract interface ContractFactoryTemplate {
"NFTMetadata": AddressUtils.parseAddress(Type<&NFTMetadata>())!,
"UniversalCollection": AddressUtils.parseAddress(Type<&UniversalCollection>())!,
"BaseCollection": AddressUtils.parseAddress(Type<&{BaseCollection}>())!,
"AddressUtils": AddressUtils.parseAddress(Type<&AddressUtils>())!
"AddressUtils": AddressUtils.parseAddress(Type<&AddressUtils>())!,
"ContractBorrower": AddressUtils.parseAddress(Type<ContractBorrower>())!
}

return d
Expand Down
34 changes: 11 additions & 23 deletions contracts/nft/OpenEditionTemplate.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,50 @@ import "MetadataViews"
import "NFTMetadata"

access(all) contract OpenEditionTemplate: ContractFactoryTemplate {
access(all) fun createContract(acct: auth(AddContract) &Account, name: String, params: {String: AnyStruct}) {
access(all) fun createContract(acct: auth(AddContract) &Account, name: String, params: {String: AnyStruct}, initializeIdentifier: String) {
let code = self.generateImports(names: [
"NonFungibleToken",
"MetadataViews",
"ViewResolver",
"FlowtyDrops",
"BaseNFT",
"BaseCollection",
"NFTMetadata",
"UniversalCollection",
"BaseCollection",
"AddressUtils"
]).concat("\n\n"
"ContractBorrower",
"BaseCollection"
]).concat("\n\n")
.concat("access(all) contract ").concat(name).concat(": BaseCollection {\n")
.concat(" access(all) var MetadataCap: Capability<&NFTMetadata.Container>\n")
.concat(" access(all) var totalSupply: UInt64\n")
.concat("\n\n")
.concat(" access(all) resource NFT: BaseNFT.NFT {\n")
.concat(" access(all) let id: UInt64\n")
.concat(" access(all) let metadataID: UInt64\n")
.concat("\n")
.concat("\n\n")
.concat(" init() {\n")
.concat(" ").concat(name).concat(".totalSupply = ").concat(name).concat(".totalSupply + 1\n")
.concat(" self.id = ").concat(name).concat(".totalSupply\n")
.concat(" self.metadataID = 0\n")
.concat(" }\n")
.concat(" }\n")
.concat("\n\n")
.concat(" access(all) resource NFTMinter: FlowtyDrops.Minter {\n")
.concat(" access(contract) fun createNextNFT(): @{NonFungibleToken.NFT} {\n")
.concat(" return <- create NFT()\n")
.concat(" }\n")
.concat(" }\n")
.concat("\n\n")
.concat("\n")
.concat(" access(all) fun createEmptyCollection(nftType: Type): @{NonFungibleToken.Collection} {\n")
.concat(" return <- UniversalCollection.createCollection(nftType: Type<@NFT>())\n"))
.concat(" return <- UniversalCollection.createCollection(nftType: Type<@NFT>())\n")
.concat(" }\n")
.concat("\n\n")
.concat(" init(collectionDisplay: MetadataViews.NFTCollectionDisplay, data: NFTMetadata.Metadata) {\n")
.concat("\n")
.concat(" init(params: {String: AnyStruct}, initializeIdentifier: String) {\n")
.concat(" self.totalSupply = 0\n")
.concat(" let collectionInfo = NFTMetadata.CollectionInfo(collectionDisplay: collectionDisplay)\n")
.concat("\n\n")
.concat(" let acct: auth(Storage, Contracts, Keys, Inbox, Capabilities) &Account = Account(payer: self.account)\n")
.concat(" let cap = acct.capabilities.account.issue<auth(Storage, Contracts, Keys, Inbox, Capabilities) &Account>()\n")
.concat(" self.account.storage.save(cap, to: /storage/metadataAuthAccount_").concat(name).concat(")\n")
.concat("\n\n")
.concat(" let caps = NFTMetadata.initialize(acct: acct.capabilities.account.issue<auth(SaveValue, IssueStorageCapabilityController, PublishCapability) &Account>().borrow()!, collectionInfo: collectionInfo)\n")
.concat(" self.MetadataCap = caps.pubCap\n")
.concat(" caps.ownerCap.borrow()!.addMetadata(id: 0, data: data)\n")
.concat(" self.MetadataCap = ContractBorrower.borrowInitializer(typeIdentifier: initializeIdentifier).initialize(contractAcct: self.account, params: params).pubCap\n")
.concat("\n\n")
.concat(" let minter <- create NFTMinter()\n")
.concat(" self.account.storage.save(<-minter, to: FlowtyDrops.getMinterStoragePath(type: self.getType()))\n")
.concat(" self.account.capabilities.storage.issue<&{FlowtyDrops.Minter}>(FlowtyDrops.getMinterStoragePath(type: self.getType()))\n")
.concat(" }\n")
.concat("}\n")

acct.contracts.add(name: name, code: code.utf8, params["collectionDisplay"]! as! MetadataViews.NFTCollectionDisplay, params["data"]! as! NFTMetadata.Metadata)
acct.contracts.add(name: name, code: code.utf8, params, initializeIdentifier)
}
}
3 changes: 2 additions & 1 deletion transactions/factory/create_open_edition_contract.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import "ContractFactory"
import "ContractFactoryTemplate"
import "OpenEditionTemplate"
import "MetadataViews"
import "OpenEditionInitializer"

transaction(name: String, params: {String: AnyStruct}) {
prepare(acct: auth(AddContract) &Account) {
ContractFactory.createContract(templateType: Type<OpenEditionTemplate>(), acct: acct, name: name, params: params)
ContractFactory.createContract(templateType: Type<OpenEditionTemplate>(), acct: acct, name: name, params: params, initializeIdentifier: Type<OpenEditionInitializer>().identifier)
}
}

0 comments on commit ab0047a

Please sign in to comment.