How to convert array static to dynamic in solidity?


This code is a betting smart contract. How can I convert the static payout to dynamic? The structure is only Hardcode 1:1 static payout odds. How can I convert it to dynamic?

source code full:

  function claimBetPayout(uint _betId) external {
    Bet storage bet = bets[_betId];
    Event memory betEvent = events[bet.eventId];

    require(msg.sender == bet.bettor, "Only original bettor address can claim payout");
    require(betEvent.result == bet.option, "Only winning bets can claim payout");
    require(bet.claimed == 0, "Bet payout was already claimed");

    uint payoutAmount = calculateBetPayoutAmount(bet);

    bet.claimed = 1;

Above is the claimBetPayout function that payouts fix value. How to claim multiple results in events?

You are using the value of "staticPayoutOdds" every time you create a new Event, you should add an extra "PayoutOdds" parameter when creating a new event and then use that value.

function addEvent(string memory _option1, string memory _option2, uint64 _startTime, uint8[] memory payoutOdds) external onlyOwner {

    uint eventId = events.length;

    Event memory newEvent = Event(_option1, _option2, _startTime, payoutOdds, 0);


    emit NewEvent(eventId, _option1, _option2, _startTime, payoutOdds, 0);

1 Like