Implementation of DrawChain
Overview
Setting Up DrawChain
■ Functions for Publishers
Create a contract to set conditions for running DrawChain:
Create a contract that implements the IDrawChainAuthorizer interface (IDrawChainAuthorizer.sol):
@param drawChainId DrawChain ID
@param presetId Preset number (freely defined within the implementation contract)
@param personaId PERSONA Id
function authorizeDraw (uint256 drawChainId, uint256 presetId, uint256 personaId) external view returns (bool);
Refer to the environment information for the interface file.
Register DrawChain
Register the contract created in step 1 in AuthorizerInfo. Set the address of the created contract and presetId in AuthorizerInfo. The usage of presetId can be freely defined within the implementation contract.
Function to register DrawChain (Drawchain.sol):
@param squareKey SquareKey associated with DrawChain
@param _authorizers List of authorizers
@return DrawChain ID
function newDrawChain(uint256 squareKey, AuthorizerInfo[] calldata _authorizers) public returns (uint256)
AuthorizerInfo[]:
struct AuthorizerInfo {
@notice Address of the IDrawChainAuthorizer contract
address authorizer;
@notice Preset ID of the IDrawChainAuthorizer contract
uint256 presetId;
}
Setting Active and Inactive States
Function to set the active and inactive states of DrawChain (Drawchain.sol):
@param drawChainId DrawChain ID @param active true: draw is possible, false: draw is not possible function deactivateDrawChain(uint256 drawChainId, bool active) public;
Other DrawChain Functions
Returning an Array of DrawChain IDs for Which a Specific PERSONA Can Draw (Drawchain.sol):
@param from Starting ID of DrawChains to inspect (inclusive)
@param until Ending ID of DrawChains to inspect (inclusive)
@param limit Limit the search to this many successful DrawChains (maximum number of elements to return in the array)
@param personaId PERSONA ID to draw DrawChains
@return Array of DrawChain IDs where draw is successful
function availables(uint256 from, uint256 until, uint256 limit, uint256 personaId) public view returns (uint256[] memory)
Regarding Specified Ranges
Be cautious when using availables() to search over a wide range, as it may result in gas exhaustion.
Getting DrawChain Information (Drawchain.sol):
@param fromId Starting DrawChain ID
@param count Number of DrawChain information to retrieve
@return Array of DrawChainInfo
function getDrawChain(uint256 fromId, uint256 count) public view returns (DrawChainInfo[] memory)
DrawChainInfo:
struct DrawChainInfo {
uint256 id;
uint32 squareKey;
uint8 active;
uint8 pad1;
uint16 pad2;
uint64 pad3;
uint128 pad4;
}
Returning the Number of Draws (History Count) for Each DrawChain (Drawchain.sol):
@param drawChainId DrawChain ID
@return Number of draws (history count)
function drawHistoryCountByDrawChain(uint256 drawChainId) public view returns (uint256)
Returning the Draw History for Each DrawChain (Batch Version) (Drawchain.sol):
@param drawChainId DrawChain ID
@param fromIdx Starting index (inclusive)
@param count Number of draw histories to retrieve
@return Array of draw histories
function drawHistoryByDrawChain(uint256 drawChainId, uint256 fromIdx, uint256 count) public view returns (History[] memory)
Returning the Number of Draws (History Count) for Each PERSONA (Drawchain.sol):
@param personaId PERSONA Id
@return Number of draws (history count)
function drawHistoryCountByPersona(uint256 personaId) public view returns (uint256)
Returning the Draw History for Each PERSONA (Batch Version) (Drawchain.sol):
@param personaId PERSONA Id
@param fromIdx Starting index (inclusive)
@param count Number of draw histories to retrieve
@return Array of draw histories
function drawHistoryByPersona(uint256 personaId, uint256 fromIdx, uint256 count) public view returns (History[] memory)
History:
struct History {
@notice History ID, same as the value returned by draw()
uint256 id;
@notice DrawChain Id
uint256 drawChainId;
@notice PERSONA Id
uint256 personaId;
@notice Owner of the PERSONA at the time of the draw
address personaOwner;
@notice Timestamp when the draw occurred
uint128 drawnOn;
@notice Timestamp when the delivery was made
uint128 deliveredOn;
}
Returning the Number of Draws (History Count) for Each DrawChain and PERSONA (Drawchain.sol):
@param drawChainId DrawChain ID
@param personaId PERSONA Id
@return Number of draws (history count)
function drawHistoryCountByDrawChainAndPersona(uint256 drawChainId, uint256 personaId) public view returns (uint256)
Returning the Draw History for Each DrawChain and PERSONA (Batch Version) (Drawchain.sol):
@param drawChainId DrawChain ID
@param personaId PERSONA Id
@param fromIdx Starting index (inclusive)
@param count Number of draw histories to retrieve
@return Array of draw histories
function drawHistoryByDrawChainAndPersona(uint256 drawChainId, uint256 personaId, uint256 fromIdx, uint256 count) public view returns (History[] memory)
Returning the Number of Draws (History Count) for Each PERSONA Owner (Drawchain.sol):
@param personaOwner Persona owner address
@return Number of draws (history count)
function drawHistoryCountByPersonaOwner(address personaOwner) public view returns (uint256)
Returning the Draw History for Each PERSONA Owner (Batch Version) (Drawchain.sol):
@param personaOwner Persona owner address
@param fromIdx Starting index (inclusive)
@param count Number of draw histories to retrieve
@return Array of draw histories
function drawHistoryByPersonaOwner(address personaOwner, uint256 fromIdx, uint256 count) public view returns (History[] memory)
Executing DrawChain
Drawing a DrawChain Contract: Drawchain
■ Function Executed by Users When Performing Operations
Function to draw a DrawChain (Drawchain.sol):
@param drawChainId DrawChain ID @param personaId PERSONA ID @return 0: Draw failed. Non-zero: Index of the history function draw(uint256 drawChainId, uint256 personaId) public returns (uint256)
Calling the DrawChain creator (Publisher) when distributing prizes and register the timestamp when delivery of prizes is made.
■ Function for Publishers
Function to register a timestamp (Drawchain.sol):
@param historyId History ID returned when draw is successful function delivered(uint256 historyId)
Contract to Limit the Ability Values of PERSONAs that Can Draw (DrawAbilityLimitter.sol)
Functions for Registration:
@param limit Set the ability value limits. Limit[6] corresponds to FOR, ABS, DFT, MND, INT, EXP, in that order.
@return numPresets Registration number
function newPreset(Limit[6] calldata limit) public returns (uint256)
Functions for Modification:
@notice Specify the registration number for presetId. Only the sender at the time of newPreset can update.
@param presetId Registration number
@param limit Set the ability value limits. Limit[6] corresponds to FOR, ABS, DFT, MND, INT, EXP, in that order.
function alterPreset(uint256 presetId, Limit[6] calldata limit)
Values:
uint256 public numPresets; // Registration number, incremented and assigned automatically by newPreset.
mapping(uint256 => Limit[6]) public preset; // Mapping of registration numbers to ability value limit contents
mapping(uint256 => address) public presetOwner; // Mapping of registration numbers to the sender at the time of newPreset
Limit Structure:
struct Limit {
uint16 min;
uint16 max;
}
Contract to Limit PERSONA Categories that Can Draw (DrawPersonaCategoryLimitter.sol)
Contract to Limit the Number of Draws (DrawQuantityLimitter.sol)
Contract to Limit the Caller of draw() to Subscribers of the Square Key Associated with DrawChain (DrawFollowerLimitter.sol)
Functions to Register or Remove from the Blacklist:
@param squareKey Target square key
@param _address Follower address
@param isBlack true: Register, false: Remove from the blacklist
function setBlackList(uint256 squareKey, address _address, bool isBlack) public
Contract to Limit the Number of draw() Calls by the Same PERSONA (DrawCountLimitter.sol)
Contract to Limit draw() Calls to Specific PERSONAs (DrawPersonaLimitter.sol)
newPreset:
@param personas Array of PERSONA IDs to be registered
@return numPresets Registration number
function newPreset(uint256[] calldata personas) public returns (uint256)