-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add functions to reclaim leases and test
- Loading branch information
1 parent
fc1ea49
commit d40ff1b
Showing
6 changed files
with
116 additions
and
3 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
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,40 @@ | ||
import "FungibleToken" | ||
import "FlowToken" | ||
import "LockedTokens" | ||
|
||
transaction(amount: UFix64, to: Address) { | ||
|
||
// The Vault resource that holds the tokens that are being transferred | ||
let sentVault: @{FungibleToken.Vault} | ||
|
||
prepare(signer: auth(BorrowValue) &Account) { | ||
|
||
// Get a reference to the signer's locked token manager | ||
let tokenManagerRef = signer.storage.borrow<auth(FungibleToken.Withdraw, LockedTokens.RecoverLease) &LockedTokens.LockedTokenManager>(from: LockedTokens.LockedTokenManagerStoragePath) | ||
?? panic("The signer does not store a LockedTokenManager object at the path " | ||
.concat(LockedTokens.LockedTokenManagerStoragePath.toString())) | ||
|
||
let nodeRef = tokenManagerRef.borrowNodeForLease() | ||
?? panic("Could not borrow a reference to a node in the LockedTokenManager of the signer's account") | ||
|
||
// Withdraw enough tokens to pay for fees, assuming there are some rewards in the rewards bucket | ||
tokenManagerRef.deposit(from: <-nodeRef.withdrawRewardedTokens(amount: 0.0001)!) | ||
|
||
// Withdraw tokens from the signer's stored vault | ||
self.sentVault <- nodeRef.withdrawUnstakedTokens(amount: amount)! | ||
} | ||
|
||
execute { | ||
|
||
// Get a reference to the recipient's Receiver | ||
let receiverRef = getAccount(to) | ||
.capabilities.borrow<&{FungibleToken.Receiver}>(/public/flowTokenReceiver) | ||
?? panic("Could not borrow a Receiver reference to the FlowToken Vault in account " | ||
.concat(to.toString()).concat(" at path /public/flowTokenReceiver") | ||
.concat(". Make sure you are sending to an address that has ") | ||
.concat("a FlowToken Vault set up properly at the specified path.")) | ||
|
||
// Deposit the withdrawn tokens in the recipient's receiver | ||
receiverRef.deposit(from: <-self.sentVault) | ||
} | ||
} |