Skip to content

Proposed modification of getPowerUpInfo in the powerUps contract #23

@Austin-Williams

Description

@Austin-Williams

The getPowerUpInfo function in the powerUps contract returns an "empty" powerUp when id is out of range / does not exist. Should we instead have getPowerUpInfo revert when the passed id is out of range / does not exist?

Current code:

/**
    * @dev Returns info about a given PowerUp
    * @param id The index of the PowerUp in the powerUps array
    */
    function getPowerUpInfo(
        uint256 id
    )
        external
        view
        returns (
            string memory contentAddress,
            uint256 tokensBurned,
            uint256 lastTopupTime,
            bytes32 keyword
        )
    {
        if (powerUps.length > id) {

            PowerUp storage powerUp = powerUps[id];

            contentAddress = powerUp.contentAddress;
            tokensBurned = powerUp.tokensBurned;
            lastTopupTime = powerUp.lastTopupTime;
            keyword = powerUp.keyword;

        }

        return (contentAddress, tokensBurned, lastTopupTime, keyword);
    }

Proposed change:

/**
    * @dev Returns info about a given PowerUp
    * @param id The index of the PowerUp in the powerUps array
    */
    function getPowerUpInfo(
        uint256 id
    )
        external
        view
        returns (
            string memory contentAddress,
            uint256 tokensBurned,
            uint256 lastTopupTime,
            bytes32 keyword
        )
    {
        require(id < powerUps.length, "id is out of range");

        PowerUp storage powerUp = powerUps[id];

        contentAddress = powerUp.contentAddress;
        tokensBurned = powerUp.tokensBurned;
        lastTopupTime = powerUp.lastTopupTime;
        keyword = powerUp.keyword;

        return (contentAddress, tokensBurned, lastTopupTime, keyword);
    }

Metadata

Metadata

Assignees

Labels

❗lowLow priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions