Skip to content

Commit

Permalink
add comments to token query
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Jun 7, 2024
1 parent f3538cf commit ba7e726
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cadence/scripts/tokens/get_all_vault_info_from_storage.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ import "FlowToken"
import "MetadataViews"
import "FungibleTokenMetadataViews"

/// Custom struct to store Fungible Token vault info
access(all)
struct FTVaultInfo {
/// The name of the Fungible Token
access(all) let name: String
/// The symbol of the Fungible Token
access(all) let symbol: String
/// The balance of the Fungible Token
access(all) var balance: UFix64
/// The address of the Fungible Token contract
access(all) let tokenContractAddress: Address
/// The name of the Fungible Token contract
access(all) let tokenContractName: String
/// The storage path of the Fungible Token vault
access(all) let storagePath: StoragePath
/// The receiver path of the Fungible Token vault
access(all) let receiverPath: PublicPath

init(
Expand All @@ -31,11 +39,21 @@ struct FTVaultInfo {
self.receiverPath = receiverPath
}

/// Updates the balance of the Fungible Token vault
access(all) fun updateBalance(delta: UFix64) {
self.balance = self.balance + delta
}
}

/// Returns a FTVaultInfo struct with the provided data
///
/// @param vaultType: The type of the Fungible Token vault
/// @param balance: The balance of the Fungible Token vault
/// @param display: The FTDisplay view of the Fungible Token vault
/// @param data: The FTVaultData view of the Fungible Token vault
///
/// @return FTVaultInfo: The FTVaultInfo struct with the provided data
///
access(all)
fun getVaultInfo(
vaultType: Type,
Expand All @@ -59,6 +77,11 @@ fun getVaultInfo(
)
}

/// Returns a mapping of all Fungible Token vaults stored in the account's storage indexed by their type
///
/// @param address: The address of the account to query
///
/// @return {Type: FTVaultInfo}: A mapping of vault types to their respective info
access(all)
fun main(address: Address): {Type: FTVaultInfo} {
let acct = getAuthAccount<auth(BorrowValue) &Account>(address)
Expand Down
8 changes: 8 additions & 0 deletions cadence/scripts/utils/get_evm_address_from_hex.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import "EVM"

import "EVMUtils"

access(all)
fun main(hex: String): EVM.EVMAddress? {
return EVMUtils.getEVMAddressFromHexString(address: hex)
}

0 comments on commit ba7e726

Please sign in to comment.