diff --git a/.github/workflows/cadence_lint.yml b/.github/workflows/cadence_lint.yml new file mode 100644 index 0000000..58565d0 --- /dev/null +++ b/.github/workflows/cadence_lint.yml @@ -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 diff --git a/.github/workflows/cadence_tests.yml b/.github/workflows/cadence_tests.yml new file mode 100644 index 0000000..9a51f78 --- /dev/null +++ b/.github/workflows/cadence_tests.yml @@ -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 diff --git a/cadence/contract.cdc b/cadence/contract.cdc index b09d9c8..38f629f 100644 --- a/cadence/contract.cdc +++ b/cadence/contract.cdc @@ -1,4 +1,5 @@ -pub resource interface Provider { +access(all) +resource interface Provider { // withdraw // @@ -6,16 +7,15 @@ pub resource interface Provider { // 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" } } -} \ No newline at end of file +} diff --git a/cadence/transaction.cdc b/cadence/transaction.cdc index 04b521a..8d28d43 100644 --- a/cadence/transaction.cdc +++ b/cadence/transaction.cdc @@ -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!") + } } - diff --git a/flow.json b/flow.json new file mode 100644 index 0000000..e81ec35 --- /dev/null +++ b/flow.json @@ -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" + } +} \ No newline at end of file diff --git a/index.js b/index.js index 3f8c648..7981ee8 100644 --- a/index.js +++ b/index.js @@ -23,6 +23,6 @@ export const withdrawingTokens = { transactionCode: transactionPath, transactionExplanation: transactionExplanationPath, filters: { - difficulty: "beginner" - } + difficulty: "beginner", + }, };