From 4e7389b82587fece13abacc6e8281c3d243f711c Mon Sep 17 00:00:00 2001 From: Lea Lobanov Date: Thu, 14 Nov 2024 17:24:35 +0900 Subject: [PATCH] C1.0 migration --- cadence/contract.cdc | 34 +++++++++++++++++----------------- cadence/transaction.cdc | 25 +++++++++++-------------- index.js | 7 +++---- 3 files changed, 31 insertions(+), 35 deletions(-) diff --git a/cadence/contract.cdc b/cadence/contract.cdc index b28820b..35c8d65 100644 --- a/cadence/contract.cdc +++ b/cadence/contract.cdc @@ -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 ..... @@ -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 { @@ -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 @@ -64,6 +62,8 @@ pub resource Admin { return newID } -.... } + +.... + //rest of TopShot contract below \ No newline at end of file diff --git a/cadence/transaction.cdc b/cadence/transaction.cdc index 4243b02..1a346a6 100644 --- a/cadence/transaction.cdc +++ b/cadence/transaction.cdc @@ -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") + } } diff --git a/index.js b/index.js index 46fe180..a91e239 100644 --- a/index.js +++ b/index.js @@ -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), @@ -23,7 +23,6 @@ export const createATopShotPlay= { transactionCode: transactionPath, transactionExplanation: transactionExplanationPath, filters: { - difficulty: "intermediate" - } + difficulty: "intermediate", + }, }; -