Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C1.0 migration #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/cadence_lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run Cadence 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

- name: Run Cadence Lint
run: |
echo "Running Cadence linter on all .cdc files in the current repository"
flow cadence lint **/*.cdc
34 changes: 34 additions & 0 deletions .github/workflows/cadence_tests.yml
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
16 changes: 8 additions & 8 deletions cadence/contract.cdc
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
pub resource interface Provider {
access(all)
resource interface Provider {

// withdraw
//
// Function that subtracts tokens from the owner's Vault
// and returns a Vault resource (@Vault) with the removed tokens.
//
// The function's access level is public, but this isn't a problem
// because even the public functions are not fully public at first.
// anyone in the network can call them, but only if the owner grants
// them access by publishing a resource that exposes the withdraw
// function.
// because even public functions are not fully accessible unless the owner
// grants access by publishing a resource that exposes the withdraw function.
//
pub fun withdraw(amount: UFix64): @Vault {
access(all)
fun withdraw(amount: UFix64): @Vault {
post {
// 'result' refers to the return value of the function
result.balance == UFix64(amount):
"Withdrawal amount must be the same as the balance of the withdrawn Vault"
"Withdrawal amount must match the balance of the withdrawn Vault"
}
}
}
}
46 changes: 23 additions & 23 deletions cadence/transaction.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ import ExampleToken from 0x01
// that owns a Vault
transaction {

// Temporary Vault object that holds the balance that is being transferred
var temporaryVault: @ExampleToken.Vault
// Temporary Vault object that holds the balance that is being transferred
var temporaryVault: @ExampleToken.Vault

prepare(acct: AuthAccount) {
// withdraw tokens from your vault by borrowing a reference to it
// and calling the withdraw function with that reference
let vaultRef = acct.borrow<&ExampleToken.Vault>(from: /storage/MainVault)
?? panic("Could not borrow a reference to the owner's vault")

self.temporaryVault <- vaultRef.withdraw(amount: 10.0)
}
prepare(acct: auth(Storage, Capabilities) &Account) {
// Withdraw tokens from your vault by borrowing a reference to it
// and calling the withdraw function with that reference
let vaultRef = acct.capabilities.storage.borrow<&ExampleToken.Vault>(
from: /storage/MainVault
) ?? panic("Could not borrow a reference to the owner's vault")

self.temporaryVault <- vaultRef.withdraw(amount: 10.0)
}

execute {
// get the recipient's public account object
let recipient = getAccount(0x01)
execute {
// Get the recipient's public account object
let recipient = getAccount(0x01)

// get the recipient's Receiver reference to their Vault
// by borrowing the reference from the public capability
let receiverRef = recipient.getCapability(/public/MainReceiver)
.borrow<&ExampleToken.Vault{ExampleToken.Receiver}>()
?? panic("Could not borrow a reference to the receiver")
// Get the recipient's Receiver reference to their Vault
// by borrowing the reference from the public capability
let receiverRef = recipient.capabilities.borrow<&ExampleToken.Vault{ExampleToken.Receiver}>(
/public/MainReceiver
) ?? panic("Could not borrow a reference to the receiver")

// deposit your tokens to their Vault
receiverRef.deposit(from: <-self.temporaryVault)
// Deposit your tokens to their Vault
receiverRef.deposit(from: <-self.temporaryVault)

log("Transfer succeeded!")
}
log("Transfer succeeded!")
}
}

16 changes: 16 additions & 0 deletions flow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"contracts": {
"Counter": {
"source": "cadence/contracts/Counter.cdc",
"aliases": {
"testing": "0000000000000007"
}
}
},
"networks": {
"emulator": "127.0.0.1:3569",
"mainnet": "access.mainnet.nodes.onflow.org:9000",
"testing": "127.0.0.1:3569",
"testnet": "access.devnet.nodes.onflow.org:9000"
}
}
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export const withdrawingTokens = {
transactionCode: transactionPath,
transactionExplanation: transactionExplanationPath,
filters: {
difficulty: "beginner"
}
difficulty: "beginner",
},
};
Loading