/// @dev An internal method that creates a new cutie and stores it. This
/// method does not check anything and should only be called when the
/// input data is valid for sure. Will generate both a Birth event
/// and a Transfer event.
/// @param _momId The cutie ID of the mom of this cutie (zero for gen0)
/// @param _dadId The cutie ID of the dad of this cutie (zero for gen0)
/// @param _generation The generation number of this cutie, must be computed by caller.
/// @param _genes The cutie's genetic code.
/// @param _owner The initial owner of this cutie, must be non-zero (except for the unCutie, ID 0)
function _createCutie(
uint40 _momId,
uint40 _dadId,
uint16 _generation,
uint16 _cooldownIndex,
uint256 _genes,
address _owner,
uint40 _birthTime
)
internal
returns (uint40)
{
Cutie memory _cutie = Cutie({
genes: _genes,
birthTime: _birthTime,
cooldownEndTime: 0,
momId: _momId,
dadId: _dadId,
cooldownIndex: _cooldownIndex,
generation: _generation,
optional: 0
});
uint256 newCutieId256 = cuties.push(_cutie) - 1;
// Check if id can fit into 40 bits
require(newCutieId256 <= 0xFFFFFFFFFF);
uint40 newCutieId = uint40(newCutieId256);
// emit the birth event
emit Birth(_owner, newCutieId, _cutie.momId, _cutie.dadId, _cutie.genes);
// This will assign ownership, as well as emit the Transfer event as
// per ERC721 draft
_transfer(0, _owner, newCutieId);
return newCutieId;
}
/// @notice Returns all the relevant information about a certain cutie.
/// @param _id The ID of the cutie of interest.
function getCutie(uint40 _id)
external
view
returns (
uint256 genes,
uint40 birthTime,
uint40 cooldownEndTime,
uint40 momId,
uint40 dadId,
uint16 cooldownIndex,
uint16 generation
) {
Cutie storage cutie = cuties[_id];
genes = cutie.genes;
birthTime = cutie.birthTime;
cooldownEndTime = cutie.cooldownEndTime;
momId = cutie.momId;
dadId = cutie.dadId;
cooldownIndex = cutie.cooldownIndex;
generation = cutie.generation;
}
/// @dev Assigns ownership of a particular Cutie to an address.
function _transfer(address _from, address _to, uint40 _cutieId) internal {
// since the number of cuties is capped to 2^40
// there is no way to overflow this
ownershipTokenCount[_to]++;
// transfer ownership
cutieIndexToOwner[_cutieId] = _to;
// When creating new cuties _from is 0x0, but we cannot account that address.
if (_from != address(0)) {
ownershipTokenCount[_from]--;
// once the cutie is transferred also clear breeding allowances
delete sireAllowedToAddress[_cutieId];
// clear any previously approved ownership exchange
delete cutieIndexToApproved[_cutieId];
}
// Emit the transfer event.
emit Transfer(_from, _to, _cutieId);
}
/// @dev For transferring a cutie owned by this contract to the specified address.
/// Used to rescue lost cuties. (There is no "proper" flow where this contract
/// should be the owner of any Cutie. This function exists for us to reassign
/// the ownership of Cuties that users may have accidentally sent to our address.)
/// @param _cutieId - ID of cutie
/// @param _recipient - Address to send the cutie to
function restoreCutieToAddress(uint40 _cutieId, address _recipient) public onlyOperator whenNotPaused {
require(_isOwner(this, _cutieId));
_transfer(this, _recipient, _cutieId);
}
address ownerAddress;
address operatorAddress;
bool public paused = false;
modifier onlyOwner()
{
require(msg.sender == ownerAddress);
_;
}