Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NFT License View #186

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions contracts/ExampleNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ pub contract ExampleNFT: NonFungibleToken, ViewResolver {
Type<MetadataViews.NFTCollectionData>(),
Type<MetadataViews.NFTCollectionDisplay>(),
Type<MetadataViews.Serial>(),
Type<MetadataViews.Traits>()
Type<MetadataViews.Traits>(),
Type<MetadataViews.NFTLicense>()
]
}

Expand Down Expand Up @@ -159,7 +160,8 @@ pub contract ExampleNFT: NonFungibleToken, ViewResolver {
traitsView.addTrait(fooTrait)

return traitsView

case Type<MetadataViews.NFTLicense>():
return MetadataViews.nlpUtil()
}
return nil
}
Expand Down
191 changes: 191 additions & 0 deletions contracts/MetadataViews.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -737,4 +737,195 @@ pub contract MetadataViews {
return Traits(traits)
}

/// A struct to expose license information according to https://forum.onflow.org/t/flow-nft-license-project/4716
/// By default, there are only 12 possible license combinations,
/// so these are enabled by the 12 utility methods below the struct definition
/// to allow easy construction of each possible combination
/// For a given NFT, returning a license view is as simple as
/// calling the method for the desired view, like so:
///
/* pub fun resolveView(_ view: Type): AnyStruct? {
switch view {
case Type<MetadataViews.NFTLicense>():
return MetadataViews.nlpVoteCom()
case ...
*/
///
/// The first version of the NFT license standard is only deployed
/// with the license names and text descriptions. Projects must refer
/// to the proposal and license documentation for specific descriptions of
/// the rights that each license grants.
///
pub struct NFTLicense {
/// Array of the specific license identifiers
pub let rights: [String]

/// Link to a badge image that can be displayed alongside
/// the asset on a webpage for a visual representation of the license
pub var badgeLink: Media?

/// Link to a description of the specific rights that the license offers
pub var descriptionLink: Media?

/// Plain text description of the license
pub var description: String?

init() {
self.rights = []
self.badgeLink = nil
self.descriptionLink = nil
self.description = nil
}

access(contract) fun setBadgeLink(link: Media) {
self.badgeLink = link
}

access(contract) fun setDescriptionLink(link: Media) {
self.descriptionLink = link
}

access(contract) fun setDescription(_ description: String) {
self.description = description
}

access(contract) fun personalUse(): NFTLicense {
self.rights.append("NLP-PER")
return self
}

access(contract) fun votingRights(): NFTLicense {
self.rights.append("NLP-VOTE")
return self
}

access(contract) fun commercialRights(): NFTLicense {
self.rights.append("NLP-COM")
return self
}

access(contract) fun additionalContentExperienceRights(): NFTLicense {
self.rights.append("NLP-ALP")
return self
}

access(contract) fun merchandisingRights(): NFTLicense {
self.rights.append("NLP-MERCH")
return self
}

access(all) fun equals(_ otherLicense: NFTLicense): Bool {
if self.rights == otherLicense.rights {
return true
}
return false
}

}

pub fun nlpUtil(): NFTLicense {
let license = NFTLicense().personalUse().votingRights().additionalContentExperienceRights()
// license.setBadgeLink(link: Media(file: , mediaType: ))
// license.setDescriptionLink(link: Media(file: , mediaType: ))
license.setDescription("This license gives the buyer Personal Use Rights, Voting Rights, and ACE Rights")
return license
}

pub fun nlpVoteMerch(): NFTLicense {
let license = NFTLicense().personalUse().votingRights().merchandisingRights()
// license.setBadgeLink(link: Media(file: , mediaType: ))
// license.setDescriptionLink(link: Media(file: , mediaType: ))
license.setDescription("This license gives the buyer Personal Use Rights, Voting Rights, and Merch Rights")
return license
}

