|
1 | 1 | import TopShot from 0xTOPSHOTADDRESS |
2 | 2 |
|
3 | | -// This transaction updates an existing play struct |
4 | | -// and stores it in the Top Shot smart contract |
5 | | -// We currently stringify the metadata and insert it into the |
6 | | -// transaction string, but want to use transaction arguments soon |
| 3 | +// This transaction updates multiple existing plays' taglines |
| 4 | +// and stores them in the Top Shot smart contract |
7 | 5 |
|
8 | 6 | // Parameters: |
9 | 7 | // |
10 | | -// metadata: A dictionary of all the play metadata associated |
| 8 | +// plays: A dictionary of {playID: tagline} pairs |
11 | 9 |
|
12 | 10 | transaction(plays: {UInt32: String}) { |
13 | 11 |
|
14 | 12 | // Local variable for the topshot Admin object |
15 | 13 | let adminRef: &TopShot.Admin |
| 14 | + let firstKey: UInt32 |
| 15 | + let lastKey: UInt32 |
16 | 16 |
|
17 | 17 | prepare(acct: AuthAccount) { |
18 | 18 |
|
19 | 19 | // borrow a reference to the admin resource |
20 | 20 | self.adminRef = acct.borrow<&TopShot.Admin>(from: /storage/TopShotAdmin) |
21 | 21 | ?? panic("No admin resource in storage") |
| 22 | + self.firstKey = plays.keys[0] |
| 23 | + self.lastKey = plays.keys[plays.keys.length - 1] |
22 | 24 | } |
23 | 25 |
|
24 | 26 | execute { |
25 | | - // update a play with the specified metadata |
| 27 | + // update multiple plays with the specified metadata |
26 | 28 | for key in plays.keys { |
27 | 29 | self.adminRef.updatePlayTagline(playID: key, tagline: plays[key] ?? panic("No tagline for play")) |
28 | 30 | } |
29 | 31 | } |
30 | 32 |
|
31 | 33 | post { |
32 | | - for key in plays.keys { |
33 | | - TopShot.getPlayMetaDataByField(playID: key, field: "tagline") != nil: |
34 | | - "tagline doesnt exist" |
35 | | - } |
| 34 | + TopShot.getPlayMetaDataByField(playID: self.firstKey, field: "tagline") != nil: |
| 35 | + "first play's tagline doesnt exist" |
| 36 | + TopShot.getPlayMetaDataByField(playID: self.lastKey, field: "tagline") != nil: |
| 37 | + "last play's tagline doesnt exist" |
36 | 38 | } |
37 | 39 | } |
0 commit comments