@@ -131,10 +131,13 @@ pub contract AllDay: NonFungibleToken {
131
131
// initializer
132
132
//
133
133
init (id : UInt64 ) {
134
- let series = &AllDay.seriesByID[id] as! &AllDay.Series
135
- self .id = series.id
136
- self .name = series.name
137
- self .active = series.active
134
+ if let series = &AllDay.seriesByID[id] as &AllDay.Series? {
135
+ self .id = series.id
136
+ self .name = series.name
137
+ self .active = series.active
138
+ } else {
139
+ panic (" series does not exist" )
140
+ }
138
141
}
139
142
}
140
143
@@ -229,10 +232,13 @@ pub contract AllDay: NonFungibleToken {
229
232
// initializer
230
233
//
231
234
init (id : UInt64 ) {
232
- let set = &AllDay.setByID[id] as! &AllDay.Set
235
+ if let set = &AllDay.setByID[id] as &AllDay.Set? {
233
236
self .id = id
234
237
self .name = set.name
235
238
self .setPlaysInEditions = set.setPlaysInEditions
239
+ } else {
240
+ panic (" set does not exist" )
241
+ }
236
242
}
237
243
}
238
244
@@ -312,10 +318,13 @@ pub contract AllDay: NonFungibleToken {
312
318
// initializer
313
319
//
314
320
init (id : UInt64 ) {
315
- let play = &AllDay.playByID[id] as! &AllDay.Play
321
+ if let play = &AllDay.playByID[id] as &AllDay.Play? {
316
322
self .id = id
317
323
self .classification = play.classification
318
324
self .metadata = play.metadata
325
+ } else {
326
+ panic (" play does not exist" )
327
+ }
319
328
}
320
329
}
321
330
@@ -374,14 +383,17 @@ pub contract AllDay: NonFungibleToken {
374
383
// initializer
375
384
//
376
385
init (id : UInt64 ) {
377
- let edition = &AllDay.editionByID[id] as! &AllDay.Edition
386
+ if let edition = &AllDay.editionByID[id] as &AllDay.Edition? {
378
387
self .id = id
379
388
self .seriesID = edition.seriesID
380
389
self .playID = edition.playID
381
390
self .setID = edition.setID
382
391
self .maxMintSize = edition.maxMintSize
383
392
self .tier = edition.tier
384
393
self .numMinted = edition.numMinted
394
+ } else {
395
+ panic (" edition does not exist" )
396
+ }
385
397
}
386
398
}
387
399
@@ -611,15 +623,21 @@ pub contract AllDay: NonFungibleToken {
611
623
// borrowNFT gets a reference to an NFT in the collection
612
624
//
613
625
pub fun borrowNFT (id : UInt64 ): &NonFungibleToken .NFT {
614
- return &self .ownedNFTs[id] as &NonFungibleToken.NFT
626
+ pre {
627
+ self .ownedNFTs[id] ! = nil : " Cannot borrow NFT, no such id"
628
+ }
629
+
630
+ return (&self .ownedNFTs[id] as &NonFungibleToken.NFT? )!
615
631
}
616
632
617
633
// borrowMomentNFT gets a reference to an NFT in the collection
618
634
//
619
635
pub fun borrowMomentNFT (id : UInt64 ): &AllDay .NFT ? {
620
636
if self .ownedNFTs[id] ! = nil {
621
- let ref = &self .ownedNFTs[id] as auth &NonFungibleToken.NFT
622
- return ref as! &AllDay.NFT
637
+ if let ref = &self .ownedNFTs[id] as auth &NonFungibleToken.NFT? {
638
+ return ref! as! &AllDay.NFT
639
+ }
640
+ return nil
623
641
} else {
624
642
return nil
625
643
}
@@ -667,7 +685,7 @@ pub contract AllDay: NonFungibleToken {
667
685
AllDay.seriesByID[id] ! = nil : " Cannot borrow series, no such id"
668
686
}
669
687
670
- return &AllDay.seriesByID[id] as &AllDay.Series
688
+ return ( &AllDay.seriesByID[id] as &AllDay.Series? ) !
671
689
}
672
690
673
691
// Borrow a Set
@@ -677,7 +695,7 @@ pub contract AllDay: NonFungibleToken {
677
695
AllDay.setByID[id] ! = nil : " Cannot borrow Set, no such id"
678
696
}
679
697
680
- return &AllDay.setByID[id] as &AllDay.Set
698
+ return ( &AllDay.setByID[id] as &AllDay.Set? ) !
681
699
}
682
700
683
701
// Borrow a Play
@@ -687,7 +705,7 @@ pub contract AllDay: NonFungibleToken {
687
705
AllDay.playByID[id] ! = nil : " Cannot borrow Play, no such id"
688
706
}
689
707
690
- return &AllDay.playByID[id] as &AllDay.Play
708
+ return ( &AllDay.playByID[id] as &AllDay.Play? ) !
691
709
}
692
710
693
711
// Borrow an Edition
@@ -697,7 +715,7 @@ pub contract AllDay: NonFungibleToken {
697
715
AllDay.editionByID[id] ! = nil : " Cannot borrow edition, no such id"
698
716
}
699
717
700
- return &AllDay.editionByID[id] as &AllDay.Edition
718
+ return ( &AllDay.editionByID[id] as &AllDay.Edition? ) !
701
719
}
702
720
703
721
// Create a Series
@@ -717,9 +735,11 @@ pub contract AllDay: NonFungibleToken {
717
735
// Close a Series
718
736
//
719
737
pub fun closeSeries (id : UInt64 ): UInt64 {
720
- let series = &AllDay.seriesByID[id] as &AllDay.Series
721
- series.close ()
722
- return series.id
738
+ if let series = &AllDay.seriesByID[id] as &AllDay.Series? {
739
+ series.close ()
740
+ return series.id
741
+ }
742
+ panic (" series does not exist" )
723
743
}
724
744
725
745
// Create a Set
@@ -775,9 +795,11 @@ pub contract AllDay: NonFungibleToken {
775
795
// Close an Edition
776
796
//
777
797
pub fun closeEdition (id : UInt64 ): UInt64 {
778
- let edition = &AllDay.editionByID[id] as &AllDay.Edition
779
- edition.close ()
780
- return edition.id
798
+ if let edition = &AllDay.editionByID[id] as &AllDay.Edition? {
799
+ edition.close ()
800
+ return edition.id
801
+ }
802
+ panic (" edition does not exist" )
781
803
}
782
804
783
805
// Mint a single NFT
@@ -788,7 +810,6 @@ pub contract AllDay: NonFungibleToken {
788
810
// Make sure the edition we are creating this NFT in exists
789
811
AllDay.editionByID.containsKey (editionID): " No such EditionID"
790
812
}
791
-
792
813
return <- self .borrowEdition (id : editionID).mint ()
793
814
}
794
815
}
0 commit comments