简体   繁体   English

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

[英]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 有很多冗余代码,尤其是在getValuestransfer函数中。 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.

相关问题 如何修复 python3 中的“sh: 1: title: not found”错误? - How do I fix "sh: 1: title: not found" error in python3? 如何修复“之前的预期主表达式”'令牌'错误? - How do I fix a “Expected Primary-expression before ')' token” error? 生成的CSRF令牌太多(PHP),我该如何处理它们? - Too many CSRF tokens generated (PHP), how do I deal with them? 如何在 Solidity 智能合约中启用 Claim Tokens? - How to enable Claim Tokens in Solidity Smart Contract? 如何修复find_by(remember_token:Remember_token) - How do I fix find_by(remember_token: remember_token) 如何在Zeppelin Solidity中将标准令牌与众筹链接 - How to link Standard Token with crowdsale in Zeppelin Solidity 尝试编译 Solidity 令牌合约但不断收到编译错误 - Trying to compile solidity token contract but keep getting compile error 如何在 Solidity 中制作需要 0.1 个以太坊的铸币功能? - How to make minting function that takes 0.1 ethereum in Solidity? 如何在 mapbox 链接中将令牌更改为新令牌后修复错误 - How to fix an error after changing token to new one in mapbox link 使用python库rply时,解析多行时出现意外令牌错误。 我怎样才能解决这个问题? - While using the python library rply, I get an unexpected token error when parsing more than one line. How can I fix this?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM