Created
August 18, 2021 19:29
-
-
Save briandilley/5e92bb6244724ae30f35d71d983012f8 to your computer and use it in GitHub Desktop.
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
import NonFungibleToken from 0xNONFUNGIBLETOKEN | |
pub contract NFTMetaDataExample: NonFungibleToken { | |
// The immutable data for an NFT, this is the actual NFT | |
// | |
pub resource NFT: NonFungibleToken.INFT { | |
pub let id: UInt64 | |
pub let metadata: {String: TenantService.MetadataField} | |
init(metadata: {String: TenantService.MetadataField}) { | |
self.id = ... | |
self.metadata = metadata | |
} | |
} | |
// ===================================== | |
// Metadata | |
// ===================================== | |
// The type of a meta data field | |
// | |
pub enum MetadataFieldType: UInt8 { | |
pub case STRING | |
pub case NUMBER | |
pub case BOOLEAN | |
pub case DATE | |
pub case DATE_TIME | |
pub case URL | |
pub case URL_WITH_HASH | |
pub case GEO_POINT | |
} | |
// a meta data field of variable type | |
// | |
pub struct MetadataField { | |
pub let type: MetadataFieldType | |
pub let value: AnyStruct | |
init(_ type: MetadataFieldType, _ value: AnyStruct) { | |
self.type = type | |
self.value = value | |
} | |
pub fun getStringValue(): String? { | |
if self.type != MetadataFieldType.STRING { | |
return nil | |
} | |
return self.value as? String | |
} | |
pub fun getNumberValue(): String? { | |
if self.type != MetadataFieldType.NUMBER { | |
return nil | |
} | |
return self.value as? String | |
} | |
pub fun getBooleanValue(): Bool? { | |
if self.type != MetadataFieldType.BOOLEAN { | |
return nil | |
} | |
return self.value as? Bool | |
} | |
pub fun getURLValue(): String? { | |
if self.type != MetadataFieldType.URL { | |
return nil | |
} | |
return self.value as? String | |
} | |
pub fun getDateValue(): String? { | |
if self.type != MetadataFieldType.DATE { | |
return nil | |
} | |
return self.value as? String | |
} | |
pub fun getDateTimeValue(): String? { | |
if self.type != MetadataFieldType.DATE_TIME { | |
return nil | |
} | |
return self.value as? String | |
} | |
pub fun getURLWithHashValue(): URLWithHash? { | |
if self.type != MetadataFieldType.URL_WITH_HASH { | |
return nil | |
} | |
return self.value as? URLWithHash | |
} | |
pub fun getGeoPointValue(): GeoPoint? { | |
if self.type != MetadataFieldType.GEO_POINT { | |
return nil | |
} | |
return self.value as? GeoPoint | |
} | |
} | |
// A url with a hash of the contents found at the url | |
// | |
pub struct URLWithHash { | |
pub let url: String | |
pub let hash: String? | |
pub let hashAlgo: String? | |
init(_ url: String, _ hash: String, _ hashAlgo: String?) { | |
self.url = url | |
self.hash = hash | |
self.hashAlgo = hashAlgo | |
} | |
} | |
// A geo point without any specific projection | |
// | |
pub struct GeoPoint { | |
pub let lat: UFix64 | |
pub let lng: UFix64 | |
init(_ lat: UFix64, _ lng: UFix64) { | |
self.lat = lat | |
self.lng = lng | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment