Skip to content

Commit

Permalink
Swith view and access positions
Browse files Browse the repository at this point in the history
  • Loading branch information
bshahid331 committed Apr 3, 2024
1 parent 269f08b commit 4ed8b2e
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 85 deletions.
38 changes: 19 additions & 19 deletions contracts/FastBreakV1.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ access(all) contract FastBreakV1: NonFungibleToken {

/// Get a Fast Break Run by Id
///
view access(all) fun getFastBreakRun(id: String): FastBreakV1.FastBreakRun? {
access(all) view fun getFastBreakRun(id: String): FastBreakV1.FastBreakRun? {
return FastBreakV1.fastBreakRunByID[id]
}

Expand Down Expand Up @@ -235,7 +235,7 @@ access(all) contract FastBreakV1: NonFungibleToken {

/// Get a account's active Fast Break Submission
///
view access(all) fun getFastBreakSubmissionByPlayerId(playerId: UInt64): FastBreakV1.FastBreakSubmission? {
access(all) view fun getFastBreakSubmissionByPlayerId(playerId: UInt64): FastBreakV1.FastBreakSubmission? {
let fastBreakSubmissions = self.submissions

return fastBreakSubmissions[playerId]
Expand Down Expand Up @@ -301,19 +301,19 @@ access(all) contract FastBreakV1: NonFungibleToken {

/// Validate Fast Break Submission
///
view access(all) fun isValidSubmission(submissionDeadline: UInt64): Bool {
access(all) view fun isValidSubmission(submissionDeadline: UInt64): Bool {
return submissionDeadline > UInt64(getCurrentBlock().timestamp)
}

/// Get a Fast Break Game by Id
///
view access(all) fun getFastBreakGame(id: String): FastBreakV1.FastBreakGame? {
access(all) view fun getFastBreakGame(id: String): FastBreakV1.FastBreakGame? {
return FastBreakV1.fastBreakGameByID[id]
}

/// Get the game stats of a Fast Break
///
view access(all) fun getFastBreakGameStats(id: String): [FastBreakV1.FastBreakStat] {
access(all) view fun getFastBreakGameStats(id: String): [FastBreakV1.FastBreakStat] {
if let fastBreak = FastBreakV1.getFastBreakGame(id: id) {
return fastBreak.stats
}
Expand All @@ -322,7 +322,7 @@ access(all) contract FastBreakV1: NonFungibleToken {

/// Get a Fast Break account by playerId
///
view access(all) fun getFastBreakPlayer(id: UInt64): Address? {
access(all) view fun getFastBreakPlayer(id: UInt64): Address? {
return FastBreakV1.playerAccountMapping[id]
}

Expand Down Expand Up @@ -538,13 +538,13 @@ access(all) contract FastBreakV1: NonFungibleToken {

/// Get a player id by account address
///
view access(all) fun getPlayerIdByAccount(accountAddress: Address): UInt64 {
access(all) view fun getPlayerIdByAccount(accountAddress: Address): UInt64 {
return FastBreakV1.accountPlayerMapping[accountAddress]!
}

/// Validate Fast Break Submission topShots
///
view access(all) fun validatePlaySubmission(fastBreakGame: FastBreakGame, topShots: [UInt64]): Bool {
access(all) view fun validatePlaySubmission(fastBreakGame: FastBreakGame, topShots: [UInt64]): Bool {

if (topShots.length < 1) {
return false
Expand Down Expand Up @@ -591,7 +591,7 @@ access(all) contract FastBreakV1: NonFungibleToken {
self.mintedTo = mintedTo
}

view access(all) fun isWinner(): Bool {
access(all) view fun isWinner(): Bool {
if let fastBreak = FastBreakV1.fastBreakGameByID[self.fastBreakGameID] {
if let submission = fastBreak.submissions[self.mintedTo] {
return submission.win
Expand All @@ -600,7 +600,7 @@ access(all) contract FastBreakV1: NonFungibleToken {
return false
}

view access(all) fun points(): UInt64 {
access(all) view fun points(): UInt64 {
if let fastBreak = FastBreakV1.fastBreakGameByID[self.fastBreakGameID] {
if let submission = fastBreak.submissions[self.mintedTo] {
return submission.points
Expand All @@ -613,7 +613,7 @@ access(all) contract FastBreakV1: NonFungibleToken {
return <- FastBreakV1.createEmptyCollection(nftType: Type<@FastBreakV1.NFT>())
}

view access(all) fun getViews(): [Type] {
access(all) view fun getViews(): [Type] {
return [
Type<MetadataViews.NFTCollectionData>(),
Type<MetadataViews.NFTCollectionDisplay>()
Expand Down Expand Up @@ -691,27 +691,27 @@ access(all) contract FastBreakV1: NonFungibleToken {
destroy tokens
}

view access(all) fun getIDs(): [UInt64] {
access(all) view fun getIDs(): [UInt64] {
return self.ownedNFTs.keys
}

view access(all) fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? {
access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? {
return &self.ownedNFTs[id]
}

view access(all) fun borrowFastBreakNFT(id: UInt64): &FastBreakV1.NFT? {
access(all) view fun borrowFastBreakNFT(id: UInt64): &FastBreakV1.NFT? {
return self.borrowNFT(id) as! &FastBreakV1.NFT?
}

view access(all) fun getSupportedNFTTypes(): {Type: Bool} {
access(all) view fun getSupportedNFTTypes(): {Type: Bool} {
let supportedTypes: {Type: Bool} = {}
supportedTypes[Type<@FastBreakV1.NFT>()] = true
return supportedTypes
}

// Return whether or not the given type is accepted by the collection
// A collection that can accept any type should just return true by default
view access(all) fun isSupportedNFTType(type: Type): Bool {
access(all) view fun isSupportedNFTType(type: Type): Bool {
if type == Type<@FastBreakV1.NFT>() {
return true
}
Expand All @@ -722,7 +722,7 @@ access(all) contract FastBreakV1: NonFungibleToken {
return <- FastBreakV1.createEmptyCollection(nftType: Type<@FastBreakV1.NFT>())
}

view access(all) fun getLength(): Int {
access(all) view fun getLength(): Int {
return self.ownedNFTs.keys.length
}

Expand All @@ -738,11 +738,11 @@ access(all) contract FastBreakV1: NonFungibleToken {
return <- create Collection()
}

view access(all) fun getContractViews(resourceType: Type?): [Type] {
access(all) view fun getContractViews(resourceType: Type?): [Type] {
return [Type<MetadataViews.NFTCollectionData>(), Type<MetadataViews.NFTCollectionDisplay>()]
}

view access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
access(all) view fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
post {
result == nil || result!.getType() == viewType: "The returned view must be of the given type or nil"
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/MarketTopShotOldVersion.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,18 @@ access(all) contract Market {
}

// getPrice returns the price of a specific token in the sale
view access(all) fun getPrice(tokenID: UInt64): UFix64? {
access(all) view fun getPrice(tokenID: UInt64): UFix64? {
return self.prices[tokenID]
}

// getIDs returns an array of token IDs that are for sale
view access(all) fun getIDs(): [UInt64] {
access(all) view fun getIDs(): [UInt64] {
return self.forSale.getIDs()
}

// borrowMoment Returns a borrowed reference to a Moment in the collection
// so that the caller can read data from it
view access(all) fun borrowMoment(id: UInt64): &TopShot.NFT? {
access(all) view fun borrowMoment(id: UInt64): &TopShot.NFT? {
let ref = self.forSale.borrowMoment(id: id)
return ref
}
Expand Down
Loading

0 comments on commit 4ed8b2e

Please sign in to comment.