-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create new branch as #125 get corrupted
- Loading branch information
1 parent
fae3075
commit ed4f379
Showing
11 changed files
with
254 additions
and
4 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
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 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 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 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 FungibleToken from "../../../../../contracts/FungibleToken.cdc" | ||
import ExampleToken from "../../../../../contracts/ExampleToken.cdc" | ||
import FungibleTokenSwitchboard from "../../../../../contracts/FungibleTokenSwitchboard.cdc" | ||
|
||
transaction() { | ||
|
||
prepare(signer: AuthAccount) { | ||
|
||
signer.unlink(FungibleTokenSwitchboard.ReceiverPublicPath) | ||
|
||
// Create a public capability to the Vault that only exposes | ||
// the deposit function through the Receiver interface | ||
signer.link<&ExampleToken.Vault{FungibleToken.Receiver}>( | ||
ExampleToken.ReceiverPublicPath, | ||
target: ExampleToken.VaultStoragePath | ||
) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
lib/js/test/mocks/transactions/setup_infinite_loop_capability.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 FungibleToken from "../../../../../contracts/FungibleToken.cdc" | ||
import ExampleToken from "../../../../../contracts/ExampleToken.cdc" | ||
import FungibleTokenSwitchboard from "../../../../../contracts/FungibleTokenSwitchboard.cdc" | ||
|
||
transaction() { | ||
|
||
prepare(signer: AuthAccount) { | ||
|
||
signer.unlink(ExampleToken.ReceiverPublicPath) | ||
|
||
// Create a public capability to the Vault that only exposes | ||
// the deposit function through the Receiver interface | ||
signer.link<&ExampleToken.Vault{FungibleToken.Receiver}>( | ||
FungibleTokenSwitchboard.ReceiverPublicPath, | ||
target: ExampleToken.VaultStoragePath | ||
) | ||
} | ||
} |
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 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
10 changes: 10 additions & 0 deletions
10
transactions/scripts/switchboard/check_receiver_by_type.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,10 @@ | ||
import FungibleTokenSwitchboard from "../../../contracts/FungibleTokenSwitchboard.cdc" | ||
import ExampleToken from "../../../contracts/ExampleToken.cdc" | ||
|
||
pub fun main(switchboard: Address): Bool { | ||
let switchboardRef = getAccount(switchboard) | ||
.getCapability<&{FungibleTokenSwitchboard.SwitchboardPublic}>(FungibleTokenSwitchboard.PublicPath) | ||
.borrow() | ||
?? panic("Unable to borrow capability with restricted type of {FungibleTokenSwitchboard.SwitchboardPublic} from ".concat(switchboard.toString()).concat( "account")) | ||
return switchboardRef.checkReceiverByType(type: Type<@ExampleToken.Vault>()) | ||
} |
10 changes: 10 additions & 0 deletions
10
transactions/scripts/tokenForwarder/is_recipient_valid.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,10 @@ | ||
import TokenForwarding from "../../../contracts/utility/TokenForwarding.cdc" | ||
|
||
pub fun main(addr: Address, tokenForwardingPath: PublicPath): Bool { | ||
let forwarderRef = getAccount(addr) | ||
.getCapability<&{TokenForwarding.ForwarderPublic}>(tokenForwardingPath) | ||
.borrow() | ||
?? panic("Unable to borrow {TokenForwarding.ForwarderPublic} restrict type from a capability") | ||
|
||
return forwarderRef.check() | ||
} |
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,45 @@ | ||
import FungibleToken from "./../../contracts/FungibleToken.cdc" | ||
import FungibleTokenSwitchboard from "./../../contracts/FungibleTokenSwitchboard.cdc" | ||
import ExampleToken from "./../../contracts/ExampleToken.cdc" | ||
|
||
// This transaction is a template for a transaction that could be used by anyone | ||
// to send tokens to another account through a switchboard using the deposit | ||
// method but before depositing we will explicitly check whether receiving capability is | ||
// borrowable or not and if yes then it will deposit the vault to the receiver capability. | ||
transaction(to: Address, amount: UFix64) { | ||
|
||
// The reference to the vault from the payer's account | ||
let vaultRef: &ExampleToken.Vault | ||
// The Vault resource that holds the tokens that are being transferred | ||
let sentVault: @FungibleToken.Vault | ||
|
||
prepare(signer: AuthAccount) { | ||
|
||
// Get a reference to the signer's stored vault | ||
self.vaultRef = signer.borrow<&ExampleToken.Vault>(from: ExampleToken.VaultStoragePath) | ||
?? panic("Could not borrow reference to the owner's Vault!") | ||
|
||
// Withdraw tokens from the signer's stored vault | ||
self.sentVault <-self.vaultRef.withdraw(amount: amount) | ||
|
||
} | ||
|
||
execute { | ||
|
||
// Get the recipient's public account object | ||
let recipient = getAccount(to) | ||
|
||
// Get a reference to the recipient's Switchboard Receiver | ||
let switchboardRef = recipient.getCapability(FungibleTokenSwitchboard.PublicPath) | ||
.borrow<&FungibleTokenSwitchboard.Switchboard{FungibleTokenSwitchboard.SwitchboardPublic}>() | ||
?? panic("Could not borrow receiver reference to switchboard!") | ||
|
||
// Validate the receiving capability by using safeBorrowByType | ||
if let receivingRef = switchboardRef.safeBorrowByType(type: Type<@ExampleToken.Vault>()){ | ||
switchboardRef.deposit(from: <-self.sentVault) | ||
} else { | ||
destroy self.sentVault | ||
} | ||
} | ||
|
||
} |