是否有可能在父合同中获得子合同的变量(uint) ?(可靠性)



我正在创建一个系统,为我的ERC20令牌的每笔交易增加费用。
我有两个文件,wiseth_v1.solERC20Mod.sol用固体写的。
ERC20.sol是ERC20的修改版本。solo Openzeppelin的合同。
wiseth_v1.sol第一行:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "./ERC20Mod.sol";
contract Wiseth is ERC20, Ownable {
using SafeMath for uint256;
uint deployDate;
uint daHour;
bool isPassed;
bytes32 num_type;
uint public percentage;

可以看到,父合约是ERC20Mod.sol它的子节点是wiseth_v1.sol(真正令牌的脚本)。
合约的所有者使用这个函数(wiseth_v1.sol)来设置费用的百分比):

function setFirstPercentageFee(uint256 fee) external onlyOwner {
percentage = fee;
}

这是ERC20Mod.sol上事务的transferFrom函数:

function transferFrom(
address from,
address to,
uint256 amount
) public virtual override returns (bool) {
uint256 fee = (amount.mul(percentage)).div(10000);
uint256 total = amount.sub(fee);
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, total);
return true;
}

在计算费用uint256 fee = (amount.mul(percentage)).div(10000);时,我需要取"百分比";uint256 fromwiseth_v1.sol我该怎么做呢?任何帮助都是感激的。(我不想把wiseth_v1.solERC20Mod.sol中的代码我想把它们分开。谢谢。

我在谷歌搜索,但只发现如何采取父变量在它的孩子。我使用remix.ethereum.org

我认为继承的整个逻辑是子继承父,但你想做相反的事情。也许你应该定义自己的变量"百分比"在ERC20Mod。并在需要时手动设置。

最新更新