Staking and mining is where developers use one of the characters attributes as weight to POS staking.
function stake(uint tokenId, uint energyCost) public {
require(!stable.isUsing(tokenId), 'the cattle is using');
require(stable.isStable(tokenId), 'not in the stable');
require(stable.CattleOwner(tokenId) == msg.sender, "not cattle's owner");
require(cattle.getAdult(tokenId),'must bu adult');
stable.changeUsing(tokenId, true);
userInfo[msg.sender].cattleList.push(tokenId);
// uint power = cattle.getMilk(tokenId);
// require(power > 0, 'only cow can stake');
uint power = coutingPower(msg.sender, tokenId);
uint tempDebt = coutingDebt();
totalPower += power;
lastTime = block.timestamp;
debt = tempDebt;
userInfo[msg.sender].totalPower += power;
stakeInfo[tokenId] = StakeInfo({
status : true,
milkPower : power,
tokenId : tokenId,
endTime : findEndTime(tokenId, energyCost),
starrtTime : block.timestamp,
claimTime : block.timestamp,
debt : tempDebt
});
stable.costEnergy(tokenId, coutingEnergyCost(msg.sender,energyCost));
cowsAmount ++;
}
Through the character router contract, users can consume the attribute of the characters (dynamic value). He or she can stake the character into the staking contract and gain corresponding rewards, the contract will update the status of the character and tell if it is in use.
Users can always quit staking and claim the rewards.