-
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.
* updating dependencies and mint tokens script * first draft of private forwarding * tests for forwarding
- Loading branch information
1 parent
3d12094
commit 32371bd
Showing
17 changed files
with
834 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
# Fungible Token Private Receiver Contract | ||
This contract implements a special resource and receiver interface | ||
whose deposit function is only callable by an admin through a public capability. | ||
*/ | ||
|
||
import FungibleToken from 0xFUNGIBLETOKENADDRESS | ||
|
||
pub contract PrivateReceiverForwarder { | ||
|
||
// Event that is emitted when tokens are deposited to the target receiver | ||
pub event PrivateDeposit(amount: UFix64, to: Address?) | ||
|
||
pub let SenderStoragePath: StoragePath | ||
|
||
pub let PrivateReceiverStoragePath: StoragePath | ||
pub let PrivateReceiverPublicPath: PublicPath | ||
|
||
pub resource Forwarder { | ||
|
||
// This is where the deposited tokens will be sent. | ||
// The type indicates that it is a reference to a receiver | ||
// | ||
access(self) var recipient: Capability<&{FungibleToken.Receiver}> | ||
|
||
// deposit | ||
// | ||
// Function that takes a Vault object as an argument and forwards | ||
// it to the recipient's Vault using the stored reference | ||
// | ||
access(contract) fun deposit(from: @FungibleToken.Vault) { | ||
let receiverRef = self.recipient.borrow()! | ||
|
||
let balance = from.balance | ||
|
||
receiverRef.deposit(from: <-from) | ||
|
||
emit PrivateDeposit(amount: balance, to: self.owner?.address) | ||
} | ||
|
||
init(recipient: Capability<&{FungibleToken.Receiver}>) { | ||
pre { | ||
recipient.borrow() != nil: "Could not borrow Receiver reference from the Capability" | ||
} | ||
self.recipient = recipient | ||
} | ||
} | ||
|
||
// createNewForwarder creates a new Forwarder reference with the provided recipient | ||
// | ||
pub fun createNewForwarder(recipient: Capability<&{FungibleToken.Receiver}>): @Forwarder { | ||
return <-create Forwarder(recipient: recipient) | ||
} | ||
|
||
|
||
pub resource Sender { | ||
pub fun sendPrivateTokens(_ address: Address, tokens: @FungibleToken.Vault) { | ||
|
||
let account = getAccount(address) | ||
|
||
let privateReceiver = account.getCapability<&PrivateReceiverForwarder.Forwarder>(PrivateReceiverForwarder.PrivateReceiverPublicPath) | ||
.borrow() ?? panic("Could not borrow reference to private forwarder") | ||
|
||
privateReceiver.deposit(from: <-tokens) | ||
|
||
} | ||
} | ||
|
||
init(senderPath: StoragePath, storagePath: StoragePath, publicPath: PublicPath) { | ||
|
||
self.SenderStoragePath = senderPath | ||
|
||
self.PrivateReceiverStoragePath = storagePath | ||
self.PrivateReceiverPublicPath = publicPath | ||
|
||
self.account.save(<-create Sender(), to: self.SenderStoragePath) | ||
|
||
} | ||
} |
File renamed without changes.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.