ChildBet Architecture

This transaction is responsible for associating a child bet with a parent bet using a unique bet UUID.

Inside the transaction's prepare block, the code performs the following actions:

  • It retrieves the parent bet resource using the provided bet UUID from the smart contract's storage.

  • A new child bet is created by invoking the createChildBet function on the parent bet resource, providing the child bet's name and available options.

  • The updated parent bet resource and the newly created child bet resource are stored back in the smart contract's storage.

  • A public link is established between the child bet's public path and its storage path to ensure accessibility.

By executing this transaction, users can create child bets associated with existing parent bets, allowing for the expansion of betting options within the FlowBetPalace application. The proper storage and linking of the child bet resource guarantee its availability and accessibility within the smart contract, ensuring accurate and secure bet management.

import FlowBetPalace from 0xd19f554fdb83f838

    transaction(betUuid: String,name:String,options: [String]) {

    prepare(acct: AuthAccount) {
        
        //set the StoragePath of the bet
        let betPath: StoragePath = StoragePath(identifier:"bet".concat(betUuid))!

        //get the resource
        let bet <- acct.load<@FlowBetPalace.Bet>(from: betPath) ?? panic("invalid bet uuid")

        //create the betChild
        let childBet <- bet.createChildBet(name:name,options:options,startDate:bet.startDate,endDate:bet.endDate,stopAcceptingBetsDate:bet.stopAcceptingBetsDate)

        //save back the resource
        acct.save(<-bet,to:betPath)

        //save the betChildResource
        let childBetPath: StoragePath = childBet.storagePath
        let childBetPublicPath: PublicPath = childBet.publicPath
        acct.save(<-childBet,to:childBetPath)

        //create a link to the storage path
        acct.link<&AnyResource{FlowBetPalace.ChildBetPublicInterface}>(childBetPublicPath,target:childBetPath)

        log("created a childBet, stored in storage and added a public link")
    }

    execute {
    }
    }

Last updated