-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from packagelabs/blind-nft-view
Add metadata view for blind NFTs
- Loading branch information
Showing
9 changed files
with
166 additions
and
25 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 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 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,45 @@ | ||
import {{ contractName }} from {{{ contractAddress }}} | ||
import NonFungibleToken from {{{ imports.NonFungibleToken }}} | ||
import MetadataViews from {{{ imports.MetadataViews }}} | ||
import FreshmintMetadataViews from {{{ imports.FreshmintMetadataViews }}} | ||
|
||
pub struct NFT { | ||
pub let id: UInt64 | ||
|
||
pub let display: MetadataViews.Display | ||
pub let metadataHash: String? | ||
|
||
init( | ||
id: UInt64, | ||
display: MetadataViews.Display, | ||
metadataHash: String? | ||
) { | ||
self.id = id | ||
self.display = display | ||
self.metadataHash = metadataHash | ||
} | ||
} | ||
|
||
pub fun main(address: Address, id: UInt64): NFT? { | ||
if let col = getAccount(address).getCapability<&{{ contractName }}.Collection{NonFungibleToken.CollectionPublic, {{ contractName }}.{{ contractName }}CollectionPublic}>({{ contractName }}.CollectionPublicPath).borrow() { | ||
if let nft = col.borrow{{ contractName }}(id: id) { | ||
|
||
let display = nft.resolveView(Type<MetadataViews.Display>())! as! MetadataViews.Display | ||
|
||
var metadataHash: String? = nil | ||
|
||
if let blindNFTView = nft.resolveView(Type<FreshmintMetadataViews.BlindNFT>()) { | ||
let blindNFT = blindNFTView as! FreshmintMetadataViews.BlindNFT | ||
metadataHash = String.encodeHex(blindNFT.metadataHash) | ||
} | ||
|
||
return NFT( | ||
id: id, | ||
display: display, | ||
metadataHash: metadataHash | ||
) | ||
} | ||
} | ||
|
||
return nil | ||
} |
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,13 @@ | ||
pub contract FreshmintMetadataViews { | ||
|
||
// BlindNFT returns a representation of | ||
// a hidden or "blind" NFT, which at this point | ||
// is a secure hash of the NFT's metadata values. | ||
pub struct BlindNFT { | ||
pub let metadataHash: [UInt8] | ||
|
||
init(metadataHash: [UInt8]) { | ||
self.metadataHash = metadataHash | ||
} | ||
} | ||
} |
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 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 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,16 @@ | ||
import { ContractImports } from '../config'; | ||
import TemplateGenerator from './TemplateGenerator'; | ||
|
||
export class CommonNFTGenerator extends TemplateGenerator { | ||
static getNFT({ | ||
imports, | ||
contractName, | ||
contractAddress, | ||
}: { | ||
imports: ContractImports; | ||
contractName: string; | ||
contractAddress: string; | ||
}): string { | ||
return this.generate('../../../cadence/common-nft/scripts/get_nft.cdc', { imports, contractName, contractAddress }); | ||
} | ||
} |
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,7 @@ | ||
import TemplateGenerator from './TemplateGenerator'; | ||
|
||
export class FreshmintMetadataViewsGenerator extends TemplateGenerator { | ||
static contract(): string { | ||
return this.generate('../../../cadence/metadata-views/FreshmintMetadataViews.cdc', {}); | ||
} | ||
} |
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