Smart Contract

MotoGPPackMetadata

A.a49cc0ee46c54bfb.MotoGPPackMetadata

Deployed

1d ago
Feb 26, 2026, 09:43:52 PM UTC

Dependents

0 imports
1import FungibleToken from 0xf233dcee88fe0abe
2import NonFungibleToken from 0x1d7e57aa55817448 
3import MetadataViews from 0x1d7e57aa55817448
4import MotoGPAdmin from 0xa49cc0ee46c54bfb
5import ContractVersion from 0xb223b2bfe4b8ffb5
6import MotoGPRegistry from 0xa49cc0ee46c54bfb 
7
8// Contract to hold Metadata for MotoGPPacks. Metadata is accessed using the Pack's packID (not the Pack's id)
9//
10pub contract MotoGPPackMetadata: ContractVersion {
11
12    pub fun getVersion():String {
13        return "1.0.2"
14    }
15
16   //////////////////////////////////
17   // MotoGPPack MetadataViews implementation
18   //////////////////////////////////
19
20    access(contract) fun resolveDisplayView(packID: UInt64): MetadataViews.Display {
21        let metadata = self.metadatas[packID]!
22        return MetadataViews.Display(
23            name: metadata.name, 
24            description: metadata.description,
25            thumbnail: MetadataViews.HTTPFile(url: metadata.imageUrl)
26        )
27    }
28
29    access(contract) fun resolveRoyaltiesView(): MetadataViews.Royalties {
30        var royaltyList: [MetadataViews.Royalty] = []
31        let capability = getAccount(MotoGPRegistry.get(key: "motogp-royalty-receiver")! as! Address).getCapability<&{FungibleToken.Receiver}>(MetadataViews.getRoyaltyReceiverPublicPath())
32        let royalty:MetadataViews.Royalty = MetadataViews.Royalty(
33            receiver: capability,
34            cut: 0.075,
35            description: "Creator royalty"
36        )
37        royaltyList.append(royalty)
38        return MetadataViews.Royalties(royaltyList)
39    }
40
41    access(contract) fun resolveExternalURLView(id: UInt64): MetadataViews.ExternalURL {
42        return MetadataViews.ExternalURL("https://motogp-ignition.com/nft/pack/".concat(id.toString()))
43    }
44
45    access(contract) fun resolveNFTCollectionDisplayView(): MetadataViews.NFTCollectionDisplay {
46        let socials:{String: MetadataViews.ExternalURL} = {}
47        socials.insert(key: "twitter", MetadataViews.ExternalURL("https://twitter.com/MotoGPIgnition"))
48        
49        let squareMedia = MetadataViews.Media(
50            file: MetadataViews.HTTPFile(url: "https://ipfs-assets.animocabrands.com/MGPI-pack-Square.jpg"),
51            mediaType: "image/jpeg"
52        )
53        let bannerMedia = MetadataViews.Media(
54            file: MetadataViews.HTTPFile(url: "https://ipfs-assets.animocabrands.com/MGPI-pack-Banner.jpg"),
55            mediaType: "image/jpeg"
56        ) 
57        return MetadataViews.NFTCollectionDisplay(
58            name: "MotoGPPack", 
59            description: "MotoGP Ignition is an NFT collection for MotoGP enthusiasts",
60            externalURL: MetadataViews.ExternalURL("https://motogp-ignition.com"),
61            squareImage: squareMedia,
62            bannerImage: bannerMedia,
63            socials: socials
64        )
65    }
66
67    access(contract) fun resolveMediasView(packID: UInt64): MetadataViews.Medias {
68        let metadata = self.metadatas[packID]!
69        let imageUrl = metadata.imageUrl
70        let medias:[MetadataViews.Media] = []
71        medias.append(MetadataViews.Media(file: MetadataViews.HTTPFile(url: imageUrl), mediaType: "image/jpeg"))
72        return MetadataViews.Medias(medias)
73    }
74
75    access(contract) fun resolveTraitsView(packID: UInt64): MetadataViews.Traits {
76        let metadata = self.metadatas[packID]!
77        let traits = MetadataViews.Traits([])
78        for key in metadata.data.keys {
79            if key != "id" && key != "name" && key != "description" && key != "imageUrl" && key != "videoUrl" && key != "thumbnailVideoUrl" {
80                let trait = MetadataViews.Trait(name: key, value: metadata.data[key], nil, nil)
81                traits.addTrait(trait)
82            }
83        }
84        return traits
85    }
86
87    pub fun resolveView(
88        view: Type,
89        id: UInt64,
90        packID: UInt64,
91        serial: UInt64,
92        publicCollectionType: Type,
93        publicLinkedType: Type,
94        providerLinkedType: Type,
95        createEmptyCollectionFunction: ((): @NonFungibleToken.Collection)
96    ):  AnyStruct? {
97
98            switch view {
99
100                case Type<MetadataViews.Traits>():
101                    return self.resolveTraitsView(packID: packID)
102
103                case Type<MetadataViews.Display>():
104                    return self.resolveDisplayView(packID: packID)
105
106                case Type<MetadataViews.Royalties>():
107                    return self.resolveRoyaltiesView()
108                
109                case Type<MetadataViews.ExternalURL>():
110                    return self.resolveExternalURLView(id: id)
111
112                case Type<MetadataViews.Medias>():
113                    return self.resolveMediasView(packID: packID)
114
115                case Type<MetadataViews.NFTCollectionDisplay>():
116                    return self.resolveNFTCollectionDisplayView()
117
118                case Type<MetadataViews.NFTCollectionData>():
119                    return MetadataViews.NFTCollectionData( 
120                        storagePath: StoragePath(identifier: "motogpPackCollection")!,
121                        publicPath: PublicPath(identifier: "motogpPackCollection")!,
122                        providerPath: PrivatePath(identifier: "motogpPackCollection")!,
123                        publicCollection: publicCollectionType,
124                        publicLinkedType: publicLinkedType,
125                        providerLinkedType:  providerLinkedType,
126                        createEmptyCollectionFunction: createEmptyCollectionFunction
127                    )
128                    
129            }
130            
131            return nil
132        }
133
134
135    pub struct Metadata {
136        pub let packID: UInt64
137        pub let name: String
138        pub let description: String
139        pub let imageUrl: String
140        // data contains all 'other' metadata fields, e.g. videoUrl, team, etc
141        //
142        pub let data: {String: String} 
143        init(_packID:UInt64, _name:String, _description:String, _imageUrl:String, _data:{String:String}){
144            pre {
145                    !_data.containsKey("name") : "data dictionary contains 'name' key"
146                    !_data.containsKey("description") : "data dictionary contains 'description' key"
147                    !_data.containsKey("imageUrl") : "data dictionary contains 'imageUrl' key"
148            }
149            self.packID = _packID
150            self.name = _name
151            self.description = _description
152            self.imageUrl = _imageUrl
153            self.data = _data
154        }
155    }
156
157    //Dictionary to hold all metadata with packID as key
158    //
159    access(self) let metadatas: {UInt64: MotoGPPackMetadata.Metadata} 
160
161    // Get all metadatas
162    //
163    pub fun getMetadatas(): {UInt64: MotoGPPackMetadata.Metadata} {
164        return self.metadatas
165    }
166
167    pub fun getMetadatasCount(): UInt64 {
168        return UInt64(self.metadatas.length)
169    }
170
171    //Get metadata for a specific packID
172    //
173    pub fun getMetadataForPackID(packID: UInt64): MotoGPPackMetadata.Metadata? {
174        return self.metadatas[packID]
175    }
176
177    //Access to set metadata is controlled using an Admin reference as argument
178    //
179    pub fun setMetadata(adminRef: &MotoGPAdmin.Admin, packID: UInt64, name:String, description:String, imageUrl:String, data:{String: String}) {
180        pre {
181            adminRef != nil: "adminRef is nil"
182        }
183        let metadata = Metadata(_packID:packID, _name:name, _description:description, _imageUrl:imageUrl, _data:data)
184        self.metadatas[packID] = metadata
185    }
186
187    //Remove metadata by packID
188    //
189    pub fun removeMetadata(adminRef: &MotoGPAdmin.Admin, packID: UInt64) {
190        pre {
191            adminRef != nil: "adminRef is nil"
192        }
193        self.metadatas.remove(key: packID)
194    }
195    
196    init(){
197            self.metadatas = {}
198    }
199        
200}
201