pub fun nlpVoteCom(): NFTLicense {
let license = NFTLicense().personalUse().votingRights().commercialRights()
// license.setBadgeLink(link: Media(file: , mediaType: ))
// license.setDescriptionLink(link: Media(file: , mediaType: ))
license.setDescription("This license gives the buyer Personal Use Rights, Voting Rights, and Comm Rights")
return license
}

pub fun nlpAceMerch(): NFTLicense {
let license = NFTLicense().personalUse().additionalContentExperienceRights().merchandisingRights()
// license.setBadgeLink(link: Media(file: , mediaType: ))
// license.setDescriptionLink(link: Media(file: , mediaType: ))
license.setDescription("This license gives the buyer Personal Use Rights, ACE Rights, and Merch Rights")
return license
}

pub fun nlpAceCom(): NFTLicense {
let license = NFTLicense().personalUse().additionalContentExperienceRights().commercialRights()
// license.setBadgeLink(link: Media(file: , mediaType: ))
// license.setDescriptionLink(link: Media(file: , mediaType: ))
license.setDescription("This license gives the buyer Personal Use Rights, ACE Rights, and Comm Rights")
return license
}

pub fun nlpUtilMerch(): NFTLicense {
let license = NFTLicense().personalUse().votingRights().additionalContentExperienceRights().merchandisingRights()
// license.setBadgeLink(link: Media(file: , mediaType: ))
// license.setDescriptionLink(link: Media(file: , mediaType: ))
license.setDescription("This license gives the buyer Personal Use Rights, Voting Rights, ACE Rights, and Merch Rights")
return license
}

pub fun nlpUtilCom(): NFTLicense {
let license = NFTLicense().personalUse().votingRights().additionalContentExperienceRights().commercialRights()
// license.setBadgeLink(link: Media(file: , mediaType: ))
// license.setDescriptionLink(link: Media(file: , mediaType: ))
license.setDescription("This license gives the buyer Personal Use Rights, Voting Rights, ACE Rights, and Comm Rights")
return license
}

pub fun nlpAce(): NFTLicense {
let license = NFTLicense().personalUse().additionalContentExperienceRights()
// license.setBadgeLink(link: Media(file: , mediaType: ))
// license.setDescriptionLink(link: Media(file: , mediaType: ))
license.setDescription("This license gives the buyer Personal Use Rights and ACE Rights")
return license
}

pub fun nlpPer(): NFTLicense {
let license = NFTLicense().personalUse()
// license.setBadgeLink(link: Media(file: , mediaType: ))
// license.setDescriptionLink(link: Media(file: , mediaType: ))
license.setDescription("This license gives the buyer Personal Use Rights")
return license
}

pub fun nlpVote(): NFTLicense {
let license = NFTLicense().personalUse().votingRights()
// license.setBadgeLink(link: Media(file: , mediaType: ))
// license.setDescriptionLink(link: Media(file: , mediaType: ))
license.setDescription("This license gives the buyer Personal Use Rights and Voting Rights")
return license
}

pub fun nlpCom(): NFTLicense {
let license = NFTLicense().personalUse().commercialRights()
// license.setBadgeLink(link: Media(file: , mediaType: ))
// license.setDescriptionLink(link: Media(file: , mediaType: ))
license.setDescription("This license gives the buyer Personal Use Rights and Comm Rights")
return license
}

pub fun nlpMerch(): NFTLicense {
let license = NFTLicense().personalUse().merchandisingRights()
// license.setBadgeLink(link: Media(file: , mediaType: ))
// license.setDescriptionLink(link: Media(file: , mediaType: ))
license.setDescription("This license gives the buyer Personal Use Rights and Merch Rights")
return license
}

pub fun getNFTLicense(_ viewResolver: &{Resolver}) : NFTLicense? {
if let view = viewResolver.resolveView(Type<NFTLicense>()) {
if let v = view as? NFTLicense {
return v
}
}
return nil
}

}
Loading
Loading