Skip to content

Commit

Permalink
C1.0 migration
Browse files Browse the repository at this point in the history
  • Loading branch information
lealobanov committed Nov 14, 2024
1 parent 2a7661a commit 4e7389b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 35 deletions.
34 changes: 17 additions & 17 deletions cadence/contract.cdc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//TopShot Contract Code Above
...
.....

access(self) var playDatas: {UInt32: Play}
access(all) var playDatas: {UInt32: Play}

pub var nextPlayID: UInt32
access(all) var nextPlayID: UInt32

.....

Expand All @@ -16,16 +16,15 @@ pub var nextPlayID: UInt32
// its metadata. The plays are publicly accessible, so anyone can
// read the metadata associated with a specific play ID
//
pub struct Play {
access(all)
struct Play {

// The unique ID for the Play
pub let playID: UInt32
access(all) let playID: UInt32

// Stores all the metadata about the play as a string mapping
// This is not the long term way NFT metadata will be stored. It's a temporary
// construct while we figure out a better way to do metadata.
//
pub let metadata: {String: String}
// This is not the long-term way NFT metadata will be stored.
access(all) let metadata: {String: String}

init(metadata: {String: String}) {
pre {
Expand All @@ -36,22 +35,21 @@ pub struct Play {
}
}


.....

pub resource Admin {
access(all)
resource Admin {

// createPlay creates a new Play struct
// and stores it in the Plays dictionary in the TopShot smart contract
//
// Parameters: metadata: A dictionary mapping metadata titles to their data
// example: {"Player Name": "Kevin Durant", "Height": "7 feet"}
// (because we all know Kevin Durant is not 6'9")
//
// Returns: the ID of the new Play object
//
pub fun createPlay(metadata: {String: String}): UInt32 {
access(all)
fun createPlay(metadata: {String: String}): UInt32 {
// Create the new Play
var newPlay = Play(metadata: metadata)
let newPlay = Play(metadata: metadata)
let newID = newPlay.playID

// Increment the ID so that it isn't used again
Expand All @@ -64,6 +62,8 @@ pub resource Admin {

return newID
}
....
}

....

//rest of TopShot contract below
25 changes: 11 additions & 14 deletions cadence/transaction.cdc
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import TopShot from 0x01


transaction {
let admin: auth(Admin) &TopShot.Admin

let admin: &TopShot.Admin

prepare(acct: AuthAccount) {

self.admin = acct.borrow<&TopShot.Admin>(from: /storage/TopShotAdmin)
?? panic("Cant borrow admin resource")

prepare(acct: auth(Storage) &Account) {
// Borrow the Admin resource from the specified storage path
self.admin = acct.storage.borrow<&TopShot.Admin>(from: /storage/TopShotAdmin)
?? panic("Cannot borrow admin resource")
}


execute {
self.admin.createPlay(metadata: {"Rookie": "2004", "Player Name": "Dwight Howard"})
self.admin.createPlay(metadata: {"Rookie": "2003", "Player Name": "Dwayne Wade"})
log("play created")
}
execute {
// Create plays using the admin resource
self.admin.createPlay(metadata: {"Rookie": "2004", "Player Name": "Dwight Howard"})
self.admin.createPlay(metadata: {"Rookie": "2003", "Player Name": "Dwayne Wade"})
log("Play created")
}
}
7 changes: 3 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const transactionPath = `${recipe}/cadence/transaction.cdc`;
const smartContractExplanationPath = `${recipe}/explanations/contract.txt`;
const transactionExplanationPath = `${recipe}/explanations/transaction.txt`;

export const createATopShotPlay= {
export const createATopShotPlay = {
slug: recipe,
title: "Create a TopShot Play",
createdAt: new Date(2022, 3, 1),
Expand All @@ -23,7 +23,6 @@ export const createATopShotPlay= {
transactionCode: transactionPath,
transactionExplanation: transactionExplanationPath,
filters: {
difficulty: "intermediate"
}
difficulty: "intermediate",
},
};

0 comments on commit 4e7389b

Please sign in to comment.