javascript 基本的kickstarter合同

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 基本的kickstarter合同相关的知识,希望对你有一定的参考价值。

pragma solidity ^0.4.17;

contract campaignFactory {
    address[] public deployedContracts;
    
    function createCampaign(uint minimum) public {
        address newCampaign = new Campaign(minimum, msg.sender);
        deployedContracts.push(newCampaign);
    }
    
    function getDeployedContacts () public view returns (address[]) {
        return deployedContracts;
    }
}

contract Campaign {
    // decalre a new struct type called Request
    struct Request {
        string description;
        uint value;
        address recipient;
        bool complete;
        uint approvalCount;
        mapping(address => bool) approvals;
        
    }
    
     modifier restricted () {
        require(msg.sender == manager);
        _;
    }
    
    address public manager;
    // create a mapping to hold all approvers/contributers
    mapping (address => bool) public approvers;
    uint public approversCount;
    uint public minimumContribution;
    // create an array of type struct based on our Request struct called requests 
    Request[] public requests;
    // initiate contract manager abn minimumcContribution variables
    function Campaign (uint amount, address creator) public {
       manager = creator;
       minimumContribution = amount;
    }
    
    function contribute () public payable {
        require(msg.value > minimumContribution);
        // Add new approver into our mapping
        approvers[msg.sender] = true;
        approversCount++;
    }
    // create a new request for funds passing info into a newRequest object called Request
    function createRequest (string description, uint value, address recipient)
    public restricted {
        Request memory newRequest = Request({
            description: description,
            value: value,
            recipient: recipient,
            complete: false,
            approvalCount: 0
        });
   // push this struct instance into a requests array
        requests.push(newRequest);
    }
    
    function approveRequest(uint index) public {
        Request storage request = requests[index];
        //require(msg.sender != manager);
        require(approvers[msg.sender]);
        require(!request.approvals[msg.sender]);
        
        request.approvals[msg.sender] = true;
        request.approvalCount++;
    }
    
    function finalizeRequest(uint index) public restricted {
        // create a pointer to requests array to quiery
        Request storage request = requests[index];
        require(!request.complete);
        require(request.approvalCount > approversCount / 2);
        request.recipient.transfer(request.value);
        request.complete = true;
    }
}

以上是关于javascript 基本的kickstarter合同的主要内容,如果未能解决你的问题,请参考以下文章

pxe+kickstart自动装机详解

kickstart无人值守安装

cent7中kickstart初步探究

CentOS6 PXE+Kickstart无人值守安装

运维之系统服务篇------ 4.批量装机环境 配置PXE引导 kickstart自动应答

1.1.环境的基本配置