-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BaseNFT interfaces and helper contracts
- Loading branch information
1 parent
9d11f92
commit ced139d
Showing
7 changed files
with
272 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import "MetadataViews" | ||
import "NonFungibleToken" | ||
import "NFTMetadata" | ||
|
||
access(all) contract interface BaseNFTVars { | ||
access(all) let collectionDisplay: MetadataViews.NFTCollectionDisplay | ||
access(all) var totalMinted: UInt64 | ||
|
||
access(all) var MetadataCap: Capability<&NFTMetadata.Container> | ||
access(all) var totalSupply: UInt64 | ||
access(all) fun createEmptyCollection(nftType: Type): @{NonFungibleToken.Collection} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import "NonFungibleToken" | ||
import "MetadataViews" | ||
|
||
access(all) contract NFTMetadata { | ||
access(all) let StoragePath: StoragePath | ||
access(all) let PublicPath: PublicPath | ||
|
||
access(all) entitlement Owner | ||
|
||
access(all) event MetadataFrozen(uuid: UInt64, owner: Address?) | ||
|
||
access(all) struct CollectionInfo { | ||
access(all) var collectionDisplay: MetadataViews.NFTCollectionDisplay | ||
|
||
init(collectionDisplay: MetadataViews.NFTCollectionDisplay) { | ||
self.collectionDisplay = collectionDisplay | ||
} | ||
} | ||
|
||
access(all) struct Metadata { | ||
// these are used to create the display metadata view so that we can concatenate | ||
// the id onto it. | ||
access(all) let name: String | ||
access(all) let description: String | ||
access(all) let thumbnail: {MetadataViews.File} | ||
|
||
access(all) let traits: MetadataViews.Traits? | ||
access(all) let editions: MetadataViews.Editions? | ||
access(all) let externalURL: MetadataViews.ExternalURL? | ||
|
||
access(all) let data: {String: AnyStruct} // general-purpose data bucket | ||
init( | ||
name: String, | ||
description: String, | ||
thumbnail: {MetadataViews.File}, | ||
traits: MetadataViews.Traits?, | ||
editions: MetadataViews.Editions?, | ||
externalURL: MetadataViews.ExternalURL?, | ||
data: {String: AnyStruct} | ||
) { | ||
self.name = name | ||
self.description = description | ||
self.thumbnail = thumbnail | ||
|
||
self.traits = traits | ||
self.editions = editions | ||
self.externalURL = externalURL | ||
|
||
self.data = {} | ||
} | ||
} | ||
|
||
access(all) resource Container { | ||
access(all) var collectionInfo: CollectionInfo | ||
access(all) let metadata: {UInt64: Metadata} | ||
access(all) var frozen: Bool | ||
|
||
access(all) fun borrowMetadata(id: UInt64): &Metadata? { | ||
return &self.metadata[id] | ||
} | ||
|
||
access(Owner) fun addMetadata(id: UInt64, data: Metadata) { | ||
pre { | ||
self.metadata[id] == nil: "id already has metadata assigned" | ||
} | ||
|
||
self.metadata[id] = data | ||
} | ||
|
||
access(Owner) fun freeze() { | ||
self.frozen = true | ||
emit MetadataFrozen(uuid: self.uuid, owner: self.owner?.address) | ||
} | ||
|
||
init(collectionInfo: CollectionInfo) { | ||
self.collectionInfo = collectionInfo | ||
self.metadata = {} | ||
self.frozen = false | ||
} | ||
} | ||
|
||
access(all) struct InitializeCaps { | ||
access(all) let pubCap: Capability<&Container> | ||
access(all) let ownerCap: Capability<auth(Owner) &Container> | ||
|
||
init(pubCap: Capability<&Container>, ownerCap: Capability<auth(Owner) &Container>) { | ||
self.pubCap = pubCap | ||
self.ownerCap = ownerCap | ||
} | ||
} | ||
|
||
access(all) fun createContainer(collectionInfo: CollectionInfo): @Container { | ||
return <- create Container(collectionInfo: collectionInfo) | ||
} | ||
|
||
access(all) fun initialize(acct: auth(SaveValue, IssueStorageCapabilityController, PublishCapability) &Account, collectionInfo: CollectionInfo): InitializeCaps { | ||
let container <- self.createContainer(collectionInfo: collectionInfo) | ||
acct.storage.save(<-container, to: self.StoragePath) | ||
let pubCap = acct.capabilities.storage.issue<&Container>(self.StoragePath) | ||
let ownerCap = acct.capabilities.storage.issue<auth(Owner) &Container>(self.StoragePath) | ||
return InitializeCaps(pubCap: pubCap, ownerCap: ownerCap) | ||
} | ||
|
||
access(all) struct UriFile: MetadataViews.File { | ||
access(self) let url: String | ||
|
||
access(all) view fun uri(): String { | ||
return self.url | ||
} | ||
|
||
init(_ url: String) { | ||
self.url = url | ||
} | ||
} | ||
|
||
init() { | ||
let identifier = "NFTMetadata_".concat(self.account.address.toString()) | ||
self.StoragePath = StoragePath(identifier: identifier)! | ||
self.PublicPath = PublicPath(identifier: identifier)! | ||
} | ||
} |
Oops, something went wrong.