如何修复Solidity上的Stack Too Deep错误



在solidity上,我一直收到"堆栈太深"的错误。我想知道是否有人可以用以下代码帮我解决这个问题:

function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256) {
uint256 tFee = calculateTaxFee(tAmount);
uint256 tLiquidity = calculateLiquidityFee(tAmount);
uint256 tDev = calculateDevFee(tAmount);
uint256 tBurn = calculateBurnFee(tAmount);
uint256 tCharity = calculateCharityFee(tAmount);
uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity);
tTransferAmount = tTransferAmount.sub(tDev);
tTransferAmount = tTransferAmount.sub(tCharity);
tTransferAmount = tTransferAmount.sub(tBurn);
return (tTransferAmount, tFee, tLiquidity, tDev, tBurn, tCharity);
}

谢谢!

您不能拥有超过16个局部变量(iirc(,但在这种特殊情况下,您并不真正需要全部变量。Safemoon有很多冗余代码,尤其是在getValuestransfer函数中。我建议你看看SafeToken-https://github.com/solidity-guru/safetoken/blob/main/safetoken.sol

_getTValues计算所有这些t值的唯一原因是从tTransferAmount中减去它们。。。但你可以使用所有费用的总和,例如

function _getTValues(uint256 tAmount) ... {
uint256 tFeesSum = calculateSumOfFees(tAmount);
uint256 tTransferAmount = tAmount - tFeesSum; // no need to use SafeMath in solidity ^0.8
return tTransferAmount;
}

相关内容

  • 没有找到相关文章

最新更新