【发布时间】:2021-08-14 10:55:29
【问题描述】:
我是编码新手,在 Solidity 中找不到解决 Stack too deep 错误的方法
function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256) {
(uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity, uint256 tCharity, uint256 tMarketing) = _getTValues(tAmount);
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, tCharity, tMarketing, _getRate());
return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity, tCharity, tMarketing);
}
添加 tMarketing 后,我在第 3 行收到错误消息。
我尝试使用此处显示的逻辑解决我的问题:https://soliditydeveloper.com/stacktoodeep
我只是不知道如何正确应用它......
我需要帮助。谢谢大家
这是 _getValues() 函数的依赖项 - _getTValues() 和 _getRValues()(以及它们的依赖项)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
合约 STACKTOODEEP {
uint256 public _taxFee = 3; // 3% Redistributed to all holders
uint256 private _previousTaxFee = _taxFee;
uint256 public _liquidityFee = 3; // 3% Sent to PancakSwap Liquidity Pool
uint256 private _previousLiquidityFee = _liquidityFee;
uint256 public _charityFee = 2; // 2% Sent to Charity Wallet
uint256 private _previousCharityFee = _charityFee;
uint256 public _marketingFee = 2; // 2% Sent to Marketing Wallet
uint256 private _previousMarketingFee = _marketingFee;
function calculateTaxFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_taxFee).div(
10**2
);
}
function calculateLiquidityFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_liquidityFee).div(
10**2
);
}
function calculateCharityFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_charityFee).div(
10**2
);
}
function calculateMarketingFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_marketingFee).div(
10**2
);
}
function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256) {
(uint256 tTransferAmount, uint256 tFee, uint256 tLiquidity, uint256 tCharity, uint256 tMarketing) = _getTValues(tAmount);
(uint256 rAmount, uint256 rTransferAmount, uint256 rFee) = _getRValues(tAmount, tFee, tLiquidity, tCharity, tMarketing, _getRate());
return (rAmount, rTransferAmount, rFee, tTransferAmount, tFee, tLiquidity, tCharity, tMarketing);
}
function _getTValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256, uint256) {
uint256 tFee = calculateTaxFee(tAmount);
uint256 tLiquidity = calculateLiquidityFee(tAmount);
uint256 tCharity = calculateCharityFee(tAmount);
uint256 tMarketing = calculateMarketingFee(tAmount);
uint256 tTransferAmount = tAmount.sub(tFee).sub(tLiquidity);
return (tTransferAmount, tFee, tLiquidity, tCharity, tMarketing);
}
function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 tCharity, uint256 tMarketing, uint256 currentRate) private pure returns (uint256, uint256, uint256) {
uint256 rAmount = tAmount.mul(currentRate);
uint256 rFee = tFee.mul(currentRate);
uint256 rLiquidity = tLiquidity.mul(currentRate);
uint256 rCharity = tCharity.mul(currentRate);
uint256 rMarketing = tMarketing.mul(currentRate);
uint256 rTransferAmount = rAmount.sub(rFee).sub(rLiquidity).sub(rCharity).sub(rMarketing);
return (rAmount, rTransferAmount, rFee);
}
}
【问题讨论】:
-
请编辑您的问题并分享
_getValues()函数的依赖项 -_getTValues()和_getRValues()(及其依赖项),以便重现(和解决)您的问题。 -
已编辑以添加 _getValues() 函数的依赖项 - _getTValues() 和 _getRValues()(及其依赖项)@PetrHejda
-
看来从
_getTValues函数调用的这一行uint256 tMarketing = calculateMarketingFee(tAmount);失败了。是否也可以将其作为依赖项包含在内? -
嗨,对不起,我说过我是编码新手,所以我不太擅长分享我的代码。我已经编辑了我的问题。我希望这次你有你需要的一切。非常感谢你帮助我,我很感激@PetrHejda
标签: solidity