如何覆盖 GovernorCountingSimple.sol 文件中的 openzeppelin _countVote 函数?

how to override openzeppelin _countVote function in GovernorCountingSimple.sol file?

我正在使用 openzeppelin 创建一个 DAO,我从 openzeppelin 合同向导下载了他们提供的治理合同。一旦我将这个文件导入到 remix IDE 中,就会弹出一个错误提示

“函数必须覆盖指定但不覆盖任何东西”

所以我按照那个错误找到了 GovernorCountingSimple.sol 文件,发现它是 _countVote 函数,但我似乎无法覆盖它。我想我只是遗漏了一些简单的东西,但是当函数中的最后一个参数是没有声明名称的“字节内存”时,我不知道如何重写它,而且我似乎不能只调用函数上的 super 语句来传递最后一个参数。

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/governance/Governor.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorSettings.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorCountingSimple.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorVotes.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorTimelockControl.sol";

contract GovernernerContract is Governor, GovernorSettings, GovernorCountingSimple, 
GovernorVotes, GovernorVotesQuorumFraction, GovernorTimelockControl {
constructor(
                            IVotes _token, 
                            TimelockController _timelock, 
                            uint256 _votingDelay,
                            uint256 _votingPeriod,
                            uint256 _quorumPercentage
                        )
    Governor("governernerContract")
    GovernorSettings( _votingDelay /* 1 block */, _votingPeriod  /* 45818= ~ 1 week */, 0)
    GovernorVotes(_token)
    GovernorVotesQuorumFraction(_quorumPercentage)
    GovernorTimelockControl(_timelock)
{}
    

// The following functions are overrides required by Solidity.

//this is my attempt to override the function but i dont know how to deal with the bytes 
//memory argument
function _countVote(
    uint256 proposalId,
    address account,
    uint8 support,
    uint256 weight,
    bytes memory // params
) internal override {
//    super._countVote(proposalId,account,support,weight,*);
}


function votingDelay()
    public
    view
    override(IGovernor, GovernorSettings)
    returns (uint256)
{
    // return super.votingDelay();
}

function votingPeriod()
    public
    view
    override(IGovernor, GovernorSettings)
    returns (uint256)
{
    return super.votingPeriod();
}

function quorum(uint256 blockNumber)
    public
    view
    override(IGovernor, GovernorVotesQuorumFraction)
    returns (uint256)
{
    return super.quorum(blockNumber);
}

function state(uint256 proposalId)
    public
    view
    override(Governor, GovernorTimelockControl)
    returns (ProposalState)
{
    return super.state(proposalId);
}

function propose(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, string memory description)
    public
    override(Governor, IGovernor)
    returns (uint256)
{
    return super.propose(targets, values, calldatas, description);
}

function proposalThreshold()
    public
    view
    override(Governor, GovernorSettings)
    returns (uint256)
{
    return super.proposalThreshold();
}

function _execute(uint256 proposalId, address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)
    internal
    override(Governor, GovernorTimelockControl)
{
    super._execute(proposalId, targets, values, calldatas, descriptionHash);
}

function _cancel(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, bytes32 descriptionHash)
    internal
    override(Governor, GovernorTimelockControl)
    returns (uint256)
{
    return super._cancel(targets, values, calldatas, descriptionHash);
}

function _executor()
    internal
    view
    override(Governor, GovernorTimelockControl)
    returns (address)
{
    return super._executor();
}

function supportsInterface(bytes4 interfaceId)
    public
    view
    override(Governor, GovernorTimelockControl)
    returns (bool)
{
    return super.supportsInterface(interfaceId);
}

}

您离解决方案更近了...

只需更改此行:super._countVote(proposalId,account,support,weight,*);

不要使用此符号 * 来省略最后一个参数,请尝试使用单引号。

这应该有效: super._countVote(proposalId,account,support,weight,'');