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 draw ID to calculate ring buffer storage slots. The PrizeDistribution parameters can be created by manager/owner and existing PrizeDistribution parameters can only be updated by the owner. When adding a new PrizeDistribution basic sanity checks will be used to validate the incoming parameters.
Write methods description
initialize()
Allows to initialize the contract during the deployment. Initialize for PrizeDistributionBuffer.
Parameters:
Name | Type | Description |
---|---|---|
_owner | address | Address of the PrizeDistributionBuffer owner. |
_cardinality | uint8 | Cardinality of the |
pushPrizeDistribution()
Adds new PrizeDistribution record to ring buffer storage. Only callable by the owner or manager.
Parameters:
Name | Type | Description |
---|---|---|
_drawId | uint32 | Draw ID linked to PrizeDistribution parameters. |
_prizeDistribution | PrizeDistribution | Parameters struct. |
Return:
Name | Type | Description |
---|---|---|
_pushed | bool |
|
setPrizeDistribution()
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.
Parameters:
Name | Type | Description |
---|---|---|
_drawId | uint32 | Draw ID to be set. |
_prizeDistribution | PrizeDistribution | Information to set on the drawId. |
Return:
Name | Type | Description |
---|---|---|
_drawId | uint32 | Draw ID that was set. |
claimOwnership()
Allows the pendingOwner
address to claim the owner role. This function is only callable by the pendingOwner
.
renounceOwnership()
Leaves the contract without owner. It will not be possible to call the owner's functions anymore. Can only be called by the current owner. The method does not take any parameters. Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.
transferOwnership()
Transfers ownership of the contract to a _pendingOwner
. Can only be called by the current owner.
Parameters:
Name | Type | Description |
---|---|---|
_newOwner | address | An account that will become the |
setManager()
Allows the owner to give the manager role to an address. The manager role has access to the functions with the modified onlyManager
or onlyManagerOrOwner
.
Parameters:
Name | Type | Description |
---|---|---|
_newManager | address | An account that will become the new manager. |
Read methods description
getBufferCardinality()
Read a ring buffer cardinality.
getNewestPrizeDistribution()
Read newest PrizeDistribution from prize distributions ring buffer. Uses nextDrawIndex to calculate the most recently added PrizeDistribution.
Return:
Name | Type | Description |
---|---|---|
_prizeDistribution | PrizeDistribution | Prize distribution. |
_drawId | uint32 | Draw ID. |
getOldestPrizeDistribution()
Read oldest PrizeDistribution from prize distributions ring buffer. Finds the oldest Draw by buffer.nextIndex
and buffer.lastDrawId
.
Return:
Name | Type | Description |
---|---|---|
_prizeDistribution | PrizeDistribution | Prize distribution. |
_drawId | uint32 | Draw ID. |
getPrizeDistribution()
Gets the PrizeDistributionBuffer for a _drawId
.
Return:
Name | Type | Description |
---|---|---|
_prizeDistribution | PrizeDistribution | Prize distribution. |
_drawId | uint32 | Draw ID. |
getPrizeDistributionCount()
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:
Name | Type | Description |
---|---|---|
_number | uint32 | Number of PrizeDistributions stored in the prize distributions ring buffer. |
getPrizeDistributions()
Gets PrizeDistribution list from array of _drawIds
.
Parameters:
Name | Type | Description |
---|---|---|
_drawIds | uint32[] |
|
owner()
Owner role that can be granted exclusive access to specific functions with the modifier onlyOwner
.
manager()
Manager role that can be granted exclusive access to specific functions with the modifier onlyManager
or onlyManagerOrOwner
.
pendingOwner()
Address that can claim the owner role. It is used to transfer the owner.
Last updated