Skip to main content

PrizeDistributionBuffer

The PrizeDistributionBuffer contract provides historical lookups of PrizeDistribution struct parameters (linked with a Draw ID) via a circular ring buffer. Historical PrizeDistribution parameters can be accessed on-chain using a drawId to calculate ring buffer storage slot. The PrizeDistribution parameters can be created by manager/owner and existing PrizeDistribution parameters can only be updated the owner. When adding a new PrizeDistribution basic sanity checks will be used to validate the incoming parameters.

Structs

PrizeDistribution

  • uint8 bitRangeSize
  • uint8 matchCardinality
  • uint32 startTimestampOffset
  • uint32 endTimestampOffset
  • uint32 maxPicksPerUser
  • uint32 expiryDuration
  • uint104 numberOfPicks
  • uint32[16] tiers
  • uint256 prize

Functions

constructor

  function constructor(
address _owner,
uint8 _cardinality
) public

Constructor for PrizeDistributionBuffer

Parameters:

NameTypeDescription
_owneraddressAddress of the PrizeDistributionBuffer owner
_cardinalityuint8Cardinality of the bufferMetadata

getBufferCardinality

  function getBufferCardinality(
) external returns (uint32)

Read a ring buffer cardinality

Return Values:

TypeDescription
uint32Ring buffer cardinality

getPrizeDistribution

  function getPrizeDistribution(
uint32 drawId
) external returns (struct IPrizeDistributionBuffer.PrizeDistribution)

Gets the PrizeDistributionBuffer for a drawId

Parameters:

NameTypeDescription
drawIduint32drawId

getPrizeDistributions

  function getPrizeDistributions(
uint32[] drawIds
) external returns (struct IPrizeDistributionBuffer.PrizeDistribution[])

Gets PrizeDistribution list from array of drawIds

Parameters:

NameTypeDescription
drawIdsuint32[]drawIds to get PrizeDistribution for

getPrizeDistributionCount

  function getPrizeDistributionCount(
) external returns (uint32)

Gets the number of PrizeDistributions stored in the prize distributions ring buffer.

If no Draws have been pushed, it will return 0. If the ring buffer is full, it will return the cardinality. Otherwise, it will return the NewestPrizeDistribution index + 1.

Return Values:

TypeDescription
uint32Number of PrizeDistributions stored in the prize distributions ring buffer.

getNewestPrizeDistribution

  function getNewestPrizeDistribution(
) external returns (struct IPrizeDistributionBuffer.PrizeDistribution prizeDistribution, uint32 drawId)

Read newest PrizeDistribution from prize distributions ring buffer.

Uses nextDrawIndex to calculate the most recently added PrizeDistribution.

getOldestPrizeDistribution

  function getOldestPrizeDistribution(
) external returns (struct IPrizeDistributionBuffer.PrizeDistribution prizeDistribution, uint32 drawId)

Read oldest PrizeDistribution from prize distributions ring buffer.

Finds the oldest Draw by buffer.nextIndex and buffer.lastDrawId

pushPrizeDistribution

  function pushPrizeDistribution(
uint32 drawId,
struct IPrizeDistributionBuffer.PrizeDistribution prizeDistribution
) external returns (bool)

Adds new PrizeDistribution record to ring buffer storage.

Only callable by the owner or manager

Parameters:

NameTypeDescription
drawIduint32Draw ID linked to PrizeDistribution parameters
prizeDistributionstruct IPrizeDistributionBuffer.PrizeDistributionPrizeDistribution parameters struct

setPrizeDistribution

  function setPrizeDistribution(
) external returns (uint32)

Sets existing PrizeDistribution with new PrizeDistribution parameters in ring buffer storage.

Retroactively updates an existing PrizeDistribution and should be thought of as a "safety" fallback. If the manager is setting invalid PrizeDistribution parameters the Owner can update the invalid parameters with correct parameters.

manager

  function manager(
) public returns (address)

Gets current _manager.

Return Values:

TypeDescription
addressCurrent _manager address.

setManager

  function setManager(
address _newManager
) external returns (bool)

Set or change of manager.

Throws if called by any account other than the owner.

Parameters:

NameTypeDescription
_newManageraddressNew _manager address.

Return Values:

TypeDescription
boolBoolean to indicate if the operation was successful or not.

owner

  function owner(
) public returns (address)

Returns the address of the current owner.

pendingOwner

  function pendingOwner(
) external returns (address)

Gets current _pendingOwner.

Return Values:

TypeDescription
addressCurrent _pendingOwner address.

renounceOwnership

  function renounceOwnership(
) external

Renounce ownership of the contract.

Leaves the contract without owner. It will not be possible to call onlyOwner functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.

transferOwnership

  function transferOwnership(
address _newOwner
) external

Allows current owner to set the _pendingOwner address.

Parameters:

NameTypeDescription
_newOwneraddressAddress to transfer ownership to.

claimOwnership

  function claimOwnership(
) external

Allows the _pendingOwner address to finalize the transfer.

This function is only callable by the _pendingOwner.

Events

Deployed

  event Deployed(
uint8 cardinality
)

Emitted when the contract is deployed.

Parameters:

NameTypeDescription
cardinalityuint8The maximum number of records in the buffer before they begin to expire.

ManagerTransferred

  event ManagerTransferred(
address previousManager,
address newManager
)

Emitted when _manager has been changed.

Parameters:

NameTypeDescription
previousManageraddressprevious _manager address.
newManageraddressnew _manager address.

OwnershipOffered

  event OwnershipOffered(
address pendingOwner
)

Emitted when _pendingOwner has been changed.

Parameters:

NameTypeDescription
pendingOwneraddressnew _pendingOwner address.

OwnershipTransferred

  event OwnershipTransferred(
address previousOwner,
address newOwner
)

Emitted when _owner has been changed.

Parameters:

NameTypeDescription
previousOwneraddressprevious _owner address.
newOwneraddressnew _owner address.

PrizeDistributionSet

  event PrizeDistributionSet(
uint32 drawId,
struct IPrizeDistributionBuffer.PrizeDistribution prizeDistribution
)

Emit when PrizeDistribution is set.

Parameters:

NameTypeDescription
drawIduint32Draw id
prizeDistributionstruct IPrizeDistributionBuffer.PrizeDistributionIPrizeDistributionBuffer.PrizeDistribution