-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add collection & vault configuration scripts
- Loading branch information
1 parent
e41d781
commit fac0e0f
Showing
2 changed files
with
60 additions
and
0 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,30 @@ | ||
import "NonFungibleToken" | ||
import "MetadataViews" | ||
import "ViewResolver" | ||
|
||
import "FlowEVMBridgeUtils" | ||
|
||
/// Returns true if the recipient has Collection configured for the provided NFT contract | ||
/// | ||
/// @param nftIdentifier The type identifier of the NFT Collection to check for | ||
/// @param recipient The address of the recipient | ||
/// | ||
/// @returns true if the recipient has Collection configured for the provided NFT contract, false if not. Reverts if the | ||
/// provided contract cannot be accessed or does not have default Collection storage information. | ||
/// | ||
access(all) | ||
fun main(nftIdentifier: String, recipient: Address): Bool { | ||
let nftType = CompositeType(nftIdentifier) ?? panic("Invalid nft identifier: ".concat(nftIdentifier)) | ||
let contractAddress = FlowEVMBridgeUtils.getContractAddress(fromType: nftType) | ||
?? panic("Could not find contract address for nft: ".concat(nftIdentifier)) | ||
let contractName = FlowEVMBridgeUtils.getContractName(fromType: nftType) | ||
?? panic("Could not find contract name for nft: ".concat(nftIdentifier)) | ||
let nftContract = getAccount(contractAddress).contracts.borrow<&{NonFungibleToken}>(name: contractName) | ||
?? panic("No such contract found") | ||
let collectionData = nftContract.resolveContractView( | ||
resourceType: nftType, | ||
viewType: Type<MetadataViews.NFTCollectionData>() | ||
) as! MetadataViews.NFTCollectionData? | ||
?? panic("FungibleToken does not provide default Collection data") | ||
return getAccount(recipient).capabilities.exists(collectionData.publicPath) | ||
} |
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,30 @@ | ||
import "FungibleToken" | ||
import "FungibleTokenMetadataViews" | ||
import "ViewResolver" | ||
|
||
import "FlowEVMBridgeUtils" | ||
|
||
/// Returns true if the recipient has Vault configured for the provided FungibleToken contract | ||
/// | ||
/// @param vaultIdentifier The type identifier of the Vault to check for | ||
/// @param recipient The address of the recipient | ||
/// | ||
/// @returns true if the recipient has Vault configured for the provided FungibleToken contract, false if not. Reverts | ||
/// if the provided contract cannot be accessed or does not have default Vault storage information. | ||
/// | ||
access(all) | ||
fun main(vaultIdentifier: String, recipient: Address): Bool { | ||
let vaultType = CompositeType(vaultIdentifier) ?? panic("Invalid vault identifier: ".concat(vaultIdentifier)) | ||
let contractAddress = FlowEVMBridgeUtils.getContractAddress(fromType: vaultType) | ||
?? panic("Could not find contract address for vault: ".concat(vaultIdentifier)) | ||
let contractName = FlowEVMBridgeUtils.getContractName(fromType: vaultType) | ||
?? panic("Could not find contract name for vault: ".concat(vaultIdentifier)) | ||
let tokenContract = getAccount(contractAddress).contracts.borrow<&{FungibleToken}>(name: contractName) | ||
?? panic("No such contract found") | ||
let vaultData = tokenContract.resolveContractView( | ||
resourceType: vaultType, | ||
viewType: Type<FungibleTokenMetadataViews.FTVaultData>() | ||
) as! FungibleTokenMetadataViews.FTVaultData? | ||
?? panic("FungibleToken does not provide default Vault data") | ||
return getAccount(recipient).capabilities.exists(vaultData.receiverPath) | ||
} |