Skip to content

Commit

Permalink
Repo structure
Browse files Browse the repository at this point in the history
  • Loading branch information
lealobanov committed Dec 11, 2024
1 parent 06dd44d commit 9212ebd
Show file tree
Hide file tree
Showing 9 changed files with 239 additions and 165 deletions.
29 changes: 25 additions & 4 deletions .github/workflows/cadence_lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Cadence Lint
name: Run Cadence Contract Compilation, Deployment, Transaction Execution, and Lint
on: push

jobs:
Expand All @@ -9,7 +9,7 @@ jobs:
uses: actions/checkout@v3
with:
submodules: 'true'

- name: Install Flow CLI
run: |
brew update
Expand All @@ -23,8 +23,29 @@ jobs:
else
echo "Flow project already initialized."
fi
flow dependencies install
- name: Start Flow Emulator
run: |
echo "Starting Flow emulator in the background..."
nohup flow emulator start > emulator.log 2>&1 &
sleep 5 # Wait for the emulator to start
flow project deploy --network=emulator # Deploy the recipe contracts indicated in flow.json
- name: Run All Transactions
run: |
echo "Running all transactions in the transactions folder..."
for file in ./cadence/transactions/*.cdc; do
echo "Running transaction: $file"
TRANSACTION_OUTPUT=$(flow transactions send "$file" --signer emulator-account)
echo "$TRANSACTION_OUTPUT"
if echo "$TRANSACTION_OUTPUT" | grep -q "Transaction Error"; then
echo "Transaction Error detected in $file, failing the action..."
exit 1
fi
done
- name: Run Cadence Lint
run: |
echo "Running Cadence linter on all .cdc files in the current repository"
flow cadence lint **/*.cdc
echo "Running Cadence linter on .cdc files in the current repository"
flow cadence lint ./cadence/**/*.cdc
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
.DS_Store
.DS_Store
/imports/
/.idea/
125 changes: 0 additions & 125 deletions cadence/contract.cdc

This file was deleted.

1 change: 1 addition & 0 deletions cadence/contract.cdc
57 changes: 57 additions & 0 deletions cadence/contracts/Recipe.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import "TopShot"

access(all) contract Recipe {
// This is a snippet extracting the relevant logic from the TopShot contract for demonstration purposes
// More TopShot Code Above
access(all) event PlayAddedToSet(setID: UInt32, playID: UInt32)

access(all) resource Set {

// addPlay adds a play to the set
//
// Parameters: playID: The ID of the Play that is being added
//
// Pre-Conditions:
// The Play needs to be an existing play
// The Set needs to be not locked
// The Play can't have already been added to the Set
//
/// Resource fields
access(all) var locked: Bool
access(all) let plays: [UInt32]
access(all) let retired: {UInt32: Bool}
access(all) let numberMintedPerPlay: {UInt32: UInt32}
access(all) let setID: UInt32

// Resource initializer
init(setID: UInt32) {
self.locked = false
self.plays = []
self.retired = {}
self.numberMintedPerPlay = {}
self.setID = setID
}

access(all) fun addPlay(playID: UInt32) {
pre {
TopShot.getPlayMetaData(playID: playID) != nil: "Cannot add the Play to Set: Play doesn't exist."
!self.locked: "Cannot add the play to the Set after the set has been locked."
self.numberMintedPerPlay[playID] == nil: "The play has already been added to the set."
}

// Add the Play to the array of Plays
self.plays.append(playID)

// Open the Play up for minting
self.retired[playID] = false

// Initialize the Moment count to zero
self.numberMintedPerPlay[playID] = 0

emit PlayAddedToSet(setID: self.setID, playID: playID)
}
}
// More TopShot Code Below
}
6 changes: 6 additions & 0 deletions cadence/tests/Recipe_test.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import Test

access(all) fun testExample() {
let array = [1, 2, 3]
Test.expect(array.length, Test.equal(3))
}
32 changes: 0 additions & 32 deletions cadence/transaction.cdc

This file was deleted.

1 change: 1 addition & 0 deletions cadence/transaction.cdc
32 changes: 32 additions & 0 deletions cadence/transactions/mint_moment.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import "TopShot"

transaction {

let admin: auth(AdminEntitlement) &TopShot.Admin
let borrowedSet: &TopShot.Set

prepare(acct: auth(Storage, Capabilities) &Account) {
// Borrow the admin resource
self.admin = acct.capabilities.storage.borrow<&TopShot.Admin>(
from: /storage/TopShotAdmin
) ?? panic("Can't borrow admin resource")

// Borrow the Set resource
self.borrowedSet = self.admin.borrowSet(setID: 1)

// Borrow the recipient's MomentCollectionPublic capability
let receiverRef = acct.capabilities.borrow<&{TopShot.MomentCollectionPublic}>(
/public/MomentCollection
) ?? panic("Can't borrow collection reference")

// Mint moments and return them as a collection
let collection <- self.borrowedSet.batchMintMoment(playID: 3, quantity: 3)

// Deposit the minted moments into the recipient's collection
receiverRef.batchDeposit(tokens: <-collection)
}

execute {
log("Plays minted")
}
}
1 change: 1 addition & 0 deletions emulator-account.pkey
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xdc07d83a937644ff362b279501b7f7a3735ac91a0f3647147acf649dda804e28
Loading

0 comments on commit 9212ebd

Please sign in to comment.