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

Adds entitlement to TokenForwarding #163

Merged
merged 1 commit into from
May 30, 2024
Merged
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
14 changes: 11 additions & 3 deletions contracts/utility/TokenForwarding.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ import "FungibleToken"

access(all) contract TokenForwarding {

access(all) entitlement Owner

// Event that is emitted when tokens are deposited to the target receiver
access(all) event ForwardedDeposit(amount: UFix64, depositedUUID: UInt64, from: Address?, to: Address?, toUUID: UInt64, depositedType: Type)
access(all) event ForwardedDeposit(amount: UFix64, depositedUUID: UInt64, from: Address?, to: Address?, toUUID: UInt64, depositedType: String)

// Event that is emitted when the recipient of a forwarder has changed
access(all) event ForwarderRecipientUpdated(owner: Address?, oldRecipient: Address?, newRecipient: Address?, newReceiverType: String, newReceiverUUID: UInt64)

access(all) resource interface ForwarderPublic {

Expand Down Expand Up @@ -55,7 +60,7 @@ access(all) contract TokenForwarding {

let uuid = from.uuid

emit ForwardedDeposit(amount: balance, depositedUUID: uuid, from: self.owner?.address, to: receiverRef.owner?.address, toUUID: receiverRef.uuid, depositedType: from.getType())
emit ForwardedDeposit(amount: balance, depositedUUID: uuid, from: self.owner?.address, to: receiverRef.owner?.address, toUUID: receiverRef.uuid, depositedType: from.getType().identifier)

receiverRef.deposit(from: <-from)
}
Expand All @@ -78,10 +83,13 @@ access(all) contract TokenForwarding {

// changeRecipient changes the recipient of the forwarder to the provided recipient
//
access(all) fun changeRecipient(_ newRecipient: Capability) {
access(Owner) fun changeRecipient(_ newRecipient: Capability) {
pre {
newRecipient.borrow<&{FungibleToken.Receiver}>() != nil: "Could not borrow Receiver reference from the Capability"
}
let newRef = newRecipient.borrow<&{FungibleToken.Receiver}>()!
let oldRef = self.recipient.borrow<&{FungibleToken.Receiver}>()!
emit ForwarderRecipientUpdated(owner: self.owner?.address, oldRecipient: oldRef.owner?.address, newRecipient: newRef.owner?.address, newReceiverType: newRef.getType().identifier, newReceiverUUID: newRef.uuid)
self.recipient = newRecipient
}

Expand Down
6 changes: 3 additions & 3 deletions lib/go/contracts/internal/assets/assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading