import "FungibleToken"
import "FlowToken"
import "Fixes"
import "FRC20Indexer"
import "FixesInscriptionFactory"
transaction(
tick: String,
amt: UFix64,
to: Address,
) {
let ins: auth(Fixes.Extractable) &Fixes.Inscription
prepare(acct: auth(Storage, Capabilities) &Account) {
/** ------------- Prepare the Inscription Store - Start ---------------- */
let storePath = Fixes.getFixesStoreStoragePath()
if acct.storage
.borrow<auth(Fixes.Manage) &Fixes.InscriptionsStore>(from: storePath) == nil {
acct.storage.save(<- Fixes.createInscriptionsStore(), to: storePath)
}
let store = acct.storage
.borrow<auth(Fixes.Manage) &Fixes.InscriptionsStore>(from: storePath)
?? panic("Could not borrow a reference to the Inscriptions Store!")
/** ------------- End -------------------------------------------------- */
// The Inscription's metadata
let dataStr = FixesInscriptionFactory.buildTransferFRC20(tick: tick, to: to, amt: amt)
// estimate the required storage
let estimatedReqValue = FixesInscriptionFactory.estimateFrc20InsribeCost(dataStr)
// Get a reference to the signer's stored vault
let vaultRef = acct.storage
.borrow<auth(FungibleToken.Withdraw) &FlowToken.Vault>(from: /storage/flowTokenVault)
?? panic("Could not borrow reference to the owner's Vault!")
// Withdraw tokens from the signer's stored vault
let flowToReserve <- vaultRef.withdraw(amount: estimatedReqValue)
// Create the Inscription first
let newInsId = FixesInscriptionFactory.createAndStoreFrc20Inscription(
dataStr,
<- (flowToReserve as! @FlowToken.Vault),
store
)
// borrow a reference to the new Inscription
self.ins = store.borrowInscriptionWritableRef(newInsId)
?? panic("Could not borrow reference to the new Inscription!")
}
execute {
let indexer = FRC20Indexer.getIndexer()
indexer.transfer(ins: self.ins)
}
}