pub fn func_place_bet(ctx: &ScFuncContext, f: &PlaceBetContext) {

    // Since we are sure that the 'number' parameter actually exists we can
    // retrieve its actual value into an i64.
    let number: i64 = f.params.number().value();

    // Require that the number is a valid number to bet on, otherwise panic out.
    ctx.require(number >= 1 && number <= MAX_NUMBER, "invalid number");

    // Create ScBalances proxy to the incoming balances for this request.
    // Note that ScBalances wraps an ScImmutableMap of token color/amount combinations
    // in a simpler to use interface.
    let incoming: ScBalances = ctx.incoming();

    // Retrieve the amount of plain iota tokens that are part of the incoming balance.
    let amount: i64 = incoming.balance(&ScColor::IOTA);

    // Require that there are actually some plain iotas there
    ctx.require(amount > 0, "empty bet");

    // Now we gather all information together into a single serializable struct
    // Note that we use the caller() method of the function context to determine
    // the agent id of the better. This is where a potential pay-out will be sent.
    let bet = Bet {
        better: ctx.caller(),
        amount: amount,
        number: number,
    };

    // Get the array of current bets from state storage.
    let bets: ArrayOfMutableBet = f.state.bets();

    // Determine what the next bet number is by retrieving the length of the bets array.
    let bet_nr: i32 = bets.length();

    // Append the bet data to the bets array. The bet array will automatically take care
    // of serializing the bet struct into a bytes representation.
    bets.get_bet(bet_nr).set_value(&bet);

    // Was this the first bet of this round?
    if bet_nr == 0 {
        // Yes it was, query the state for the length of the playing period in seconds by
        // retrieving the playPeriod value from state storage
        let mut play_period: i32 = f.state.play_period().value();

        // if the play period is less than 10 seconds we override it with the default duration.
        // Note that this will also happen when the play period was not set yet because in that
        // case a zero value was returned.
        if play_period < 10 {
            play_period = DEFAULT_PLAY_PERIOD;
        }

        // And now for our next trick we post a delayed request to ourselves on the Tangle.
        // We are requesting to call the 'lockBets' function, but delay it for the play_period
        // amount of seconds. This will lock in the playing period, during which more bets can
        // be placed. Once the 'lockBets' function gets triggered by the ISCP it will gather all
        // bets up to that moment as the ones to consider for determining the winner.
        ScFuncs::lock_bets(ctx).func.delay(play_period).transfer_iotas(1).post();
    }
}
// 'placeBet' is used by betters to place a bet on a number from 1 to MAX_NUMBER. The first
// incoming bet triggers a betting round of configurable duration. After the playing period
// expires the smart contract will automatically pay out any winners and start a new betting
// round upon arrival of a new bet.
// The 'placeBet' function takes 1 mandatory parameter:
// - 'number', which must be an Int64 number from 1 to MAX_NUMBER
// The 'member' function will save the number together with the address of the better and
// the amount of incoming iotas as the bet amount in its state.
'placeBet' is used by betters to place a bet on a number from 1 to MAX_NUMBER. The first
incoming bet triggers a betting round of configurable duration. After the playing period
expires the smart contract will automatically pay out any winners and start a new betting
round upon arrival of a new bet.
' placeBet ' is used by betters to place a bet on a number from 1 to MAX_NUMBER . The first incoming bet triggers a betting round of configurable duration . After the playing period expires the smart contract will automatically pay out any winners and start a new betting round upon arrival of a new bet .
pub fn func_place_bet(ctx: &ScFuncContext, f: &PlaceBetContext) {
    // Since we are sure that the 'number' parameter actually exists we can
    // retrieve its actual value into an i64.
    let number: i64 = f.params.number().value();
    // Require that the number is a valid number to bet on, otherwise panic out.
    ctx.require(number >= 1 && number <= MAX_NUMBER, "invalid number");
    // Create ScBalances proxy to the incoming balances for this request.
    // Note that ScBalances wraps an ScImmutableMap of token color/amount combinations
    // in a simpler to use interface.
    let incoming: ScBalances = ctx.incoming();
    // Retrieve the amount of plain iota tokens that are part of the incoming balance.
    let amount: i64 = incoming.balance(&ScColor::IOTA);
    // Require that there are actually some plain iotas there
    ctx.require(amount > 0, "empty bet");
    // Now we gather all information together into a single serializable struct
    // Note that we use the caller() method of the function context to determine
    // the agent id of the better. This is where a potential pay-out will be sent.
    let bet = Bet {
        better: ctx.caller(),
        amount: amount,
        number: number,
    };
    // Get the array of current bets from state storage.
    let bets: ArrayOfMutableBet = f.state.bets();
    // Determine what the next bet number is by retrieving the length of the bets array.
    let bet_nr: i32 = bets.length();
    // Append the bet data to the bets array. The bet array will automatically take care
    // of serializing the bet struct into a bytes representation.
    bets.get_bet(bet_nr).set_value(&bet);
    // Was this the first bet of this round?
    if bet_nr == 0 {
        // Yes it was, query the state for the length of the playing period in seconds by
        // retrieving the playPeriod value from state storage
        let mut play_period: i32 = f.state.play_period().value();
        // if the play period is less than 10 seconds we override it with the default duration.
        // Note that this will also happen when the play period was not set yet because in that
        // case a zero value was returned.
        if play_period < 10 {
            play_period = DEFAULT_PLAY_PERIOD;
        }
        // And now for our next trick we post a delayed request to ourselves on the Tangle.
        // We are requesting to call the 'lockBets' function, but delay it for the play_period
        // amount of seconds. This will lock in the playing period, during which more bets can
        // be placed. Once the 'lockBets' function gets triggered by the ISCP it will gather all
        // bets up to that moment as the ones to consider for determining the winner.
        ScFuncs::lock_bets(ctx).func.delay(play_period).transfer_iotas(1).post();
    }
}
pub fn func_place_bet ( ctx : & ScFuncContext , f : & PlaceBetContext ) { // Since we are sure that the 'number' parameter actually exists we can // retrieve its actual value into an i64. let number : i64 = f . params . number ( ) . value ( ) ; // Require that the number is a valid number to bet on, otherwise panic out. ctx . require ( number >= 1 && number <= MAX_NUMBER , " " ) ; // Create ScBalances proxy to the incoming balances for this request. // Note that ScBalances wraps an ScImmutableMap of token color/amount combinations // in a simpler to use interface. let incoming : ScBalances = ctx . incoming ( ) ; // Retrieve the amount of plain iota tokens that are part of the incoming balance. let amount : i64 = incoming . balance ( & ScColor :: IOTA ) ; // Require that there are actually some plain iotas there ctx . require ( amount > 0 , " " ) ; // Now we gather all information together into a single serializable struct // Note that we use the caller() method of the function context to determine // the agent id of the better. This is where a potential pay-out will be sent. let bet = Bet { better : ctx . caller ( ) , amount : amount , number : number , } ; // Get the array of current bets from state storage. let bets : ArrayOfMutableBet = f . state . bets ( ) ; // Determine what the next bet number is by retrieving the length of the bets array. let bet_nr : i32 = bets . length ( ) ; // Append the bet data to the bets array. The bet array will automatically take care // of serializing the bet struct into a bytes representation. bets . get_bet ( bet_nr ) . set_value ( & bet ) ; // Was this the first bet of this round? if bet_nr == 0 { // Yes it was, query the state for the length of the playing period in seconds by // retrieving the playPeriod value from state storage let mut play_period : i32 = f . state . play_period ( ) . value ( ) ; // if the play period is less than 10 seconds we override it with the default duration. // Note that this will also happen when the play period was not set yet because in that // case a zero value was returned. if play_period < 10 { play_period = DEFAULT_PLAY_PERIOD ; } // And now for our next trick we post a delayed request to ourselves on the Tangle. // We are requesting to call the 'lockBets' function, but delay it for the play_period // amount of seconds. This will lock in the playing period, during which more bets can // be placed. Once the 'lockBets' function gets triggered by the ISCP it will gather all // bets up to that moment as the ones to consider for determining the winner. ScFuncs :: lock_bets ( ctx ) . func . delay ( play_period ) . transfer_iotas ( 1 ) . post ( ) ; } }
'placeBet' is used by betters to place a bet on a number from 1 to MAX_NUMBER.
' placeBet ' is used by betters to place a bet on a number from 1 to MAX_NUMBER .
ctx
&ScFuncContext
f
&PlaceBetContext
ctx
&ScFuncContext
f
&PlaceBetContext