[英]How do I fix Stack Too Deep Error on Solidity?
On solidity, I keep getting the 'stack too deep' error.在稳固性上,我不断收到“堆栈太深”的错误。 I was wondering if anyone can help me fix this with in following code:
我想知道是否有人可以通过以下代码帮助我解决此问题:
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);
}
Thanks!谢谢!
You cannot have more than 16 local variable (iirc) but in this particular case you don't really need them all.您不能拥有超过 16 个局部变量 (iirc),但在这种特殊情况下,您并不真正需要它们。 Safemoon has a lot of redundant code, especially in the
getValues
and transfer
functions. Safemoon 有很多冗余代码,尤其是在
getValues
和transfer
函数中。 I suggest you have a look at the way this is done in SafeToken
- https://github.com/solidity-guru/safetoken/blob/main/safetoken.sol I suggest you have a look at the way this is done in
SafeToken
- https://github.com/solidity-guru/safetoken/blob/main/safetoken.sol
The only reason _getTValues
is calculating all those t values is to subtract them from the tTransferAmount
... but you could just use the sum of all fees, eg _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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.