From b1a54fa5e1475afcabbd471cbd3eb9eb3258a6e8 Mon Sep 17 00:00:00 2001 From: Bjarte Stien Karlsen Date: Wed, 31 May 2023 09:44:06 +0200 Subject: [PATCH 1/2] first stab at adding nft license view with methods on MetadataViews to create the 12 combinations --- contracts/MetadataViews.cdc | 97 ++++++++++++++++++++++++++++++++++--- 1 file changed, 91 insertions(+), 6 deletions(-) diff --git a/contracts/MetadataViews.cdc b/contracts/MetadataViews.cdc index 7aa7bb4b..f303a2e5 100644 --- a/contracts/MetadataViews.cdc +++ b/contracts/MetadataViews.cdc @@ -288,7 +288,7 @@ pub contract MetadataViews { } return nil } - + /// View that defines the composable royalty standard that gives marketplaces a /// unified interface to support NFT royalties. /// @@ -395,8 +395,8 @@ pub contract MetadataViews { pub let mediaType: String init(file: AnyStruct{File}, mediaType: String) { - self.file=file - self.mediaType=mediaType + self.file=file + self.mediaType=mediaType } } @@ -640,7 +640,7 @@ pub contract MetadataViews { /// @return A optional Rarity struct /// pub fun getRarity(_ viewResolver: &{Resolver}) : Rarity? { - if let view = viewResolver.resolveView(Type()) { + if let vTiew = viewResolver.resolveView(Type()) { if let v = view as? Rarity { return v } @@ -686,7 +686,7 @@ pub contract MetadataViews { init(_ traits: [Trait]) { self.traits = traits } - + /// Adds a single Trait to the Traits view /// /// @param Trait: The trait struct to be added @@ -737,5 +737,90 @@ pub contract MetadataViews { return Traits(traits) } + /// A struct to expose license information according to https://forum.onflow.org/t/flow-nft-license-project/4716 + pub struct NFTLicense { + pub let licenses: {String:Bool} + + init() { + self.licenses={} + } + + + access(contract) fun personalUse() :NFTLicense{ + self.licenses["NLP-PER"]=true + return self + } + + access(contract) fun votingRights() :NFTLicense{ + self.licenses["NFL-VOTE"]=true + return self + } + + access(contract) fun commercialRights() :NFTLicense{ + self.licenses["NFL-COM"]=true + return self + } + + access(contract) fun additionalContentExperienceRights() :NFTLicense{ + self.licenses["NLP-ALP"]=true + return self + } + + access(contract) fun merchandisingRights() :NFTLicense{ + self.licenses["NLP-MERCH"] + return self + } + + } + + pub fun nlpUtil() :NFTLicense { + return NFTLicense().personalUse().votingRights().additionalContentExperienceRights() + } + + pub fun nlpVoteMerch() :NFTLicense { + return NFTLicense().personalUse().votingRights().merchandisingRights() + } + + pub fun nlpVoteCom() :NFTLicense{ + return NFTLicense().personalUse().votingRights().commercialRights() + } + + pub fun nlpAceMerch() :NFTLicense { + return NFTLicense().personalUse().additionalContentExperienceRights().merchandisingRights() + } + + pub fun nlpAceCom():NFTLicense{ + return NFTLicense().personalUse().additionalContentExperienceRights().commercialRights() + } + + pub fun nlpUtilMerch():NFTLicense { + return NFTLicense().personalUse().votingRights().additionalContentExperienceRights().merchandisingRights() + } + + pub fun nlpUtilCom():NFTLicense{ + return NFTLicense().personalUse().votingRights().additionalContentExperienceRights().commercialRights() + } + + pub fun nlpAce() : NFTLicense{ + return NFTLicense().additionalContentExperienceRights() + } + + pub fun nlpPer() : NFTLicense{ + return NFTLicense().personalUse() + } + + pub fun nlpVote() : NFTLicense { + return NFTLicense().votingRights() + } + + pub fun nlpCom() : NFTLicense{ + return NFTLicense().commercialRights() + } + + pub fun nlpMerch() :NFTLicense { + return NFTLicense().merchandisingRights() + } + + } - \ No newline at end of file + From fc696e424327044c05b6f57f05a754dc7d1e0425 Mon Sep 17 00:00:00 2001 From: Bjarte Stien Karlsen Date: Wed, 31 May 2023 09:46:42 +0200 Subject: [PATCH 2/2] use array and not map --- contracts/MetadataViews.cdc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/contracts/MetadataViews.cdc b/contracts/MetadataViews.cdc index f303a2e5..7c935073 100644 --- a/contracts/MetadataViews.cdc +++ b/contracts/MetadataViews.cdc @@ -739,35 +739,35 @@ pub contract MetadataViews { /// A struct to expose license information according to https://forum.onflow.org/t/flow-nft-license-project/4716 pub struct NFTLicense { - pub let licenses: {String:Bool} + pub let licenses: [String] init() { - self.licenses={} + self.licenses=[] } access(contract) fun personalUse() :NFTLicense{ - self.licenses["NLP-PER"]=true + self.licenses.append("NLP-PER") return self } access(contract) fun votingRights() :NFTLicense{ - self.licenses["NFL-VOTE"]=true + self.licenses.append("NFL-VOTE") return self } access(contract) fun commercialRights() :NFTLicense{ - self.licenses["NFL-COM"]=true + self.licenses.append("NFL-COM") return self } access(contract) fun additionalContentExperienceRights() :NFTLicense{ - self.licenses["NLP-ALP"]=true + self.licenses.append("NLP-ALP") return self } access(contract) fun merchandisingRights() :NFTLicense{ - self.licenses["NLP-MERCH"] + self.licenses.append("NLP-MERCH") return self }