已部署合同中的合同问题-实体

时间:2018-06-30 13:24:01

标签: ethereum solidity remix

我已经部署了以下合同,并具有CampaignFactory合同的地址。我使用它的地址并在重新混合中部署它,当我尝试部署它时,调用createCampaign方法,该方法调用另一个协定并将其地址添加到数组中。当我调用方法getCampaigns来返回地址数组时,尽管添加了地址,但我还是得到了长度为0的数组:

pragma solidity ^0.4.0;

contract CampaignFactory {
    address[] public deployedCampaigns;

    function createCampaign(uint minimum) public {
        address newCampaign = new Campaign(minimum, msg.sender);
        deployedCampaigns.push(newCampaign);
    }

    function getDeployedCampaigns() public view returns(address[]) {
        return deployedCampaigns;
    }
}

contract Campaign {
    struct Request {
        string description;
        uint value;
        address recipient;
        bool complete;
        uint approvalCount;
        mapping(address => bool) approvals;
    }

    Request[] public requests;
    address public manager;
    uint public minimumContribution;
    mapping(address => bool) public approvers;
    uint public approversCount;

    modifier restricted() {
        require(msg.sender == manager);
        _;
    }

    function Campaign(uint minimum, address creator) public {
        manager = creator;
        minimumContribution = minimum;
    }

    function contribute() public payable {
        require(msg.value > minimumContribution);
        approvers[msg.sender] = true;
        approversCount++;
    }

    function createRequest(string description, uint value, address recipient)    public restricted {
        Request memory newRequest = Request({
            description: description,
            value: value,
            recipient: recipient,
            complete: false,
            approvalCount: 0
        });
        requests.push(newRequest);
    }

    function approveRequest(uint index) public {
        Request storage request = requests[index];
        require(approvers[msg.sender]);
        require(!request.approvals[msg.sender]);

        request.approvals[msg.sender] = true;
        request.approvalCount++;
    }

    function finalizeRequest(uint index) public restricted {
        require(!requests[index].complete);
    require(requests[index].approvalCount > approversCount / 2);
        requests[index].complete = true;
    requests[index].recipient.transfer(requests[index].value);
    }
}

0 个答案:

没有答案