Skip to content

Commit

Permalink
Merge branch 'master' into standard-v2
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed May 2, 2024
2 parents 40c3de7 + d8db9b2 commit 7f576a1
Show file tree
Hide file tree
Showing 11 changed files with 1,019 additions and 18 deletions.
55 changes: 53 additions & 2 deletions contracts/ExampleNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ access(all) contract ExampleNFT: NonFungibleToken {
Type<MetadataViews.NFTCollectionData>(),
Type<MetadataViews.NFTCollectionDisplay>(),
Type<MetadataViews.Serial>(),
Type<MetadataViews.Traits>()
Type<MetadataViews.Traits>(),
Type<MetadataViews.EVMBridgedMetadata>()
]
}

Expand Down Expand Up @@ -123,6 +124,30 @@ access(all) contract ExampleNFT: NonFungibleToken {
traitsView.addTrait(fooTrait)

return traitsView
case Type<MetadataViews.EVMBridgedMetadata>():
// Implementing this view gives the project control over how the bridged NFT is represented as an
// ERC721 when bridged to EVM on Flow via the public infrastructure bridge.
// Get the contract-level name and symbol values
let contractLevel = ExampleNFT.resolveContractView(
resourceType: nil,
viewType: Type<MetadataViews.EVMBridgedMetadata>()
) as! MetadataViews.EVMBridgedMetadata?
?? panic("Could not resolve contract-level EVMBridgedMetadata")
// Compose the token-level URI based on a base URI and the token ID, pointing to a JSON file. This
// would be a file you've uploaded and are hosting somewhere - in this case HTTP, but this could be
// IPFS, S3, a data URL containing the JSON directly, etc.
let baseURI = "https://example-nft.onflow.org/token-metadata/"
let uriValue = self.id.toString().concat(".json")

return MetadataViews.EVMBridgedMetadata(
name: contractLevel.name,
symbol: contractLevel.symbol,
uri: MetadataViews.URI(
baseURI: baseURI, // defining baseURI results in a concatenation of baseURI and value
value: self.id.toString().concat(".json")
)
)
}
return nil
}
Expand Down Expand Up @@ -225,7 +250,8 @@ access(all) contract ExampleNFT: NonFungibleToken {
access(all) view fun getContractViews(resourceType: Type?): [Type] {
return [
Type<MetadataViews.NFTCollectionData>(),
Type<MetadataViews.NFTCollectionDisplay>()
Type<MetadataViews.NFTCollectionDisplay>(),
Type<MetadataViews.EVMBridgedMetadata>()
]
}

Expand Down Expand Up @@ -264,6 +290,20 @@ access(all) contract ExampleNFT: NonFungibleToken {
"twitter": MetadataViews.ExternalURL("https://twitter.com/flow_blockchain")
}
)
case Type<MetadataViews.EVMBridgedMetadata>():
// Implementing this view gives the project control over how the bridged NFT is represented as an ERC721
// when bridged to EVM on Flow via the public infrastructure bridge.
// Compose the contract-level URI. In this case, the contract metadata is located on some HTTP host,
// but it could be IPFS, S3, a data URL containing the JSON directly, etc.
return MetadataViews.EVMBridgedMetadata(
name: "ExampleNFT",
symbol: "XMPL",
uri: MetadataViews.URI(
baseURI: nil, // setting baseURI as nil sets the given value as the uri field value
value: "https://example-nft.onflow.org/contract-metadata.json"
)
)
}
return nil
}
Expand Down Expand Up @@ -303,6 +343,17 @@ access(all) contract ExampleNFT: NonFungibleToken {
}
}

/// @return An array of Types defining the implemented views. This value will be used by
/// developers to know which parameter to pass to the resolveView() method.
///
access(all) view fun getViews(): [Type] {
return [
Type<MetadataViews.NFTCollectionData>(),
Type<MetadataViews.NFTCollectionDisplay>(),
Type<MetadataViews.EVMBridgedMetadata>()
]
}

init() {

// Set the named paths
Expand Down
9 changes: 9 additions & 0 deletions contracts/MetadataViews.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -767,4 +767,13 @@ access(all) contract MetadataViews {
}
}

access(all) fun getEVMBridgedMetadata(_ viewResolver: &{ViewResolver.Resolver}) : EVMBridgedMetadata? {
if let view = viewResolver.resolveView(Type<EVMBridgedMetadata>()) {
if let v = view as? EVMBridgedMetadata {
return v
}
}
return nil
}

}
Loading

0 comments on commit 7f576a1

Please sign in to comment.