如何覆盖openzeppelin _countVote函数consorcountingsimple.sol文件?

发布于 2025-01-29 06:25:38 字数 3872 浏览 4 评论 0原文

我正在使用Openzeppelin制作DAO,然后下载了他们从Openzeppelin合同向导提供的治理合同。一旦我将此文件导入到混音IDE中后,出现了一个错误,说

“函数必须覆盖指定但不会覆盖任何内容”,

所以我遵循该错误到convortorCountingSimple.sol.sol文件,发现这是_countVote函数,但我无法似乎覆盖了它。我想我只是缺少简单的东西,但是当功能中的最后一个参数是“ by by by by nose”而没有声明的名称时,我不知道该如何覆盖它最后一个论点。

// 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);
}

}

I am making a DAO using openzeppelin and I downloaded the governance contract that they provide from the openzeppelin contract wizard. once I had imported this file into remix IDE an error popped up saying

"Function has to override specified but does not override anything"

so I followed that error to the GovernorCountingSimple.sol file and saw that it was the _countVote function but I can't seem to override it. I think I am just missing something simple but I don't know how to override it when the last argument within the function is "bytes memory" with no declared name and I cant seem to just call the super statement on the function to pass the last argument.

// 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);
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人海汹涌 2025-02-05 06:25:38

您更接近解决方案...

只需更改以下行:super._countvote(proposalID,帐户,支持,权重,*);

而不是使用此符号* to省略最后一个参数,尝试单引号。

这应该有效:
super._countvote(proposalID,帐户,支持,权重,'');

You was closer to the solution...

Just change this line: super._countVote(proposalId,account,support,weight,*);

Instead of using this symbol * to omit last parameter, try with single quotes.

This should work:
super._countVote(proposalId,account,support,weight,'');

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文