-
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.
update generic setup and transfer transactions
- Loading branch information
1 parent
320aa3c
commit 2ab8303
Showing
6 changed files
with
139 additions
and
36 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
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
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,37 @@ | ||
import FungibleToken from "FungibleToken" | ||
import FungibleTokenMetadataViews from "FungibleTokenMetadataViews" | ||
|
||
/// This transaction is what an account would run | ||
/// to set itself up to manage fungible tokens. This function | ||
/// uses views to know where to set up the vault | ||
/// in storage and to create the empty vault. | ||
transaction(contractAddress: Address, contractName: String) { | ||
|
||
prepare(signer: auth(SaveValue, Capabilities) &Account) { | ||
// Borrow a reference to the vault stored on the passed account at the passed publicPath | ||
let resolverRef = getAccount(contractAddress) | ||
.contracts.borrow<&FungibleToken>(name: contractName) | ||
?? panic("Could not borrow a reference to the fungible token contract") | ||
|
||
// Use that reference to retrieve the FTView | ||
let ftVaultData = resolverRef.resolveContractView(resourceType: nil, viewType: Type<FungibleTokenMetadataViews.FTVaultData>()) as! FungibleTokenMetadataViews.FTVaultData? | ||
?? panic("Could not resolve the FTVaultData view for the given Fungible token contract") | ||
|
||
// Create a new empty vault using the createEmptyVault function inside the FTVaultData | ||
let emptyVault <-ftVaultData.createEmptyVault() | ||
|
||
// Save it to the account | ||
signer.storage.save(<-emptyVault, to: ftVaultData.storagePath) | ||
|
||
// Create a public capability for the vault which includes the .Resolver interface | ||
let vaultCap = signer.capabilities.storage.issue<&{FungibleToken.Vault}>(ftVaultData.storagePath) | ||
signer.capabilities.publish(vaultCap, at: ftVaultData.metadataPath) | ||
|
||
// Create a public capability for the vault exposing the receiver interface | ||
let receiverCap = signer.capabilities.storage.issue<&{FungibleToken.Receiver}>(ftVaultData.storagePath) | ||
signer.capabilities.publish(receiverCap, at: ftVaultData.receiverPath) | ||
|
||
} | ||
} | ||
|