Skip to content

Commit

Permalink
fastbreak(cadence): upgrade
Browse files Browse the repository at this point in the history
* Check all collections.
  • Loading branch information
chumeston committed Dec 9, 2024
1 parent 25e36b9 commit 974bec8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions contracts/FastBreakV1.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import NonFungibleToken from 0xNFTADDRESS
import TopShot from 0xTOPSHOTADDRESS
import MetadataViews from 0xMETADATAVIEWSADDRESS
import TopShotMarketV3, Market from 0xMARKETV3ADDRESS

/// Game & Oracle Contract for Fast Break V1
///
Expand Down Expand Up @@ -413,17 +414,25 @@ access(all) contract FastBreakV1: NonFungibleToken {
FastBreakV1.accountPlayerMapping[ownerAddress] = self.id
}

/// Validate Top Shots
/// Validate Top Shots
let acct = getAccount(self.owner?.address!)
let collectionRef = acct.capabilities.borrow<&TopShot.Collection>(/public/MomentCollection)
?? panic("Player does not have top shot collection")
let marketV3CollectionRef = acct.capabilities.borrow<&TopShotMarketV3.SaleCollection>(/public/topshotSalev3Collection)
let marketV1CollectionRef = acct.capabilities.borrow<&Market.SaleCollection>(/public/topshotSaleCollection)

/// Must own Top Shots to play Fast Break
/// more efficient to borrow ref than to loop
///
for flowId in topShots {
let topShotRef = collectionRef.borrowMoment(id: flowId)
?? panic("Top shot not owned in collection with flowId: ".concat(flowId.toString()))
if topShotRef == nil {
let hasMarketPlaceV3 = marketV3CollectionRef != nil && marketV3CollectionRef.borrowMoment(id: flowId) != nil
let hasMartketV1 = marketV1CollectionRef != nil && marketV1CollectionRef.borrowMoment(id: flowId)
if !hasMarketPlaceV3 && !hasMartketV1{
panic("does not own")
}
}
}

let fastBreakGame = (&FastBreakV1.fastBreakGameByID[fastBreakGameID] as &FastBreakV1.FastBreakGame?)
Expand Down

0 comments on commit 974bec8

Please sign in to comment.