Skip to content

Commit

Permalink
address PR comments with small formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahannan committed Sep 24, 2024
1 parent ab58bbf commit 65c59eb
Show file tree
Hide file tree
Showing 30 changed files with 151 additions and 145 deletions.
32 changes: 16 additions & 16 deletions contracts/FungibleToken.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ access(all) contract interface FungibleToken: ViewResolver {
}
post {
self.balance == 0.0:
"FungibleToken.Vault.burnCallback: Cannot burn this Vault with Burner.burn()."
.concat("The balance must be set to zero during the burnCallback method so that it cannot be spammed")
"FungibleToken.Vault.burnCallback: Cannot burn this Vault with Burner.burn(). "
.concat("The balance must be set to zero during the burnCallback method so that it cannot be spammed.")
}
self.balance = 0.0
}
Expand Down Expand Up @@ -223,21 +223,21 @@ access(all) contract interface FungibleToken: ViewResolver {
}
post {
result.getType() == self.getType():
"FungibleToken.Vault.withdraw: Cannot withdraw tokens!"
"FungibleToken.Vault.withdraw: Cannot withdraw tokens! "
.concat("The withdraw method tried to return an incompatible Vault type <")
.concat(result.getType().identifier).concat(">. ")
.concat("It must return a Vault with the same type as self (")
.concat("It must return a Vault with the same type as self <")
.concat(self.getType().identifier).concat(">.")

// use the special function `before` to get the value of the `balance` field
// at the beginning of the function execution
//
self.balance == before(self.balance) - amount:
"FungibleToken.Vault.withdraw: Cannot withdraw tokens!"
"FungibleToken.Vault.withdraw: Cannot withdraw tokens! "
.concat("The sender's balance after the withdrawal (")
.concat(self.balance.toString())
.concat(") must be the difference of the previous balance (").concat(before(self.balance.toString()))
.concat(") and the amount withdrawn (").concat(amount.toString())
.concat(") and the amount withdrawn (").concat(amount.toString()).concat(")")

emit Withdrawn(
type: result.getType().identifier,
Expand All @@ -257,12 +257,12 @@ access(all) contract interface FungibleToken: ViewResolver {
// as the vault that is accepting the deposit
pre {
from.isInstance(self.getType()):
"FungibleToken.Vault.deposit: Cannot deposit tokens!"
"FungibleToken.Vault.deposit: Cannot deposit tokens! "
.concat("The type of the deposited tokens <")
.concat(from.getType().identifier)
.concat("> has to be the same type as the Vault being deposited into <")
.concat(self.getType().identifier)
.concat(">. Check that you are withdrawing and depositing to the correct paths in the sender and receiver accounts")
.concat(">. Check that you are withdrawing and depositing to the correct paths in the sender and receiver accounts ")
.concat("and that those paths hold the same Vault types.")
}
post {
Expand All @@ -275,11 +275,11 @@ access(all) contract interface FungibleToken: ViewResolver {
balanceAfter: self.balance
)
self.balance == before(self.balance) + before(from.balance):
"FungibleToken.Vault.deposit: Cannot deposit tokens!"
"FungibleToken.Vault.deposit: Cannot deposit tokens! "
.concat("The receiver's balance after the deposit (")
.concat(self.balance.toString())
.concat(") must be the sum of the previous balance (").concat(before(self.balance.toString()))
.concat(") and the amount deposited (").concat(before(from.balance).toString())
.concat(") and the amount deposited (").concat(before(from.balance).toString()).concat(")")
}
}

Expand All @@ -289,12 +289,12 @@ access(all) contract interface FungibleToken: ViewResolver {
access(all) fun createEmptyVault(): @{Vault} {
post {
result.balance == 0.0:
"FungibleToken.Vault.createEmptyVault: Empty Vault creation failed!"
"FungibleToken.Vault.createEmptyVault: Empty Vault creation failed! "
.concat("The newly created Vault must have zero balance but it has a balance of ")
.concat(result.balance.toString())

result.getType() == self.getType():
"FungibleToken.Vault.createEmptyVault: Empty Vault creation failed!"
"FungibleToken.Vault.createEmptyVault: Empty Vault creation failed! "
.concat("The type of the new Vault <")
.concat(result.getType().identifier)
.concat("> has to be the same type as the Vault that created it <")
Expand All @@ -310,12 +310,12 @@ access(all) contract interface FungibleToken: ViewResolver {
access(all) fun createEmptyVault(vaultType: Type): @{FungibleToken.Vault} {
post {
result.balance == 0.0:
"FungibleToken.createEmptyVault: Empty Vault creation failed!"
.concat("The newly created Vault must have zero balance but it has a balance of ")
.concat(result.balance.toString())
"FungibleToken.createEmptyVault: Empty Vault creation failed! "
.concat("The newly created Vault must have zero balance but it has a balance of (")
.concat(result.balance.toString()).concat(")")

result.getType() == vaultType:
"FungibleToken.Vault.createEmptyVault: Empty Vault creation failed!"
"FungibleToken.Vault.createEmptyVault: Empty Vault creation failed! "
.concat("The type of the new Vault <")
.concat(result.getType().identifier)
.concat("> has to be the same as the type that was requested <")
Expand Down
23 changes: 14 additions & 9 deletions contracts/FungibleTokenSwitchboard.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ access(all) contract FungibleTokenSwitchboard {
// Borrow a reference to the vault pointed to by the capability we
// want to store inside the switchboard
let vaultRef = capability.borrow()
?? panic("FungibleTokenSwitchboard.Switchboard.addNewVault: Cannot borrow reference to vault from capability"
.concat("Make sure that the capability path points to a Vault that has been properly initialized"))
?? panic("FungibleTokenSwitchboard.Switchboard.addNewVault: Cannot borrow reference to vault from capability! "
.concat("Make sure that the capability path points to a Vault that has been properly initialized. "))

// Check if there is a previous capability for this token, if not
// Check if there is a previous capability for this token
if (self.receiverCapabilities[vaultRef.getType()] == nil) {
// use the vault reference type as key for storing the
// capability and then
Expand All @@ -80,6 +80,11 @@ access(all) contract FungibleTokenSwitchboard {
emit VaultCapabilityAdded(type: vaultRef.getType(),
switchboardOwner: self.owner?.address,
capabilityOwner: capability.address)
} else {
// If there was already a capability for that token, panic
panic("FungibleTokenSwitchboard.Switchboard.addNewVault: Cannot add new Vault capability! "
.concat("There is already a vault in the Switchboard for this type <")
.concat(vaultRef.getType().identifier).concat(">."))
}
}

Expand Down Expand Up @@ -137,8 +142,8 @@ access(all) contract FungibleTokenSwitchboard {
assert (
capability.check(),
message:
"FungibleTokenSwitchboard.Switchboard.addNewVaultWrapper: Cannot borrow reference to a vault from the provided capability"
.concat("Make sure that the capability path points to a Vault that has been properly initialized")
"FungibleTokenSwitchboard.Switchboard.addNewVaultWrapper: Cannot borrow reference to a vault from the provided capability! "
.concat("Make sure that the capability path points to a Vault that has been properly initialized.")
)
// Use the type parameter as key for the capability
self.receiverCapabilities[type] = capability
Expand Down Expand Up @@ -196,8 +201,8 @@ access(all) contract FungibleTokenSwitchboard {
// Borrow a reference to the vault pointed to by the capability we
// want to remove from the switchboard
let vaultRef = capability.borrow()
?? panic ("FungibleTokenSwitchboard.Switchboard.addNewVaultWrapper: Cannot borrow reference to a vault from the provided capability"
.concat("Make sure that the capability path points to a Vault that has been properly initialized"))
?? panic ("FungibleTokenSwitchboard.Switchboard.addNewVaultWrapper: Cannot borrow reference to a vault from the provided capability! "
.concat("Make sure that the capability path points to a Vault that has been properly initialized."))

// Use the vault reference to find the capability to remove
self.receiverCapabilities.remove(key: vaultRef.getType())
Expand Down Expand Up @@ -225,9 +230,9 @@ access(all) contract FungibleTokenSwitchboard {

// Borrow the reference to the desired vault
let vaultRef = depositedVaultCapability.borrow()
?? panic ("FungibleTokenSwitchboard.Switchboard.deposit: Cannot borrow reference to a vault"
?? panic ("FungibleTokenSwitchboard.Switchboard.deposit: Cannot borrow reference to a vault "
.concat("from the type of the deposited Vault <").concat(from.getType().identifier)
.concat(">. Make sure that the capability path points to a Vault that has been properly initialized"))
.concat(">. Make sure that the capability path points to a Vault that has been properly initialized."))

vaultRef.deposit(from: <-from)
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/utility/PrivateReceiverForwarder.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ access(all) contract PrivateReceiverForwarder {
init(recipient: Capability<&{FungibleToken.Receiver}>) {
pre {
recipient.borrow() != nil:
"PrivateReceiverForwarder.Forwarder.init: Could not borrow a Receiver reference from the recipient Capability."
.concat("The recipient needs to have the correct Fungible Token Vault initialized in their account with a public Receiver Capability")
"PrivateReceiverForwarder.Forwarder.init: Could not borrow a Receiver reference from the recipient Capability. "
.concat("The recipient needs to have the correct Fungible Token Vault initialized in their account with a public Receiver Capability.")
}
self.recipient = recipient
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/utility/TokenForwarding.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ access(all) contract TokenForwarding {
"TokenForwarding.Forwarder.changeRecipient: Could not borrow a Receiver reference from the new Capability. "
.concat("This is likely because the recipient account ")
.concat(newRecipient.address.toString())
.concat(" has not set up the FungibleToken Vault or public capability correctly.")
.concat("Verify that the address is correct and the account has the correct Vault and capability")
.concat(" has not set up the FungibleToken Vault or public capability correctly. ")
.concat("Verify that the address is correct and the account has the correct Vault and capability.")
}
let newRef = newRecipient.borrow<&{FungibleToken.Receiver}>()!
let oldRef = self.recipient.borrow<&{FungibleToken.Receiver}>()!
Expand Down Expand Up @@ -127,8 +127,8 @@ access(all) contract TokenForwarding {
"TokenForwarding.Forwarder.changeRecipient: Could not borrow a Receiver reference from the Capability. "
.concat("This is likely because the recipient account ")
.concat(recipient.address.toString())
.concat(" has not set up the FungibleToken Vault or public capability correctly.")
.concat("Verify that the address is correct and the account has the correct Vault and capability")
.concat(" has not set up the FungibleToken Vault or public capability correctly. ")
.concat("Verify that the address is correct and the account has the correct Vault and capability. ")
}
self.recipient = recipient
}
Expand Down
Loading

0 comments on commit 65c59eb

Please sign in to comment.