This script returns cadence conversion from different types to bytes Currently AnyStruct is input arg is not allowed, hence wrapping it in optional
pub fun main(v: AnyStruct?): [UInt8] {
let value = v!;
switch value.getType(){
case Type<String>():
let temp = value as? String;
return temp!.utf8;
case Type<UInt64>():
let temp = value as? UInt64;
return temp!.toBigEndianBytes();
case Type<UFix64>():
let temp = value as? UFix64;
return temp!.toBigEndianBytes();
case Type<Address>():
let temp = value as? Address;
return temp!.toBytes();
default:
log("Type is not supported")
return []
}
}This gets the blocklist status of a resource If is it blocklisted, the block it happen will be returned If it is not blocklisted, nil will return
pub fun main(uuid: UInt64): UInt64? {
return FiatToken.getBlocklist(resourceId: uuid)
}This gets the managed Minter of a MinterController If non is set by the MasterMinter, nil will return
pub fun main(uuid: UInt64): UInt64? {
return FiatToken.getManagedMinter(resourceId: uuid)
}This gets the Minter's allowance set by a MinterController If non is set, this will return error
pub fun main(uuid: UInt64): UFix64 {
return FiatToken.getMinterAllowance(resourceId: uuid)!
}Gets the Token Name
pub fun main(): String{
return FiatToken.name
}Gets the pause state of the contract
pub fun main(): Bool {
return FiatToken.paused
}This script uses the resources PubSigner Public path to use the UUID function for uuid
Alternatively, if the resource owner do not want to link PubSigner path, they can simply link the ResourceId interfaces and this script should then use the UUIDPubPath, i.e. VaultUUIDPubPath
pub fun main(resourceAddr: Address, resourceName: String): UInt64 {
let resourceAcct = getAccount(resourceAddr)
var resourcePubPath: PublicPath = FiatToken.VaultPubSigner
switch resourceName {
case "Vault":
resourcePubPath = FiatToken.VaultPubSigner
case "Minter":
resourcePubPath = FiatToken.MinterPubSigner
case "MinterController":
resourcePubPath = FiatToken.MinterControllerPubSigner
case "MasterMinter":
resourcePubPath = FiatToken.MasterMinterPubSigner
case "Pauser":
resourcePubPath = FiatToken.PauserPubSigner
case "Blocklister":
resourcePubPath = FiatToken.BlocklisterPubSigner
default:
panic ("Resource not supported")
}
let ref = resourceAcct.getCapability(resourcePubPath)
.borrow<&{OnChainMultiSig.PublicSigner}>()
?? panic("Could not borrow Get UUID reference to the Resource")
return ref.UUID()
}This script reads the total supply field of the FiatToken smart contract
pub fun main(): UFix64 {
let supply = FiatToken.totalSupply
log(supply)
return supply
}This gets the current version of the contract
pub fun main(): String {
return FiatToken.version
}This script gets the weight of a stored public key in a multiSigManager for a resource
pub fun main(resourceAddr: Address, key: String, resourcePubSignerPath: PublicPath): UFix64 {
let resourceAcct = getAccount(resourceAddr)
let ref = resourceAcct.getCapability(resourcePubSignerPath)
.borrow<&{OnChainMultiSig.PublicSigner}>()
?? panic("Could not borrow Pub Signer reference to the Vault")
let attr = ref.getSignerKeyAttr(publicKey: key)!
return attr.weight
}This gets the pubsigner path for different resources
pub fun main(resourceName: String): PublicPath {
switch resourceName {
case "MasterMinter":
return FiatToken.MasterMinterPubSigner
case "Minter":
return FiatToken.MinterPubSigner
case "MinterController":
return FiatToken.MinterControllerPubSigner
case "Vault":
return FiatToken.VaultPubSigner
case "Pauser":
return FiatToken.PauserPubSigner
case "Blocklister":
return FiatToken.BlocklisterPubSigner
default:
panic("Resource not supported")
}
return FiatToken.VaultPubSigner
}This script gets all the stored public keys in a multiSigManager for a resource
pub fun main(resourceAddr: Address, resourcePubSignerPath: PublicPath): [String] {
let resourceAcct = getAccount(resourceAddr)
let ref = resourceAcct.getCapability(resourcePubSignerPath)
.borrow<&{OnChainMultiSig.PublicSigner}>()
?? panic("Could not borrow Pub Signer reference to the Vault")
return ref.getSignerKeys()
}This script gets the current TxIndex for payloads stored in multiSigManager in a resource The new payload must be this value + 1
pub fun main(resourceAddr: Address, resourcePubSignerPath: PublicPath): UInt64{
let resourcAcct = getAccount(resourceAddr)
let ref = resourcAcct.getCapability(resourcePubSignerPath)
.borrow<&{OnChainMultiSig.PublicSigner}>()
?? panic("Could not borrow Pub Signer reference to Resource")
return ref.getTxIndex()
}This script reads the allowance field set in a vault for another resource
pub fun main(fromAcct: Address, toResourceId: UInt64): UFix64 {
let acct = getAccount(fromAcct)
let vaultRef = acct.getCapability(FiatToken.VaultAllowancePubPath)
.borrow<&FiatToken.Vault{FiatTokenInterface.Allowance}>()
?? panic("Could not borrow Allowance reference to the Vault")
return vaultRef.allowance(resourceId: toResourceId)!
}This script reads the balance field of an account's FiatToken Balance
pub fun main(account: Address): UFix64 {
let acct = getAccount(account)
let vaultRef = acct.getCapability(FiatToken.VaultBalancePubPath)
.borrow<&FiatToken.Vault{FungibleToken.Balance}>()
?? panic("Could not borrow Balance reference to the Vault")
return vaultRef.balance
}