Bet Architecture
This transaction is responsible for setting up a bet with various attributes such as its name, start date, end date, description, image link, category, and the date when accepting bets stops.
Within the prepare
block of the transaction, the code performs the following steps:
It retrieves the admin resource's reference by borrowing the admin capability from the authenticated account.
A new bet is created by invoking the
createBet
function on the admin resource, passing the specified attributes for the bet.The newly created bet resource is stored in the smart contract's storage using its storage path.
A public link is established between the bet's public path and its storage path to ensure access to the bet from other accounts.
By executing this transaction, users with the necessary authorization can create new bets within the FlowBetPalace application. The code ensures the proper storage of the bet resource and establishes a public link for easy access by other accounts.
import FlowBetPalace from 0xd19f554fdb83f838
transaction(name: String, startDate: UFix64, endDate: UFix64, description: String, imagelink: String, category: String, stopAcceptingBetsDate: UFix64) {
prepare(acct: AuthAccount) {
// Retrieve admin Reference of the admin resource
var acctAdminCapability = acct.getCapability(FlowBetPalace.adminPublicPath)
var acctAdminRef = acctAdminCapability.borrow<&AnyResource{FlowBetPalace.AdminInterface}>() ?? panic("Could not borrow admin reference")
// create the new bet
let newBet <- acctAdminRef.createBet(name: name, description: description, imageLink: imagelink,category: category,startDate: startDate ,endDate: endDate,stopAcceptingBetsDate:stopAcceptingBetsDate)
//get the bet storage path
let betStoragePath = newBet.storagePath
let betPublicPath = newBet.publicPath
//store the newBet to storage
// /storage/"bet"+bet.uuid.toString()
acct.save(<- newBet, to: betStoragePath)
//create a public link for access the bet
acct.link<&AnyResource{FlowBetPalace.BetPublicInterface}>(betPublicPath,target:betStoragePath)
log("bet saved correctly in account storage")
}
execute {
}
}
Last updated