Skip to content

Commit 28eea34

Browse files
authored
Merge pull request #10 from dapperlabs/sadie/secure-cadence
Sadie/AllDay Secure Cadence upgrade
2 parents 468524a + 3f69b8e commit 28eea34

File tree

5 files changed

+892
-32
lines changed

5 files changed

+892
-32
lines changed

contracts/AllDay.cdc

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,13 @@ pub contract AllDay: NonFungibleToken {
131131
// initializer
132132
//
133133
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+
}
138141
}
139142
}
140143

@@ -229,10 +232,13 @@ pub contract AllDay: NonFungibleToken {
229232
// initializer
230233
//
231234
init (id: UInt64) {
232-
let set = &AllDay.setByID[id] as! &AllDay.Set
235+
if let set = &AllDay.setByID[id] as &AllDay.Set? {
233236
self.id = id
234237
self.name = set.name
235238
self.setPlaysInEditions = set.setPlaysInEditions
239+
} else {
240+
panic("set does not exist")
241+
}
236242
}
237243
}
238244

@@ -312,10 +318,13 @@ pub contract AllDay: NonFungibleToken {
312318
// initializer
313319
//
314320
init (id: UInt64) {
315-
let play = &AllDay.playByID[id] as! &AllDay.Play
321+
if let play = &AllDay.playByID[id] as &AllDay.Play? {
316322
self.id = id
317323
self.classification = play.classification
318324
self.metadata = play.metadata
325+
} else {
326+
panic("play does not exist")
327+
}
319328
}
320329
}
321330

@@ -374,14 +383,17 @@ pub contract AllDay: NonFungibleToken {
374383
// initializer
375384
//
376385
init (id: UInt64) {
377-
let edition = &AllDay.editionByID[id] as! &AllDay.Edition
386+
if let edition = &AllDay.editionByID[id] as &AllDay.Edition? {
378387
self.id = id
379388
self.seriesID = edition.seriesID
380389
self.playID = edition.playID
381390
self.setID = edition.setID
382391
self.maxMintSize = edition.maxMintSize
383392
self.tier = edition.tier
384393
self.numMinted = edition.numMinted
394+
} else {
395+
panic("edition does not exist")
396+
}
385397
}
386398
}
387399

@@ -611,15 +623,21 @@ pub contract AllDay: NonFungibleToken {
611623
// borrowNFT gets a reference to an NFT in the collection
612624
//
613625
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?)!
615631
}
616632

617633
// borrowMomentNFT gets a reference to an NFT in the collection
618634
//
619635
pub fun borrowMomentNFT(id: UInt64): &AllDay.NFT? {
620636
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
623641
} else {
624642
return nil
625643
}
@@ -667,7 +685,7 @@ pub contract AllDay: NonFungibleToken {
667685
AllDay.seriesByID[id] != nil: "Cannot borrow series, no such id"
668686
}
669687

670-
return &AllDay.seriesByID[id] as &AllDay.Series
688+
return (&AllDay.seriesByID[id] as &AllDay.Series?)!
671689
}
672690

673691
// Borrow a Set
@@ -677,7 +695,7 @@ pub contract AllDay: NonFungibleToken {
677695
AllDay.setByID[id] != nil: "Cannot borrow Set, no such id"
678696
}
679697

680-
return &AllDay.setByID[id] as &AllDay.Set
698+
return (&AllDay.setByID[id] as &AllDay.Set?)!
681699
}
682700

683701
// Borrow a Play
@@ -687,7 +705,7 @@ pub contract AllDay: NonFungibleToken {
687705
AllDay.playByID[id] != nil: "Cannot borrow Play, no such id"
688706
}
689707

690-
return &AllDay.playByID[id] as &AllDay.Play
708+
return (&AllDay.playByID[id] as &AllDay.Play?)!
691709
}
692710

693711
// Borrow an Edition
@@ -697,7 +715,7 @@ pub contract AllDay: NonFungibleToken {
697715
AllDay.editionByID[id] != nil: "Cannot borrow edition, no such id"
698716
}
699717

700-
return &AllDay.editionByID[id] as &AllDay.Edition
718+
return (&AllDay.editionByID[id] as &AllDay.Edition?)!
701719
}
702720

703721
// Create a Series
@@ -717,9 +735,11 @@ pub contract AllDay: NonFungibleToken {
717735
// Close a Series
718736
//
719737
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")
723743
}
724744

725745
// Create a Set
@@ -775,9 +795,11 @@ pub contract AllDay: NonFungibleToken {
775795
// Close an Edition
776796
//
777797
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")
781803
}
782804

783805
// Mint a single NFT
@@ -788,7 +810,6 @@ pub contract AllDay: NonFungibleToken {
788810
// Make sure the edition we are creating this NFT in exists
789811
AllDay.editionByID.containsKey(editionID): "No such EditionID"
790812
}
791-
792813
return <- self.borrowEdition(id: editionID).mint()
793814
}
794815
}

lib/go/test/go.mod

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ module github.com/dapperlabs/nfl-smart-contracts/lib/go/test
33
go 1.16
44

55
require (
6-
github.com/onflow/cadence v0.18.0
7-
github.com/onflow/flow-emulator v0.22.0
6+
github.com/onflow/cadence v0.21.3-0.20220419065337-d5202c162010
7+
github.com/onflow/flow-emulator v0.31.2-0.20220422152808-6c116a9d88b7
88
github.com/onflow/flow-ft/lib/go/contracts v0.5.0
99
github.com/onflow/flow-ft/lib/go/templates v0.2.0
10-
github.com/onflow/flow-go-sdk v0.20.1-0.20210623043139-533a95abf071
11-
github.com/onflow/flow-nft/lib/go/contracts v0.0.0-20210603230546-76c44712d829
10+
github.com/onflow/flow-go v0.25.13-0.20220422145107-5a9458db1f1d // indirect
11+
github.com/onflow/flow-go-sdk v0.24.1-0.20220421152843-9ce4d554036e
12+
github.com/onflow/flow-nft/lib/go/contracts v0.0.0-20210915191154-12ee8c507a0e
1213
github.com/onflow/flow-nft/lib/go/templates v0.0.0-20210603230546-76c44712d829
13-
github.com/stretchr/testify v1.7.0
14+
github.com/stretchr/testify v1.7.1-0.20210824115523-ab6dc3262822
1415
gotest.tools v2.2.0+incompatible // indirect
15-
)
16+
)

0 commit comments

Comments
 (0)