-
Notifications
You must be signed in to change notification settings - Fork 2
Sadie/AllDay Secure Cadence upgrade #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6a0b1a4
817d690
d560e27
3f69b8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,10 +131,13 @@ pub contract AllDay: NonFungibleToken { | |
// initializer | ||
// | ||
init (id: UInt64) { | ||
let series = &AllDay.seriesByID[id] as! &AllDay.Series | ||
self.id = series.id | ||
self.name = series.name | ||
self.active = series.active | ||
if let series = &AllDay.seriesByID[id] as &AllDay.Series? { | ||
self.id = series.id | ||
self.name = series.name | ||
self.active = series.active | ||
} else { | ||
panic("series does not exist") | ||
} | ||
} | ||
} | ||
|
||
|
@@ -229,10 +232,13 @@ pub contract AllDay: NonFungibleToken { | |
// initializer | ||
// | ||
init (id: UInt64) { | ||
let set = &AllDay.setByID[id] as! &AllDay.Set | ||
if let set = &AllDay.setByID[id] as &AllDay.Set? { | ||
self.id = id | ||
self.name = set.name | ||
self.setPlaysInEditions = set.setPlaysInEditions | ||
} else { | ||
panic("set does not exist") | ||
} | ||
} | ||
} | ||
|
||
|
@@ -312,10 +318,13 @@ pub contract AllDay: NonFungibleToken { | |
// initializer | ||
// | ||
init (id: UInt64) { | ||
let play = &AllDay.playByID[id] as! &AllDay.Play | ||
if let play = &AllDay.playByID[id] as &AllDay.Play? { | ||
self.id = id | ||
self.classification = play.classification | ||
self.metadata = play.metadata | ||
} else { | ||
panic("play does not exist") | ||
} | ||
} | ||
} | ||
|
||
|
@@ -374,14 +383,17 @@ pub contract AllDay: NonFungibleToken { | |
// initializer | ||
// | ||
init (id: UInt64) { | ||
let edition = &AllDay.editionByID[id] as! &AllDay.Edition | ||
if let edition = &AllDay.editionByID[id] as &AllDay.Edition? { | ||
self.id = id | ||
self.seriesID = edition.seriesID | ||
self.playID = edition.playID | ||
self.setID = edition.setID | ||
self.maxMintSize = edition.maxMintSize | ||
self.tier = edition.tier | ||
self.numMinted = edition.numMinted | ||
} else { | ||
panic("edition does not exist") | ||
} | ||
} | ||
} | ||
|
||
|
@@ -611,15 +623,21 @@ pub contract AllDay: NonFungibleToken { | |
// borrowNFT gets a reference to an NFT in the collection | ||
// | ||
pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT { | ||
return &self.ownedNFTs[id] as &NonFungibleToken.NFT | ||
pre { | ||
self.ownedNFTs[id] != nil: "Cannot borrow NFT, no such id" | ||
} | ||
|
||
return (&self.ownedNFTs[id] as &NonFungibleToken.NFT?)! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used the force unwrap here because we have already nil checked in the precondition and I figured it would be easier than changing the function signature to limit what we need to change on our transactions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Open to other suggestions here though!) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, I think in an ideal world, we would return an optional, but that would require changing the standard, which would be a breaking change unfortunately |
||
} | ||
|
||
// borrowMomentNFT gets a reference to an NFT in the collection | ||
// | ||
pub fun borrowMomentNFT(id: UInt64): &AllDay.NFT? { | ||
if self.ownedNFTs[id] != nil { | ||
let ref = &self.ownedNFTs[id] as auth &NonFungibleToken.NFT | ||
return ref as! &AllDay.NFT | ||
if let ref = &self.ownedNFTs[id] as auth &NonFungibleToken.NFT? { | ||
return ref! as! &AllDay.NFT | ||
} | ||
return nil | ||
} else { | ||
return nil | ||
} | ||
|
@@ -667,7 +685,7 @@ pub contract AllDay: NonFungibleToken { | |
AllDay.seriesByID[id] != nil: "Cannot borrow series, no such id" | ||
} | ||
|
||
return &AllDay.seriesByID[id] as &AllDay.Series | ||
return (&AllDay.seriesByID[id] as &AllDay.Series?)! | ||
} | ||
|
||
// Borrow a Set | ||
|
@@ -677,7 +695,7 @@ pub contract AllDay: NonFungibleToken { | |
AllDay.setByID[id] != nil: "Cannot borrow Set, no such id" | ||
} | ||
|
||
return &AllDay.setByID[id] as &AllDay.Set | ||
return (&AllDay.setByID[id] as &AllDay.Set?)! | ||
} | ||
|
||
// Borrow a Play | ||
|
@@ -687,7 +705,7 @@ pub contract AllDay: NonFungibleToken { | |
AllDay.playByID[id] != nil: "Cannot borrow Play, no such id" | ||
} | ||
|
||
return &AllDay.playByID[id] as &AllDay.Play | ||
return (&AllDay.playByID[id] as &AllDay.Play?)! | ||
} | ||
|
||
// Borrow an Edition | ||
|
@@ -697,7 +715,7 @@ pub contract AllDay: NonFungibleToken { | |
AllDay.editionByID[id] != nil: "Cannot borrow edition, no such id" | ||
} | ||
|
||
return &AllDay.editionByID[id] as &AllDay.Edition | ||
return (&AllDay.editionByID[id] as &AllDay.Edition?)! | ||
} | ||
|
||
// Create a Series | ||
|
@@ -717,9 +735,11 @@ pub contract AllDay: NonFungibleToken { | |
// Close a Series | ||
// | ||
pub fun closeSeries(id: UInt64): UInt64 { | ||
let series = &AllDay.seriesByID[id] as &AllDay.Series | ||
series.close() | ||
return series.id | ||
if let series = &AllDay.seriesByID[id] as &AllDay.Series? { | ||
series.close() | ||
return series.id | ||
} | ||
panic("series does not exist") | ||
} | ||
|
||
// Create a Set | ||
|
@@ -775,9 +795,11 @@ pub contract AllDay: NonFungibleToken { | |
// Close an Edition | ||
// | ||
pub fun closeEdition(id: UInt64): UInt64 { | ||
let edition = &AllDay.editionByID[id] as &AllDay.Edition | ||
edition.close() | ||
return edition.id | ||
if let edition = &AllDay.editionByID[id] as &AllDay.Edition? { | ||
edition.close() | ||
return edition.id | ||
} | ||
panic("edition does not exist") | ||
} | ||
|
||
// Mint a single NFT | ||
|
@@ -788,7 +810,6 @@ pub contract AllDay: NonFungibleToken { | |
// Make sure the edition we are creating this NFT in exists | ||
AllDay.editionByID.containsKey(editionID): "No such EditionID" | ||
} | ||
|
||
return <- self.borrowEdition(id: editionID).mint() | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Talked to Bastian about best practise syntax for this. Slack thread here for context: https://axiomzen.slack.com/archives/CTGAW0TM2/p1653430599342029