-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from onflow/c1-migration
C1.0 migration
- Loading branch information
Showing
14 changed files
with
382 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Run Cadence Contract Compilation, Deployment, Transaction Execution, and Lint | ||
on: push | ||
|
||
jobs: | ||
run-cadence-lint: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: 'true' | ||
|
||
- name: Install Flow CLI | ||
run: | | ||
brew update | ||
brew install flow-cli | ||
- name: Initialize Flow | ||
run: | | ||
if [ ! -f flow.json ]; then | ||
echo "Initializing Flow project..." | ||
flow init | ||
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 .cdc files in the current repository" | ||
flow cadence lint ./cadence/**/*.cdc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Run Cadence Tests | ||
on: push | ||
|
||
jobs: | ||
run-cadence-tests: | ||
runs-on: macos-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: 'true' | ||
|
||
- name: Install Flow CLI | ||
run: | | ||
brew update | ||
brew install flow-cli | ||
- name: Initialize Flow | ||
run: | | ||
if [ ! -f flow.json ]; then | ||
echo "Initializing Flow project..." | ||
flow init | ||
else | ||
echo "Flow project already initialized." | ||
fi | ||
- name: Run Cadence Tests | ||
run: | | ||
if test -f "cadence/tests.cdc"; then | ||
echo "Running Cadence tests in the current repository" | ||
flow test cadence/tests.cdc | ||
else | ||
echo "No Cadence tests found. Skipping tests." | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.DS_Store | ||
.DS_Store | ||
/imports/ | ||
/.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
./cadence/contracts/Recipe.cdc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import "TopShot" | ||
|
||
access(all) contract Recipe { | ||
// This is a snippet extracting the relevant logic from the TopShot contract for demonstration purposes | ||
// TopShot Contract Code Above | ||
access(all) var playDatas: {UInt32: Recipe.Play} | ||
access(all) var nextPlayID: UInt32 | ||
|
||
access(all) event PlayCreated(id: UInt32, metadata: {String: String}) | ||
|
||
init() { | ||
self.playDatas = {} | ||
self.nextPlayID = 0 | ||
} | ||
|
||
// Play is a Struct that holds metadata associated | ||
// with a specific NBA play, like the legendary moment when | ||
// Ray Allen hit the 3 to tie the Heat and Spurs in the 2013 finals game 6 | ||
// or when Lance Stephenson blew in the ear of Lebron James. | ||
// | ||
// Moment NFTs will all reference a single play as the owner of | ||
// its metadata. The plays are publicly accessible, so anyone can | ||
// read the metadata associated with a specific play ID | ||
// | ||
access(all) struct Play { | ||
// The unique ID for the Play | ||
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. | ||
access(all) let metadata: {String: String} | ||
|
||
init(metadata: {String: String}) { | ||
pre { | ||
metadata.length != 0: "New Play metadata cannot be empty" | ||
} | ||
self.playID = TopShot.nextPlayID | ||
self.metadata = metadata | ||
} | ||
} | ||
|
||
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 | ||
// Returns: the ID of the new Play object | ||
access(all) | ||
fun createPlay(metadata: {String: String}): UInt32 { | ||
// Create the new Play | ||
let newPlay = Play(metadata: metadata) | ||
let newID = newPlay.playID | ||
|
||
// Increment the ID so that it isn't used again | ||
Recipe.nextPlayID = Recipe.nextPlayID + UInt32(1) | ||
|
||
emit PlayCreated(id: newPlay.playID, metadata: metadata) | ||
|
||
// Store it in the contract storage | ||
Recipe.playDatas[newID] = newPlay | ||
|
||
return newID | ||
} | ||
} | ||
|
||
// Rest of TopShot contract below | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import Test | ||
|
||
access(all) | ||
fun setup() { | ||
|
||
let err = Test.deployContract( | ||
name: "Recipe", | ||
path: "../contracts/Recipe.cdc", | ||
arguments: [], | ||
) | ||
|
||
Test.expect(err, Test.beNil()) | ||
} | ||
|
||
access(all) fun testExample() { | ||
let array = [1, 2, 3] | ||
Test.expect(array.length, Test.equal(3)) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
./cadence/transactions/create_play.cdc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import "TopShot" | ||
|
||
transaction { | ||
let admin: &TopShot.Admin | ||
|
||
prepare(signer: auth(Storage) &Account) { | ||
// Borrow the Admin resource from the specified storage path | ||
self.admin = signer.storage.borrow<&TopShot.Admin>(from: /storage/TopShotAdmin) | ||
?? panic("Cannot borrow admin resource") | ||
} | ||
|
||
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") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0xdc07d83a937644ff362b279501b7f7a3735ac91a0f3647147acf649dda804e28 |
Oops, something went wrong.