Smart Contract

PartyMansionDrinksContract

A.34f2bf4a80bb0f69.PartyMansionDrinksContract

Deployed

14h ago
Feb 28, 2026, 02:28:26 AM UTC

Dependents

0 imports
1/**
2*  SPDX-License-Identifier: GPL-3.0-only
3*/
4
5import FungibleToken from 0xf233dcee88fe0abe
6import ViewResolver from 0x1d7e57aa55817448
7import NonFungibleToken from 0x1d7e57aa55817448
8import MetadataViews from 0x1d7e57aa55817448
9import FindUtils from 0x097bafa4e0b48eef
10import Profile from 0x097bafa4e0b48eef 
11import FlowToken from 0x1654653399040a61
12import PartyMansionGiveawayContract from 0x34f2bf4a80bb0f69
13
14
15//							   ..`																  
16//							  +..o																  
17//							  :::/									  `						   
18//								`						 .os:.		`y+../y.					 
19//										 ++./.		  `o++o/o`		+mmdms					  
20//									   `:yNmd.		 -oy//+o-	   -ohmmmmdo.					
21//								./`	`-:my+/	   `o+:ss/+		 ---/mm/:::					
22//							   :yd.	   /		 .sd-``::			  so						
23//							   +::+`			  `os/+:+.										  
24//								`oh`			 -+ho.+y:	 -:::-								 
25//							 -sdmh-			`yd:+-+:	  :/   -/								
26//							 o-++			  `ys``+:	   .+. `+-								
27//							  -+s							  -:-`								 
28//						   .+shd:   `:::															
29//						   s+h/`	+.`+.									 `-.				   
30//						   -/:o	 `-:.									 -dmm:				  
31//						 `:+sd/			   -.-h.						  `sys.				  
32//						`ody+-				-hmmy+.		::::			  `					
33//						`++	.--			-ysdo`		 o..o					   /:-o-	   
34//							  `dmmo		   `  ..		  `..`  `o`				  :s-++-	  
35//					 `..`	  +ys-				 `.`			//+..::			 ./:+o..	  
36//					`y:.-:-`					   .y:/:``	  /+/:``-++.				.-		
37//					omh`  .:/.` ```			 -::`++.dho	  `.-+ ..o.						   
38//				   /mmmh.	-//--:/		   -m::/.o+-.`		`s/--:s`						  
39//				  -mmmms/:	+.   /-	  -::  :s-ds:`		   `:			   `				
40//				 `dmmms  -/`  .+-.:s.	 +d-//`.y/							 :sso/:+o:		   
41//				 ymmms	`/:   `.``//-+:+`/s:dh/`						/yss/+mm../+dy.		   
42//				ommmo	   sh:	  `+d-:yoy+	   .-`		   `+sso:sNy `/syo				  
43//			   /mmmo	  :dmmmy-	 .-s/+:`	  -/.`-+`	   ``yN/ ./hy-						
44//			  -mmm+	 .smmmmmmmy:  /mms//`	   o`   +.	  `+ohs.							  
45//			 `dmm+	 +dmmmmmmmds-/:.``  `/-	  `/:-:-		  `								
46//			 ymm+	-hmmmmmmmh/`   `::-	:/		`											 
47//			omm/   .smmmmmmds-`	  ./hho:` -/													 
48//		   /mm/   /dmmmmmh+.	 `:ohdmmmmmhs/:													 
49//		  -mm/  -ymmmmms:`   `-/ydmmmmmdyo:.`													   
50//		 `hm: `ommmmh+.   .:shmmmmdho/-`															
51//		 ym: :hmmmy:` `-+ydmmdhs/-.																 
52//		od:.ymmdo-`./sdmdhs+:.																	  
53//	   :d:+mmy/-:ohddy+:.`																		  
54//	  .dohds++shho/-`																			   
55//	 `hdmhyso/-`																					
56//	 sds/-`																						 
57//	 `																							  
58// PartyMansionDrinksContract
59//
60// "To Imgur! Full of truth and full of fiction, please raise your glasses to 
61// our unbreakable addiction."
62//																	
63access(all)
64contract PartyMansionDrinksContract: NonFungibleToken{ 
65
66    access(all) entitlement Owner
67    // Data 
68    //
69    // The fridge contains the beers to be served
70    access(self)
71    var fridge: [DrinkStruct]
72
73    // The shaker contains the LongDrinks to be served
74    access(self)
75    var shaker: [DrinkStruct]
76
77    // The whiskyCellar contains the whisky to be served
78    access(self)
79    var whiskyCellar: [DrinkStruct]
80
81    // FIFO
82    access(all)
83    var firstIndex: UInt32
84
85    // totalSupply
86    access(all)
87    var totalSupply: UInt64
88
89    // last call (stop minting)
90    access(all)
91    var lastCall: Bool
92
93    // Beer price
94    access(all)
95    var beerPrice: UFix64
96
97    // Long Drink Price
98    access(all)
99    var longDrinkPrice: UFix64
100
101    // Whisky Price
102    access(all)
103    var whiskyPrice: UFix64
104
105    // Private collection storage path
106    access(all)
107    let CollectionStoragePath: StoragePath
108
109    // Public collection storage path
110    access(all)
111    let CollectionPublicPath: PublicPath
112
113    // Admin storage path
114    access(all)
115    let BarkeeperStoragePath: StoragePath
116
117    // Events
118    //
119    // Event to be emitted when the contract is initialized
120    access(all)
121    event ContractInitialized()
122
123    // Event to be emitted whenever a Drink is withdrawn from a collection
124    access(all)
125    event Withdraw(id: UInt64, from: Address?)
126
127    // Event to be emitted whenever a Drink is deposited to a collection
128    access(all)
129    event Deposit(id: UInt64, to: Address?)
130
131    // Event to be emitted whenever a new Drink is minted
132    access(all)
133    event Minted(id: UInt64, title: String, description: String, cid: String)
134
135    // Event to be emitted whenever a new airdrop happens
136    access(all)
137    event Airdropped(id: UInt64)
138
139    //											   ```./+++/.										   
140    //										`-:::/+++oyy/..+++o+-									   
141    //									   /s:--/.`   -+:-.   ./y+/-`								   
142    //									-//o.	 .   `	   ````./y:`								 
143    //								`:/o/.`	.	 . `   `-/++:`  .:+o-							   
144    //							   /o:.`  `   :.  . `:`.:/yo/--+yo:.`  -h-							  
145    //							  :y`  `. `.	  `:+/. `/s`   ` .:+oo. :y							  
146    //							  +o`  ` ``  `   `  `-++/:` `  `	 :y/.h.							 
147    //							 `so`  ` ``  .- .:   -d.	`  `  .` ..od+							  
148    //							 o+ `   `   `:-./- -oy:` `` -``. `.	.o+							  
149    //							 o/ -   `  .`-+s-   d- ` -  ` .` `. .`  :y							  
150    //							 d/`	:`	  ```/d  .   ::  . .`  `  .h							  
151    //							 :y-	`   .  .dso/++++++//::-/` - .`  .h							  
152    //							  `s: ``  o`  .hod..mmmmmmmmmmmmmdys+.  -y							  
153    //							   `y   -`  :+d:ym.:mmmmhmmmm+smmmmmm/s/+o							  
154    //								-h```   :s- mm-/mmmmdmmmmmmmmmmmm-m-y:							  
155    //								 +s:-- `h`  dm//mmmmmmymmmmmdhmmd+d.d							   
156    //								  oy+  `h   yms-mmmmmmmmmmmmmmmmsd++o							   
157    //								  `d.   y-  +md.mmdommmmddmmmmmmym.d.							   
158    //								   s+-  +o  .mm-mmmmmmmmmmmmmmmmmo/s								
159    //								   .d//.y/   dm+ymmmmdmmmhmmmmmmm.h-								
160    //									s+:/:	omhommmmdmmmhmmmmmms/y								 
161    //									.h.+	 -mm+mmmmmmmmmmyhmmm.h-								 
162    //									 y:/	  dmommmmsmmmmmdmmmy:y								  
163    //									 :y.	  omhdmmmmmmmmmdmmm:y:								  
164    //									  d.	  -mmdmmmmmymmmmmmd.d`								  
165    //									  o+`	  mmmmmmmmmmmmmmmo/s								   
166    //									  :y-`	 ymmmmddmmmmmmmm:y:								   
167    //									  `m`/	 +mmmmmmmmmmmmmm`d`								   
168    //									   d.o	 -mmmmmmmmdmmmmd`m									
169    //									   h-y	 `mmmmmhmmmmmmmh-h									
170    //									   y:y`	 mmmmmmmmdmmmdy:y									
171    //									   y:y.	 dmmmmmmmmmmsmy:y									
172    //									   y:y.	 hmmmmmmymmm/mh-h									
173    //									   d.h`	 dmmmmmmmmmm-md.d									
174    //									  `m`m`	`mmmmmmmmmmm-hm`m`								   
175    //									  -h-m`	-mmmmmmmmmmm:om-y:								   
176    //									  +o+m. `-:oyyhhhdmmmmm+-m++o								   
177    //									  h-hm+ `-:/+osydhhmmmm+-mh.d								   
178    //									 .d.mmm:`  :osyhhmmmmmmydmm.h-								  
179    //									 o+ommhhyo+hmmmmmmmmmddhhmmo/s								  
180    //									 m`dmmmmhhysssooosssyhhmmmmm`m`								 
181    //									 y/odddmdhdddmmmmmdddhdmdddo/y								  
182    //									 `+o/++///.`.-----.`.://///o+`								  
183    //									   `:+o+:.```-/++:.``.:+o+/`									
184    //										   .-/+++++++++++/-.										
185    // Drink data structure
186    // This structure is used to store the payload of the Drink NFT
187    //
188    // "Here’s to a night on the town, new faces all around, taking the time
189    // to finally unwind, tonight it’s about to go down!"
190    //
191    access(all)
192    struct DrinkStruct{ 
193
194        // ID of drink
195        access(all)
196        let drinkID: UInt64
197
198        // ID in collection
199        access(all)
200        let collectionID: UInt64
201
202        // Title of drink
203        access(all)
204        let title: String
205
206        // Long description
207        access(all)
208        let description: String
209
210        // CID of the IPFS address of the picture related to the Drink NFT
211        access(all)
212        let cid: String
213
214        // Drink type
215        access(all)
216        let drinkType: DrinkType
217
218        // Drink rarity
219        access(all)
220        let rarity: UInt64
221
222        // Metadata of the Drink
223        access(all)
224        let metadata:{ String: AnyStruct}
225
226        // init
227        // Constructor method to initialize a Drink
228        //
229        // "To nights we will never remember, with the friends we will never forget."
230        //
231        init(drinkID: UInt64, collectionID: UInt64, title: String, description: String, cid: String, drinkType: DrinkType, rarity: UInt64, metadata:{ String: AnyStruct}){ 
232            self.drinkID = drinkID
233            self.collectionID = collectionID
234            self.title = title
235            self.description = description
236            self.cid = cid
237            self.drinkType = drinkType
238            self.rarity = rarity
239            self.metadata = metadata
240        }
241    }
242
243    // Drink Enum
244    //
245    // German
246    // „Ach, mir tut das Herz so weh,
247    // wenn ich vom Glas den Boden seh.“
248    //
249    access(all)
250    enum DrinkType: UInt8{ 
251        access(all)
252        case Beer
253
254        access(all)
255        case Whisky
256
257        access(all)
258        case LongDrink
259    }
260
261    // Drink NFT
262    //
263    // "Here’s to those who wish us well. And those that don’t can go to hell."
264    //
265    access(all)
266    resource NFT: NonFungibleToken.NFT, ViewResolver.Resolver{ 
267        // NFT id
268        access(all)
269        let id: UInt64
270
271        // Data structure containing all relevant describing data
272        access(all)
273        let data: DrinkStruct
274
275        // Original owner of NFT
276        access(all)
277        let originalOwner: Address
278
279        // init 
280        // Constructor to initialize the Drink
281        //
282        // "May we be in heaven half an hour before the Devil knows we’re dead."
283        //
284        init(drink: DrinkStruct, originalOwner: Address){ 
285            PartyMansionDrinksContract.totalSupply = PartyMansionDrinksContract.totalSupply + 1
286            let nftID = PartyMansionDrinksContract.totalSupply
287            self.data = DrinkStruct(drinkID: nftID, collectionID: drink.collectionID, title: drink.title, description: drink.description, cid: drink.cid, drinkType: drink.drinkType, rarity: drink.rarity, metadata: drink.metadata)
288            self.id = UInt64(self.data.drinkID)
289            self.originalOwner = originalOwner
290        }
291
292        // name
293        //
294        // "If the ocean was beer and I was a duck, 
295        //  I’d swim to the bottom and drink my way up. 
296        //  But the ocean’s not beer, and I’m not a duck. 
297        //  So raise up your glasses and shut the fuck up."
298        //
299        access(Owner)
300        fun name(): String{ 
301            return self.data.title
302        }
303
304        // description
305        //
306        // "Ashes to ashes, dust to dust, if it weren’t for our ass, our belly would bust!"
307        //
308        access(Owner)
309        fun description(): String{ 
310            return "A ".concat(PartyMansionDrinksContract.rarityToString(rarity: self.data.rarity)).concat(" ").concat(self.data.title).concat(" with serial number ").concat(self.id.toString())
311        }
312
313        // imageCID
314        //
315        // "Here’s to being single, drinking doubles, and seeing triple."
316        //
317        access(Owner)
318        fun imageCID(): String{ 
319            return self.data.cid
320        }
321
322        // getViews
323        //
324        // "Up a long ladder, down a stiff rope, here’s to King Billy, to hell with the pope!"
325        //
326        access(all)
327        view fun getViews(): [Type]{ 
328            return [Type<MetadataViews.Display>(), Type<MetadataViews.ExternalURL>(), Type<MetadataViews.Royalties>(), Type<MetadataViews.NFTCollectionData>(), Type<MetadataViews.NFTCollectionDisplay>(), Type<MetadataViews.Traits>(), Type<MetadataViews.Rarity>()]
329        }
330
331        // resolveView
332        //
333        // "Let us drink to bread, for without bread, there would be no toast."
334        //
335        access(all)
336        fun resolveView(_ view: Type): AnyStruct?{ 
337            switch view{ 
338            case Type<MetadataViews.Display>():
339                return MetadataViews.Display(name: self.name(), description: self.description(), thumbnail: MetadataViews.IPFSFile(cid: self.imageCID(), path: nil))
340            case Type<MetadataViews.ExternalURL>():
341                return MetadataViews.ExternalURL("https://partymansion.io/beers/".concat(self.id.toString()))
342            case Type<MetadataViews.Royalties>():
343                let pmCap = Profile.findReceiverCapability(address: PartyMansionDrinksContract.account.address, path: /public/flowTokenReceiver, type: Type<@FlowToken.Vault>())!
344                let ownerCap = Profile.findReceiverCapability(address: self.originalOwner, path: /public/flowTokenReceiver, type: Type<@FlowToken.Vault>())!
345                return MetadataViews.Royalties([MetadataViews.Royalty(receiver: pmCap, cut: 0.05, description: "Party Mansion"), MetadataViews.Royalty(receiver: ownerCap, cut: 0.01, description: "First Owner")])
346            case Type<MetadataViews.NFTCollectionData>():
347                return MetadataViews.NFTCollectionData(storagePath: PartyMansionDrinksContract.CollectionStoragePath, publicPath: PartyMansionDrinksContract.CollectionPublicPath, publicCollection: Type<&PartyMansionDrinksContract.Collection>(), publicLinkedType: Type<&PartyMansionDrinksContract.Collection>(), createEmptyCollectionFunction: fun (): @{NonFungibleToken.Collection}{ 
348                    return <-PartyMansionDrinksContract.createEmptyCollection(nftType: Type<@PartyMansionDrinksContract.Collection>())
349                })
350            case Type<MetadataViews.NFTCollectionDisplay>():
351                return MetadataViews.NFTCollectionDisplay(name: "Party Mansion Drinks", description: "What is a Party without drinks!? The Party Beers are an fun art collection of whacky drinks that can only be found at the bar in Party Mansion. These collectibles were first airdropped to Party Gooberz and will be a staple in the Mansion, Drink up!", externalURL: MetadataViews.ExternalURL("https://partymansion.io/"), squareImage: MetadataViews.Media(file: MetadataViews.IPFSFile(cid: "QmSEJEwqdpotJ7RX42RKDy5sVgQzhNy3XiDmFsc81wgzNC", path: nil), mediaType: "image/jpg"), bannerImage: MetadataViews.Media(file: MetadataViews.IPFSFile(cid: "QmVyXgw67QVAU98765yfQAB1meZhnSnYVoL6mz6UpzSw7W", path: nil), mediaType: "image/jpg"), socials:{ "twitter": MetadataViews.ExternalURL("https://mobile.twitter.com/the_goobz_nft"), "discord": MetadataViews.ExternalURL("http://discord.gg/zJRNqKuDQH")})
352            case Type<MetadataViews.Traits>():
353                let traits: [MetadataViews.Trait] = []
354                for traitName in self.data.metadata.keys{ 
355                    let traitValue = self.data.metadata[traitName]
356                    if traitValue != nil{ 
357                        if let tv = traitValue! as? String{ 
358                            traits.append(MetadataViews.Trait(name: FindUtils.to_snake_case(traitName), value: tv!, displayType: "String", rarity: nil))
359                            continue
360                        }
361                    }
362                }
363                var drinkType = "Beer"
364                switch self.data.drinkType{ 
365                case DrinkType.Whisky:
366                    drinkType = "Whisky"
367                case DrinkType.LongDrink:
368                    drinkType = "LongDrink"
369                }
370                traits.append(MetadataViews.Trait(name: "drink_type", value: drinkType, displayType: "String", rarity: nil))
371                return traits
372            case Type<MetadataViews.Rarity>():
373                return MetadataViews.Rarity(score: nil, max: nil, description: PartyMansionDrinksContract.rarityToString(rarity: self.data.rarity))
374            }
375            return nil
376        }
377
378        access(all)
379        fun createEmptyCollection(): @{NonFungibleToken.Collection}{ 
380            return <-create Collection()
381        }
382    }
383
384    // Interface to publicly acccess DrinkCollection
385    //
386    // "Out with the old. In with the new. Cheers to the future. And All that we do"
387    //
388    access(all)
389    resource interface DrinkCollectionPublic{ 
390
391        // Deposit NFT
392        // Param token refers to a NonFungibleToken.NFT to be deposited within this collection
393        //
394        // Belgian
395        // "Proost op onze lever"
396        //
397        access(all)
398        fun deposit(token: @{NonFungibleToken.NFT}): Void
399
400        // Get all IDs related to the current Drink Collection
401        // returns an Array of IDs
402        //
403        // Czech
404        // "Na EX!"
405        //
406        access(all)
407        view fun getIDs(): [UInt64]
408
409        // Borrow NonFungibleToken NFT with ID from current Drink Collection 
410        // Param id refers to a Drink ID
411        // Returns a reference to the NonFungibleToken.NFT
412        //
413        // Czech
414        // "Do dna!"
415        //
416        access(all)
417        view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}?
418
419        // Eventually borrow Drink NFT with ID from current Drink Collection
420        // Returns an option reference to PartyMansionDrinksContract.NFT
421        //
422        // Czech
423        // "Na zdraví!"
424        //
425        access(Owner)
426        fun borrowDrink(id: UInt64): &PartyMansionDrinksContract.NFT?{ 
427            // If the result isn't nil, the id of the returned reference
428            // should be the same as the argument to the function
429            post{ 
430                result == nil || result?.id == id:
431                "Cannot borrow Drink reference: The ID of the returned reference is incorrect"
432            }
433        }
434    }
435
436    //ddxxkO000OOO0000OOOOO0000000O00KXXNWWNX0Oxoc:::;;;;;::::c:ccclooooooooooooooooooooddddddx0NWWWWNXK00
437    //xxxkkkkkkkkkxxddddddddxxxxxxxxxxxdoolc;,,;:clloddoodxxddxdollllccloooooooooodxxkOKXXKKXXXNWMMMWXK0OO
438    //ooooooooooooooooooooooooooooooc:;,..',:codkOOOO00OOO00OO0000000OxddolldddddOXNNWWWWWWNNNWWWWWWNK0OOO
439    //oooooooooooooooooooooooooool:,'...';:lodddxxkkkO00OOO000OO00000K0OKKkdx0KKXWWWWWNNXXK00KXXNNNXK00OOO
440    //oooooooooooooooooooooooool;'....',;:::cloddxkOOO0KKK000K0O0000000000K0OOKWWWWWWNNNXK0OOOO000000OOOOk
441    //oooooooooodddooooooooool:'....',,,,,,:clddkkOO000000K0KKKKKKKKKKKK00000kkKNNWWWWWWNXK0Okkkkkkkxxxxxx
442    //ooooooooooooooooooooooc,......'''',,;:cloodxxxxkkkOOOOOOOOO00O000KKK0000xkKXXNNWNNXK00Okkkkkkkxxxxxx
443    //ooooooooodooddoooddooc.........'',;;:::ccclllllllclccllcccclooxkO000KKK0kxkOkO00OOOOOOOO000OOkkxxxxx
444    //ddddddddddxkkxddddddl'....'..',;;;;:::;,,,,,,,,,,,,,,,'''...'',:loxO000KkxkOOOOOOO000000000Okxdddddd
445    //kkkkkkOO0KXXXK0kxxdo;...''.',,;;;;,,,'...............		 ...,:lxkk0kdkkkOOOOOOOOOOOOOkkkxxxxddd
446    //KKKKKKKXNNNNNNNXKKOd,..',',,;;;,,'........					   ...;lxdddxdxxxxxxxxxxxxxxxxxkxxddxx
447    //kO0KKXXXNNWWWWWWWWWKc..,;;::;,'........  .....	  ....'',,;;,.. ...;codddddddddddddddddddddddddddd
448    //odk0KXXXXXNWWMMMMMWM0;,::::;,........  .','..   .. ..';;:cloddo;.....:oddddddddddddddddddddddddddddd
449    //odO0K0000KXNWWWWMMMWWKdlll:'..... .....''.. ...''.....';cloddxxo;...,ldddddddddddddddddddddddddddddd
450    //oxkOkxxkO0KKKKXXNWWWWWNX0d,...   ... ....  ....'''.'...,:coddxkkl'..;odddddxxxddddddddddddxddddddddd
451    //ddxddodxkOOOOkkkO00KKXXXNO, ..   .......   ..........'',;:codxxkx:..cddddddddddddddddddddxxxdddddddd
452    //kkkxxdxxxxkkxxxxkkkkOOOO0k' ..   .. ..	 .......''''',;::loxxxkd;,odddddddddxxkOOkxddddddddddddddd
453    //kkkkkkkkkkkkkkkkkkOOOO00KO, ..   ..	   ...........'',,;:cldxxxxdlodddddxxxk0KXXXXK0OOO00OOkkkxxxx
454    //xxxxxxxxxxxxxxxxxxxxxk00Oo,...   .		............'',;:clodxxxkkooddxxkOO0KKK0OO0000XXK0000OOkkk
455    //ddddddddddddddddddddddxxl:c,..   .  .   .. .............',;:cloddxxxxooxxxxxxxkkkkkkkkkkO0OkkOOkxxxx
456    //dxxxdddddddddddxddxxxddxdl;...   .  . .........'..........',;:ldxxxxkkooxxxdddddddxxxdxxxxxxxxxxxxxx
457    //xxxxkkkkOOOOkkkkkkxxkxxo::cl:. ....  ...........'''........'',:cccloddlcdxxdddddxxxxxxxdxxxxxxxxxxxx
458    //kkkkkOO00KKK00OOOOOOOkxllxdxc. .............................',;,'';::;;cdxxddxxdxxxxxxxxxxxxxxxxxxxx
459    //xxxxxxxxxxxxxxxxxkxxxxxxxxxxl. ...  ................'......'',;:cccllllcdxxdddxxxxxxxxxxxxxxxxxxxxxx
460    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxl...'.  ...........''......''',,,;::clllolloddddddddddxxxdxxxxxxxxxxxxxx
461    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxo'.''... ........'',,;;;'..',;;;::::clllcccoollllllllldxxxxxxxxxxxxxxxxx
462    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxo'.,'...........'',;;;;:;,,''',;;::cclllllodxddddddddddxxxxxxxxxxxxxxxxx
463    //xxxxxxxxxxxxxxxxxxxxxxxxxxdoc...............',,;;:::cc:,..'',;;;:cccldxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
464    //xxxxxxxxxxxxxxxxkxxxxxxdolc:,...............',,;;:::cclc;''...''';;:ldxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
465    //xxxxxxxxxxxxxxxxkkxxkkdc::;:,...............',,;;::::clooo:,'.....,;ldxxxxxxxxxxxxxxxxxxxxxxxxxxxkkk
466    //kkkkkkkkkkkkkkkkkkkxxko::;,,'................',,,;;:::cloddl:,.',;:coxkxxxxxxxxxxxxxxxxkxxxxkkkkkkkk
467    //kkkkkkkkkkkkkkkkkkkkkkdl:;,''''.'...........''',,,,;::clooooc,.coodkkkkkxxxxxxxxkkkkkkkkkkkkkkkkkkkk
468    //kkkkkkkkkkkkkkkkkkkkkkxl:;;;;,,'''...'...''',,,,,,;;;;cllolc;';oxkkxdxxkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
469    //kkkkkkkkkkkkkkkkkkkkxdlc::::;;:::;;,'''''''...,;:::::;;:cc:,';ldOXX0Oxxdxkkkkkkkkkkkkkkkkkkkkkkkkkkk
470    //kkkkkkkkkkkkkkkkkkxdlc:::::::::c::cc:;,',,,'....'::col:;;,'';:cxKXXKKKKkccdkkkkkkkkkkkkkkkkkkkkkkkkk
471    //kkkkkkkkkkkkkkkkkdc,,'''',,;;:clccllllc:;;;;;,,....,cooc'..'::lOXXXXKKK0l,coxkkkkkkkkkkkkkkkkkkkkkkk
472    //kkkkkkkkkkkkkkkkd:;,,,,,'''''',;clllllolc:;::cc:....;clo:'',clo0XXXXKKKKd;cxxxkkkkkkkkkkkkkkkkkkkkkk
473    //kkkkkkkkkkkkkkkdllc:::ccccc:;,''',:lllooolc:clll;....:looc',lco0XXXXKKKKk;:OKxxkkkkkkkkkkkkkkkkkkkkk
474    //kkkkkkkkkkkkkkd:;,''...'',:lool;'',:loooodoclllll:'..'lddo;,lldKXXXXKKKKx;:OXkdkOkkkkkkkkkkkkkkkkkkk
475    //kkkkkkkkkkkkOkl,,.....'''',,;cddc,'':loodddoooollc:,..:dddc,ldkKXXNNK0K0o,c00xodOkkkkkkkkkkkkkkkkkkk
476    //kkkkkkkkkkkkOx:........''',,;::lo:'.':oddddkkdollll:..;odxl;lokKXXXXK0KOc'ckxdookOkkOkkkkkkkkkkkkkkk
477    //kkkkkkkkOkkkOx;.............';::c;'..,coooxOOxlllllc,..,:llclokXXXNXK0Kkc';lodllxOkkOOkkOkkkkkkkOOOO
478    //OOOOOOkkOkkOOd'...	 ......',,;;'..';lookOOxolllll,...',cllokXXNNXK00x:',:lc;;dOkkOOkOOOOOOOOOOOOO
479    //OOOOOOOkOOOkOo;,...........''''.......';lxkOOkocllll:..'',:lloOXNNXKK00d;'.',,,;oOOkOOOOOOOOOOOOOOOO
480    //OOOOOOOOkkOOko::,''''',;coolcc:;,'..'..,lkOOkxocclloc,.''';lloOXNNXKK0kd;'.,:ldddkOOOOOOOOOOOOOOOOOO
481    //OOOOOOOOOOOOkl:;''''';codddoddxxdc..'..'okkkxxdlcllol;'''';lodkXNXXX0kkx:.,oxOOxdkOOOOOOOOOOOOOOOOOO
482    //OOOOOOOOOOOOklc:,,,;:cooooddxkkkxc.....'lxxxxddlclloo;...';lddOXNXNKkkOx;.,okOOOxkOOOOOOOOOOOOOOOOOO
483    //OOOOOOOOOOOOxllc::;;:cldxkO00KK0k:....',lddoooolclooo:..'':odd0XNXKOxk0d,'cxO00OdxOOOOOOOOOOOOOOOOOO
484    //OOOOOOOOOOOOkolc;;;;;clodxk0KKKOkc.....';lllloollloll;..',:odx0XXKOxxOOl'',cloolcxOkOOOOOOOOOOOOOOOO
485    //OOOOOOOOOOOOklc:;;,,;:ccloxO00Oxd:......,:cccoollllll;'',,:odx0X0Oxxk0k:...';::::dOOOOOOOOOOOOOOOOOO
486    // Resource to define methods to be used by the barkeeper in order 
487    // to administer and populate the fridge
488    //
489    // "Here’s to those who seen us at our best and seen us 
490    // at our worst and cannot tell the difference."
491    //
492    access(all)
493    resource Barkeeper{ 
494
495        // Adds drinks to the fridge
496        //
497        // Polish
498        // "Sto lat!"
499        //
500        access(Owner)
501        fun fillFridge(collectionID: UInt64, title: String, description: String, cid: String, rarity: UInt64, metadata:{ String: AnyStruct}){ 
502            pre{ 
503                cid.length > 0:
504                "Could not create Drink: cid is required."
505            }
506            PartyMansionDrinksContract.fridge.append(DrinkStruct(drinkID: 0 as UInt64, collectionID: collectionID, title: title, description: description, cid: cid, drinkType: DrinkType.Beer, rarity: rarity, metadata: metadata))
507        }
508
509        // Replaces old drinks in fridge
510        // because nobody serves old drinks to the party people
511        //
512        // Polish
513        // "Za nas!"
514        //
515        access(Owner)
516        fun replaceDrinkInFridge(collectionID: UInt64, title: String, description: String, cid: String, rarity: UInt64, metadata:{ String: AnyStruct}, index: Int){ 
517            pre{ 
518                cid.length > 0:
519                "Could not create Drink: cid is required."
520                index >= 0:
521                "Index is out of bounds"
522                PartyMansionDrinksContract.fridge.length > index:
523                "Index is out of bounds."
524            }
525            PartyMansionDrinksContract.fridge[index] = DrinkStruct(drinkID: 0 as UInt64, collectionID: collectionID, title: title, description: description, cid: cid, drinkType: DrinkType.Beer, rarity: rarity, metadata: metadata)
526        }
527
528        // removeDrinkFromFridge
529        // because sometimes party people do change their taste
530        //
531        // Polish
532        // “Za tych co nie mogą”
533        //
534        access(Owner)
535        fun removeDrinkFromFridge(index: UInt64){ 
536            pre{ 
537                PartyMansionDrinksContract.fridge[index] != nil:
538                "Could not take drink out of the fridge: drink does not exist."
539            }
540            PartyMansionDrinksContract.fridge.remove(at: index)
541        }
542
543        // throwHouseRound
544        // The barkeeper throws a house round and airdrops the Drink to a Recipient
545        //
546        // "Here’s to the glass we love so to sip,
547        // It dries many a pensive tear;
548        // ’Tis not so sweet as a woman’s lip
549        // But a damned sight more sincere."
550        //
551        access(Owner)
552        fun throwHouseRound(collectionID: UInt64, title: String, description: String, cid: String, rarity: UInt64, metadata:{ String: AnyStruct}, drinkType: DrinkType, recipient: &{NonFungibleToken.CollectionPublic}, originalOwner: Address){ 
553            pre{ 
554                cid.length > 0:
555                "Could not create Drink: cid is required."
556            }
557            // GooberStruct initializing
558            let drink: DrinkStruct = DrinkStruct(drinkID: 0 as UInt64, collectionID: collectionID, title: title, description: description, cid: cid, drinkType: drinkType, rarity: rarity, metadata: metadata)
559            recipient.deposit(token: <-create PartyMansionDrinksContract.NFT(drink: drink, originalOwner: originalOwner))
560            emit Minted(id: PartyMansionDrinksContract.totalSupply, title: (drink!).title, description: (drink!).description, cid: (drink!).cid)
561            emit Airdropped(id: PartyMansionDrinksContract.totalSupply)
562        }
563
564        // retrievePoolDrink
565        //
566        // "Time to hydrate"
567        //
568        access(Owner)
569        fun retrievePoolDrink(drinkType: DrinkType): DrinkStruct{ 
570            pre{ 
571                PartyMansionDrinksContract.checkIfBarIsSoldOut(drinkType: drinkType) == false:
572                "Bar is sold out"
573            }
574            let disposedDrink: DrinkStruct = PartyMansionDrinksContract.getDrinkFromStorage(drinkType: drinkType)
575            return disposedDrink
576        }
577
578        // announceLastCall
579        // Barkeeper shouts "Last Call"
580        //
581        // "May you always lie, cheat, and steal. Lie beside the one you love,
582        // cheat the devil, and steal away from bad company."
583        //
584        access(Owner)
585        fun announceLastCall(lastCall: Bool){ 
586            PartyMansionDrinksContract.lastCall = lastCall
587        }
588
589        // setDrinkPrices
590        //
591        // Mexico
592        // "Por lo que ayer dolió y hoy ya no importa, salud!"
593        //
594        access(Owner)
595        fun setDrinkPrices(beerPrice: UFix64, whiskyPrice: UFix64, longDrinkPrice: UFix64){ 
596            PartyMansionDrinksContract.beerPrice = beerPrice
597            PartyMansionDrinksContract.whiskyPrice = whiskyPrice
598            PartyMansionDrinksContract.longDrinkPrice = longDrinkPrice
599        }
600    }
601
602    //								  `--:/+oosyyyhhhhhhhhhhyysso+//:-.`								 
603    //						`.:+sydmNMMNNmmdhhyyysssssssssyyyhhddmNNMMNmdhs+/-`						 
604    //				   `-/sdNNNmdys+/:-````` ``			  ```````.-/+syhmNNNmyo:`					
605    //				./ymNNdy+:.``										 ``.-+shmNNh+-				 
606    //			  .smNds:.`													 `.:odNNh:`			  
607    //			 /mMh:`															 `-sNNy`			 
608    //			.NMs`																  :NMs			 
609    //			:MM/																   `mMd			 
610    //			-MMm/`																.yMMy			 
611    //			`MMMMdo.`														 `.:yNMMMs			 
612    //			 NMh+dNNds/-``											   ```:ohmMNy/MM+			 
613    //			 mMd  .+ymNMmdyo/-```								  ``.:+sydNMNds:` .MM/			 
614    //			 hMm	  .:+ydmMMMNmhyso++/:--...````````...-::/+osyhdmNMMNmho/-`	 :MM-			 
615    //			 yMM			`.:/osyhdmmNMMMMMMMMMMMMMMMMMMMNNmdhyso+/-`			+MM.			 
616    //			 oMM`					`````...----::----...`````					oMN			  
617    //			 +MM-																  yMm			  
618    //			 :MM/																  hMh			  
619    //			 -MM+										   .-:+-				  mMy			  
620    //			 `MMs									`.-:+ssso//ys-				NMo			  
621    //			  NMy		  ``..--:/+os/`	   `.-/+ssso/-.`	`/hs.			 `MM+			  
622    //			  mMd	 /oossyyyssoo+::/dy-...:ossso/-.`			`+hs.		   -MM:			  
623    //			  hMm	`Nd:-.``		 .ymmmNMMs`					.odo.		 :MM-			  
624    //			  yMM	`mhy`			  :mMMMyhs`					 -ymo`	   +MM`			  
625    //			  oMM.   `m`yh`			  `sMMo`sd-				 `-oyydMdo-	 oMN			   
626    //			  /MM-   `m``sh`	  ```.-/+osdMo  /m/			 ./yhs/. sMMMMy.   yMm			   
627    //			  :MM/   oMNhohd:+osyyyyso+/-.` do   -ms`	   `:shy+.	 hMMMMMh   hMh			   
628    //			  .MM+   -NMMMMMMs-`			do	`yd.   -ohho-	  .+mMMMMMM+   mMy			   
629    //			  `MMs	.smMMMMMNho/-`		ds	  +m+yhs:``	.:odNMMMMMNy-	NMo			   
630    //			   NMy   o-``:shmMMMMMNNmhso+//:mNmho+/:-ym/::://oshmNNMMMMNdy/`-+/  `MM/			   
631    //			   mMd   dNms/.``-/oyhdmNMMMMMMNMMMMMMMNNNMNNNNMMMMNmmhyo/-.-:odNM:  -MM:			   
632    //			   hMm   yMM/+yhyo/:.....-://+ossyyyyhyyyyyssoo+/:---://+osymNMMMM.  :MM.			   
633    //			   yMN`  sMMd:`.Nddddmdhyso++//::::::::::://++ooosssoooosydmNMMMMN`  +MM`			   
634    //			   oMM.  oMMMNs.m+`.--:/+oyhdNMMMMMMNyo++hm+//:---:/ohmNMMMMMMMMMm   oMN				
635    //			   /MM-  /MMMMMmN+ `.-:+yhmNMMMMMMMMMNd+.oh `.:ohmNMMMMMMMMMMMMMMy   yMd				
636    //			   :MM/  `dMMMMMMhydmNMMMMMMMMMMMMMMMMMMNmmhdNMMMMMMMMMMMMMMMMMMM:   hMh				
637    //			   .MM+   .dMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNo	mMs				
638    //			   `MMy`   `+mNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNh-	.NMo				
639    //				NMMd/`   `-+ymNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNmy+.   `-sNMM/				
640    //				mMMMMNy/`	 .:+ydNMMMMMMMMMMMMMMMMMMMMMMMMMMMMmhs+:`	`:smMMmMM:				
641    //				hMMMMMMMNho-`	   `.:/oosyhhdddddddhhhyso+/-.	   .:odMMMm+.+MM.				
642    //				sMMMMMMMMMMMNds+:.`		   ``  ``		   `.:+shmNMMMMMMy  oMM				 
643    //				oMMMMMMMMM-:oydNNNNdhso+/::---...-.--:::/+osyhmNNNNdyo/hMMMMMs  sMN				 
644    //				/MMMMMMMMM.   `.-/osyhdmmNNNNNNNNNNNNNNNmmdhhyo+:..`   sMMMMMo  hMd				 
645    //				:MMMMMMMMM-		  ```...--:::::----....```		  sMMMMM+  dMy				 
646    //				.MMMMMMMMM:											sMMMMM/ `mMs				 
647    //				 yNMMMMMMM:											sMMMMM//dMd-				 
648    //				  /dMMMMMM/											sMMMMMmMmo.				  
649    //				   `/hNMMMo`										   yMMMMNmo.					
650    //					  -odNMmho:.``								`.-/smMNms:`					  
651    //						 ./sdNNNmhso/-.````  `	   `  ````.-:+oydNNNmy+-						  
652    //							 `-+shmNNMMNNmdhhyyyyssyyyhhddmNNMNNmhs+:.							  
653    //									`-:/+ossyyhhhhhhhyysso+/:-.		
654    // Collection
655    // A collection of Drink NFTs owned by an account
656    //
657    // Polish
658    // “Człowiek nie wielbłąd, pić musi”
659    //
660    access(all)
661    resource Collection: DrinkCollectionPublic, NonFungibleToken.Provider, NonFungibleToken.Receiver, NonFungibleToken.Collection, NonFungibleToken.CollectionPublic, ViewResolver.ResolverCollection{ 
662        // dictionary of NFT conforming tokens
663        // NFT is a resource type with an `UInt64` ID field
664        //
665        // Norwegian
666        // "Vi skåler for våre venner og de som vi kjenner og 
667        //  de som vi ikke kjenner de driter vi i. Hei, skål!"
668        //
669        access(all)
670        var ownedNFTs: @{UInt64:{ NonFungibleToken.NFT}}
671
672        // withdraw
673        // Removes an NFT from the collection and moves it to the caller
674        //
675        // British
676        // "Let's drink the liquid of amber so bright;
677        //  Let's drink the liquid with foam snowy white; 
678        //  Let's drink the liquid that brings all good cheer; 
679        //  Oh, where is the drink like old-fashioned beer?"
680        //
681        access(NonFungibleToken.Withdraw)
682        fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT}{ 
683            let token <- self.ownedNFTs.remove(key: withdrawID) ?? panic("missing NFT")
684            emit Withdraw(id: token.id, from: self.owner?.address)
685            return <-token
686        }
687
688        // deposit
689        // Takes a NFT and adds it to the collections dictionary
690        // and adds the ID to the id array
691        //
692        // Irish
693        // "May your blessings outnumber
694        // The shamrocks that grow,
695        // And may trouble avoid you
696        // Wherever you go."
697        //
698        access(all)
699        fun deposit(token: @{NonFungibleToken.NFT}): Void{ 
700            let token <- token as! @PartyMansionDrinksContract.NFT
701            let id: UInt64 = token.id
702
703            // add the new token to the dictionary which removes the old one
704            let oldToken <- self.ownedNFTs[id] <- token
705            emit Deposit(id: id, to: self.owner?.address)
706            // destroy old resource
707            destroy oldToken
708        }
709
710        // getIDs
711        // Returns an array of the IDs that are in the collection
712        //
713        // Irish
714        // "Here’s to a long life and a merry one.
715        // A quick death and an easy one.
716        // A pretty girl and an honest one.
717        // A cold beer and another one."
718        //
719        //
720        access(all)
721        view fun getIDs(): [UInt64]{ 
722            return self.ownedNFTs.keys
723        }
724
725        // borrowNFT
726        // Gets a reference to an NFT in the collection
727        // so that the caller can read its metadata and call its methods
728        //
729        // French
730        // “Je lève mon verre à la liberté.” 
731        //
732        access(all)
733        view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}?{ 
734            return (&self.ownedNFTs[id] as &{NonFungibleToken.NFT}?)!
735        }
736
737        // borrowDrink
738        // Gets a reference to an NFT in the collection as a Drink,
739        // exposing all data.
740        // This is safe as there are no functions that can be called on the Drink.
741        //
742        // Spanish
743        // "¡arriba, abajo, al centro y adentro!"
744        //
745        access(Owner)
746        fun borrowDrink(id: UInt64): &PartyMansionDrinksContract.NFT?{ 
747            if self.ownedNFTs[id] != nil{ 
748                let ref = (&self.ownedNFTs[id] as &{NonFungibleToken.NFT}?)!
749                return ref as! &PartyMansionDrinksContract.NFT
750            } else{ 
751                return nil
752            }
753        }
754
755        access(all)
756        view fun borrowViewResolver(id: UInt64): &{ViewResolver.Resolver}?{ 
757            if self.ownedNFTs[id] != nil{ 
758                let ref = (&self.ownedNFTs[id] as &{NonFungibleToken.NFT}?)!
759                return ref as! &PartyMansionDrinksContract.NFT
760            }
761            panic("Missing NFT. ID : ".concat(id.toString()))
762        }
763
764        access(all) view fun getSupportedNFTTypes(): {Type: Bool} {
765            return { Type<@NFT>() : true}
766        }
767
768        access(all) view fun isSupportedNFTType(type: Type) : Bool {
769            return type == Type<@NFT>()
770        }
771
772        access(all)
773        fun createEmptyCollection(): @{NonFungibleToken.Collection}{ 
774            return <-create Collection()
775        }
776
777        // destructor
778        //
779        // Russian
780        // "Давайте всегда наслаждаться жизнью, как этим бокалом вина!"
781        //
782        // initializer
783        //
784        // Russian
785        // "Выпьем за то, что мы здесь собрались, и чтобы чаще собирались!"
786        //
787        init(){ 
788            self.ownedNFTs <-{} 
789        }
790    }
791
792
793    access(all) view fun getContractViews(resourceType: Type?): [Type] {
794        return [
795        Type<MetadataViews.NFTCollectionData>(),
796        Type<MetadataViews.NFTCollectionDisplay>()
797        ]
798    }
799
800    access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
801        switch viewType {
802        case Type<MetadataViews.NFTCollectionData>():
803            return MetadataViews.NFTCollectionData(storagePath: PartyMansionDrinksContract.CollectionStoragePath, publicPath: PartyMansionDrinksContract.CollectionPublicPath, publicCollection: Type<&PartyMansionDrinksContract.Collection>(), publicLinkedType: Type<&PartyMansionDrinksContract.Collection>(), createEmptyCollectionFunction: fun (): @{NonFungibleToken.Collection}{ 
804                return <-PartyMansionDrinksContract.createEmptyCollection(nftType: Type<@PartyMansionDrinksContract.Collection>())
805            })
806        case Type<MetadataViews.NFTCollectionDisplay>():
807            return MetadataViews.NFTCollectionDisplay(name: "Party Mansion Drinks", description: "What is a Party without drinks!? The Party Beers are an fun art collection of whacky drinks that can only be found at the bar in Party Mansion. These collectibles were first airdropped to Party Gooberz and will be a staple in the Mansion, Drink up!", externalURL: MetadataViews.ExternalURL("https://partymansion.io/"), squareImage: MetadataViews.Media(file: MetadataViews.IPFSFile(cid: "QmSEJEwqdpotJ7RX42RKDy5sVgQzhNy3XiDmFsc81wgzNC", path: nil), mediaType: "image/jpg"), bannerImage: MetadataViews.Media(file: MetadataViews.IPFSFile(cid: "QmVyXgw67QVAU98765yfQAB1meZhnSnYVoL6mz6UpzSw7W", path: nil), mediaType: "image/jpg"), socials:{ "twitter": MetadataViews.ExternalURL("https://mobile.twitter.com/the_goobz_nft"), "discord": MetadataViews.ExternalURL("http://discord.gg/zJRNqKuDQH")})
808        }
809        return nil
810    }
811
812    // createEmptyCollection
813    // public function that anyone can call to create a new empty collection
814    //
815    // Russian
816    // "Выпьем за то, чтобы у нас всегда был повод для праздника!"
817    //
818    access(all)
819    fun createEmptyCollection(nftType: Type): @{NonFungibleToken.Collection}{ 
820        return <-create Collection()
821    }
822
823    // +ooooooooooooooo+/.														   -/+syyyso/-`		 
824    // hNNNNNNNNNNNNNNNMMNd+`													`/ymNMNmmddmNMNNh/`	  
825    // ````````````````.:yMMd.												 `omMNho:.`````.-+hNMmo`	
826    //					/NMm/											   -dMNs-`			.sNMm:   
827    //					 -dMNo`											:NMm:				 -dMN/  
828    //					  `sMMh.										  `mMN-				   .mMN. 
829    //						/NMm:										 +MMo					 /MMs 
830    //						 -dMNo`									   :++.					 .MMd 
831    //			 /ssssssssssssyMMMhssssssssssssssssssssssssssssssssssssssssssssssssso`			 -MMh 
832    //			  +NMMMMNNNNNNNNNNMMMNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNMMMMh.			  sMM+ 
833    //			   .yMMN+````````-mMMs```````````````````````````````````````-dMMm/			   /MMd` 
834    //				 :mMMh.	   `yMMh`									+NMMs`			  `sMMd`  
835    //				   oNMMo`	   +NMm-								 -dMMd-`+:		   -sNMNo	
836    //					.hMMm:   +sssdMMNssssssssssssssssssssssssssssssssyMMN+  yMMNhs+///+ohmMMms.	 
837    //					  /mMMy. `sNMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMy.   `-ohmNMMMMMNmho:`	   
838    //					   `sMMN+` -dMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMd:		 ``..--.``		   
839    //						 :dMMd- `+mMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMNo`							  
840    //						  `+NMNs. .yMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMh-								
841    //							.yMMm/  :dMMMMMMMMMMMMMMMMMMMMMMMMMMm/`								 
842    //							  /mMMy. `oNMMMMMMMMMMMMMMMMMMMMMMNs.								   
843    //							   `sNMN+` -hMMMMMMMMMMMMMMMMMMMMd:									 
844    //								 -dMMd:  +mMMMMMMMMMMMMMMMMNo`									  
845    //								   +NMMs` .yMMMMMMMMMMMMMMh.										
846    //									.yMMm/  :dMMMMMMMMMMm/										  
847    //									  :mMMh.  oNMMMMMMMs`										   
848    //										oNMMo` .hMMMMd-											 
849    //										 .hMMm:`yMMN+											   
850    //										   /mMMNMMy.												
851    //											`yMMN:												  
852    //											 /MMd												   
853    //											 /MMd												   
854    //											 /MMd												   
855    //											 /MMd												   
856    //											 /MMd												   
857    //											 /MMd												   
858    //											 /MMd												   
859    //											 /MMd												   
860    //											 /MMd												   
861    //											 /MMd												   
862    //											 /MMd												   
863    //											 /MMd												   
864    //											 /MMd												   
865    //											 /MMd												   
866    //											 /MMd												   
867    //											 /MMd												   
868    //											 /MMd												   
869    //											 /MMd												   
870    //											 /MMd												   
871    //								```````.....-oMMm--.....``````									  
872    //							  -/+oossyyyyyyyyyyyyyyyyyyyyssso+/:`								  
873    // Beware !!! These methods know only german drinking toasts !!!
874    // checkIfBarIsSoldOut
875    //
876    // Before selling a drink the barkeeper needs to check the stock
877    //
878    // German
879    // "Nimmst du täglich deinen Tropfen,
880    //  wird dein Herz stets freudig klopfen,
881    //  wirst im Alter wie der Wein,
882    //  stets begehrt und heiter sein."
883    //
884    access(all)
885    view fun checkIfBarIsSoldOut(drinkType: DrinkType): Bool{ 
886        switch drinkType{ 
887        case DrinkType.Beer:
888            return PartyMansionDrinksContract.fridge.length == 0
889        case DrinkType.Whisky:
890            return PartyMansionDrinksContract.whiskyCellar.length == 0
891        case DrinkType.LongDrink:
892            return PartyMansionDrinksContract.shaker.length == 0
893        default:
894            panic("Undefined drink type.")
895        }
896    }
897
898    // getPriceByTypeFromPriceList
899    //
900    // German
901    // "Der größte Feind des Menschen wohl,
902    // das ist und bleibt der Alkohol.
903    // Doch in der Bibel steht geschrieben:
904    // „Du sollst auch deine Feinde lieben.“
905    //
906    access(all)
907    view fun getPriceByTypeFromPriceList(drinkType: DrinkType): UFix64{ 
908        var price: UFix64 = 0.00
909        switch drinkType{ 
910        case DrinkType.Beer:
911            price = self.beerPrice
912        case DrinkType.Whisky:
913            price = self.whiskyPrice
914        case DrinkType.LongDrink:
915            price = self.longDrinkPrice
916        default:
917            panic("Undefined drink type.")
918        }
919        return price
920    }
921
922    // getDrinkFromStorage
923    //
924    // German
925    // "Moses klopfte an einen Stein,
926    // da wurde Wasser gleich zu Wein,
927    // doch viel bequemer hast du's hier,
928    // brauchst nur rufen: Wirt, ein Bier!"
929    //
930    access(all)
931    fun getDrinkFromStorage(drinkType: DrinkType): DrinkStruct{ 
932        var disposedDrink: DrinkStruct = DrinkStruct(drinkID: 0 as UInt64, collectionID: 0 as UInt64, title: " ", description: " ", cid: " ", drinkType: drinkType, rarity: 0 as UInt64, metadata:{} )
933        switch drinkType{ 
934        case DrinkType.Beer:
935            disposedDrink = PartyMansionDrinksContract.fridge.remove(at: PartyMansionDrinksContract.firstIndex)
936        case DrinkType.Whisky:
937            disposedDrink = PartyMansionDrinksContract.whiskyCellar.remove(at: PartyMansionDrinksContract.firstIndex)
938        case DrinkType.LongDrink:
939            disposedDrink = PartyMansionDrinksContract.shaker.remove(at: PartyMansionDrinksContract.firstIndex)
940        default:
941            panic("Undefined drink type.")
942        }
943        return disposedDrink
944    }
945
946    // buyDrink
947    // Mints a new Drink NFT with a new ID and disposes it from the Bar
948    // and deposits it in the recipients collection using their collection reference
949    //
950    // German
951    // "Wer Liebe mag und Einigkeit, der trinkt auch mal ne Kleinigkeit."
952    //
953    access(all)
954    fun buyDrink(recipient: &{NonFungibleToken.CollectionPublic}, address: Address, paymentVault: @{FungibleToken.Vault}, drinkType: DrinkType){ 
955        pre{ 
956            PartyMansionDrinksContract.lastCall == false:
957            "No minting possible. Barkeeper already announced last call."
958            PartyMansionDrinksContract.checkIfBarIsSoldOut(drinkType: drinkType) == false:
959            "Bar is sold out"
960            paymentVault.isInstance(Type<@FlowToken.Vault>()):
961            "payment vault is not requested fungible token"
962            paymentVault.balance >= PartyMansionDrinksContract.getPriceByTypeFromPriceList(drinkType: drinkType):
963            "Could not buy Drink: payment balance insufficient."
964        }
965
966        // pay the barkeeper
967        let partyMansionDrinkContractAccount: &Account = getAccount(PartyMansionDrinksContract.account.address)
968        let partyMansionDrinkContractReceiver: Capability<&{FungibleToken.Receiver}> = partyMansionDrinkContractAccount.capabilities.get<&FlowToken.Vault>(/public/flowTokenReceiver)!
969        let borrowPartyMansionDrinkContractReceiver = partyMansionDrinkContractReceiver.borrow()!
970        borrowPartyMansionDrinkContractReceiver.deposit(from: <-paymentVault.withdraw(amount: paymentVault.balance))
971
972        // serve drink
973        let disposedDrink: DrinkStruct = PartyMansionDrinksContract.getDrinkFromStorage(drinkType: drinkType)
974        recipient.deposit(token: <-create PartyMansionDrinksContract.NFT(drink: disposedDrink!, originalOwner: address))
975        emit Minted(id: PartyMansionDrinksContract.totalSupply, title: (disposedDrink!).title, description: (disposedDrink!).description, cid: (disposedDrink!).cid)
976
977        // close the wallet
978        destroy paymentVault
979    }
980
981    // retrieveFreeDrink
982    //
983    // “Alcohol may be man’s worst enemy, but the bible says love your enemy.”
984    //
985    access(all)
986    fun retrieveFreeDrink(recipient: &{NonFungibleToken.CollectionPublic}, address: Address, giveawayCode: String, drinkType: DrinkType){ 
987        pre{ 
988            PartyMansionDrinksContract.checkIfBarIsSoldOut(drinkType: drinkType) == false:
989            "Bar is sold out"
990        }
991        if PartyMansionGiveawayContract.checkGiveawayCode(giveawayCode: giveawayCode) == false{ 
992            panic("Giveaway code not known.")
993        }
994
995        // deposit it in the recipient's account using their reference
996        let disposedDrink: DrinkStruct = PartyMansionDrinksContract.getDrinkFromStorage(drinkType: drinkType)
997        recipient.deposit(token: <-create PartyMansionDrinksContract.NFT(drink: disposedDrink!, originalOwner: address))
998        PartyMansionGiveawayContract.removeGiveawayCode(giveawayCode: giveawayCode)
999        emit Minted(id: PartyMansionDrinksContract.totalSupply, title: (disposedDrink!).title, description: (disposedDrink!).description, cid: (disposedDrink!).cid)
1000    }
1001
1002    //												 -:.												
1003    //												 :hd--											  
1004    //												 -sMNm-											 
1005    //												  `+MM+											 
1006    //												   `NN.											 
1007    //												   :Mm											  
1008    //												  `mMh											  
1009    //												  +MMs											  
1010    //												 `NMM/											  
1011    //									 `-/++-./-`  /MMM.											  
1012    //								   `+mMMMMMNMMy` sMMy											   
1013    //								   yMMMMMMMMMMMo-NMN.											   
1014    //								-:/MMMMMMMMMMMMMNMMs												
1015    //							 `.-yMMMMMMMMMMMMMMMMMN.												
1016    //						   :yNMMMMMMMMMMMMMMMMMMMMy												 
1017    //						  :MMMMMMMMMMMMMMMMMMMMMMM-												 
1018    //						  `yNNmMMMMMMMMMMMMMMMMMMh												  
1019    //						   `+-yMMMMMMMMMMMMMNMMMM-												  
1020    //							  -NMMMMMMMMMMMMMMMMN.												  
1021    //							  `dNMMMMMMMMMMMMMMMMmy:												
1022    //							   .dMMMMMMMMMMMMMMMMMMN-											   
1023    //							  `oMMMNmNMMMMMMMMMMMMMM/											   
1024    //							 .hMMMh//mNNMMMMMMMMMMMM+											   
1025    //							-dMMMs` ./-:hMMMMMMMMMMMh											   
1026    //						   -mMMMs	   `/mMMMMMMMMMM:											  
1027    //						   dMMMm/.`	   .hMMMMMMMMMm:											 
1028    //						  `dNNMMMNho/-.``  /MMMMMMMMMMN/											
1029    //							.-/shmNNMMNmhhhmMMMMMMMMMMMM+`										  
1030    //								  `-o+oymNNMMMMMMMMMMMMMMh`										 
1031    //									`  `..-mMMMMMMMMMMMMMMm.										
1032    //										   yMMMMMMMMMMMMMMMm.									   
1033    //										   hMMMMMMMMMMMMMMMMd									   
1034    //										  `NMMMMMMMMMMMMMMMMM+									  
1035    //										  /MMMMMMMMMMMMMMMMMMd									  
1036    //										  dMMMMMMMMMMMMMMMMMMM-									 
1037    //										 -MMMMMMMMmyysmMMMMMMMo									 
1038    //										 oMMMMMMMN-   :MMMMMMMd									 
1039    //										 hMMMMMMM:	 hMMMMMMM`									
1040    //										 mMMMMMMs	  .NMMMMMM/									
1041    //										`MMMMMMm`	   yMMMMMMs									
1042    //										-MMMMMMo		-MMMMMMh									
1043    //										:MMMMMN`		 yMMMMMm									
1044    //										/MMMMMs		  -MMMMMN`								   
1045    //										oMMMMN.		   yMMMMM.								   
1046    //										dMMMMo			-NMMMMs								   
1047    //									   :MMMMs			  /NMMMm								   
1048    //									  .mMMMh				/MMMM/								  
1049    //									 `dMMMM/				`MMMMN.								 
1050    //									 sMMMMN`				 mMMMMh								 
1051    //									.MMMMM+				  oMMMMM:								
1052    //									oMMMMy				   `hMMMMh								
1053    //									dMMMy`					`hMMMM.							   
1054    //								   `NMMm`					  `hMMMs							   
1055    //								   -MMM/						.mMMN`							  
1056    //								   :MMh						  :MMM+							  
1057    //								   oMN-						   yMMd							  
1058    //								   dMh							:MMM:							 
1059    //								  :MMo							.MMMy							 
1060    //								  hMM-							:MMMN`							
1061    //								 :MMm							 .mmMM+							
1062    //								`mMMo							  o.dMh`						   
1063    //								sMMN-							  o -NMho`						 
1064    //								-::-							   -  :///.						 
1065    // getContractAddress
1066    // returns address to smart contract
1067    //
1068    // “Lift ’em high and drain ’em dry, to the guy who says, “My turn to buy.”
1069    //
1070    access(all)
1071    fun getContractAddress(): Address{ 
1072        return self.account.address
1073    }
1074
1075    // getBeerPrice
1076    //
1077    // "May we never go to hell but always be on our way."
1078    //
1079    access(all)
1080    fun getBeerPrice(): UFix64{ 
1081        return self.beerPrice
1082    }
1083
1084    // getWhiskyPrice
1085    //
1086    // "God in goodness sent us grapes to cheer both great and small. 
1087    //  Little fools drink too much, and great fools not at all!"
1088    //
1089    access(all)
1090    fun getWhiskyPrice(): UFix64{ 
1091        return self.whiskyPrice
1092    }
1093
1094    // getLongDrinkPrice
1095    //
1096    // "The past is history, the future is a mystery, but today is a gift, 
1097    //  because it’s the present."
1098    //
1099    access(all)
1100    fun getLongDrinkPrice(): UFix64{ 
1101        return self.longDrinkPrice
1102    }
1103
1104    // rarityToString
1105    //
1106    // "Life is short, but sweet."
1107    //
1108    access(all)
1109    fun rarityToString(rarity: UInt64): String{ 
1110        switch rarity{ 
1111        case 0 as UInt64:
1112            return "Common"
1113        case 1 as UInt64:
1114            return "Rare"
1115        case 2 as UInt64:
1116            return "Epic"
1117        case 3 as UInt64:
1118            return "Legendary"
1119        }
1120        return ""
1121    }
1122
1123    // Init function of the smart contract
1124    //
1125    // "We drink to those who love us, we drink to those who don’t. 
1126    //  We drink to those who fuck us, and fuck those who don’t!"
1127    //
1128    init(){ 
1129        // Initialize the total supply
1130        self.totalSupply = 0
1131
1132        // position to take the drinks from
1133        self.firstIndex = 0
1134
1135        // Set last call
1136        self.lastCall = false
1137
1138        // Initialize drink prices
1139        self.beerPrice = 4.20
1140        self.whiskyPrice = 12.60
1141        self.longDrinkPrice = 42.00
1142
1143        // Init collections
1144        self.CollectionStoragePath = /storage/PartyMansionDrinkCollection
1145        self.CollectionPublicPath = /public/PartyMansionDrinkCollectionPublic
1146
1147        // init & save Barkeeper, assign to Bar 
1148        self.BarkeeperStoragePath = /storage/PartyMansionBarkeeper
1149        self.account.storage.save<@Barkeeper>(<-create Barkeeper(), to: self.BarkeeperStoragePath)
1150
1151        // Init the Bar
1152        self.fridge = []
1153        self.shaker = []
1154        self.whiskyCellar = []
1155    }
1156}
1157