2017-09-19 13 views
0

몇 가지 스마트 계약 템플릿을 살펴보고 여러 자습서를 살펴 보았습니다. 그러나 그들 중 어느 누구도 그 코드의 세부 사항을 한 줄씩 살펴 보지 않습니다. 나는 회사 이익의 배당금을 고객에게주는 함수를 추가하고 싶습니다. 어디에 추가해야합니까? 예를 들어, 다음 코드 템플릿, 코드 블록에 내 함수 giveBackDividend()를 추가 할 수 있습니까?자체 정의 된 기능을위한 스마트 계약 템플릿을 수정하는 방법

누구나 ICO를위한 스마트 계약의 일반적인 구조를 통해 나를 걸을 수 있습니까?

contract HubiiCrowdsale is Crowdsale { 
    uint private constant chunked_multiple = 18000 * (10 ** 18); // in wei 
    uint private constant limit_per_address = 100000 * (10 ** 18); // in wei 
    uint private constant hubii_minimum_funding = 17000 * (10 ** 18); // in wei 
    uint private constant token_initial_supply = 0; 
    uint8 private constant token_decimals = 15; 
    bool private constant token_mintable = true; 
    string private constant token_name = "Hubiits"; 
    string private constant token_symbol = "HBT"; 
    uint private constant token_in_wei = 10 ** 15; 
    // The fraction of 10,000 out of the total target tokens that is used to mint bonus tokens. These are allocated to the team's multisig wallet. 
    uint private constant bonus_base_points = 3000; 
    function HubiiCrowdsale(address _teamMultisig, uint _start, uint _end) Crowdsale(_teamMultisig, _start, _end, hubii_minimum_funding) public { 
     PricingStrategy p_strategy = new FlatPricing(token_in_wei); 
     CeilingStrategy c_strategy = new FixedCeiling(chunked_multiple, limit_per_address); 
     FinalizeAgent f_agent = new BonusFinalizeAgent(this, bonus_base_points, _teamMultisig); 
     setPricingStrategy(p_strategy); 
     setCeilingStrategy(c_strategy); 
     // Testing values 
     token = new CrowdsaleToken(token_name, token_symbol, token_initial_supply, token_decimals, _teamMultisig, token_mintable); 
     token.setMintAgent(address(this), true); 
     token.setMintAgent(address(f_agent), true); 
     token.setReleaseAgent(address(f_agent)); 
     setFinalizeAgent(f_agent); 
    } 

    // These two setters are present only to correct block numbers if they are off from their target date by more than, say, a day 
    function setStartingBlock(uint startingBlock) public onlyOwner inState(State.PreFunding) { 
     require(startingBlock > block.number && startingBlock < endsAt); 
     startsAt = startingBlock; 
    } 

    function setEndingBlock(uint endingBlock) public onlyOwner notFinished { 
     require(endingBlock > block.number && endingBlock > startsAt); 
     endsAt = endingBlock; 
    } 

}

답변

1

TL; DR; 이 코드는 단순히 블록 번호를 사용하여 ICO의 시작과 끝을 정의하지만 토큰을 구현하는 데 다양한 다른 소스를 확장합니다. 수정해도 문제는 발생하지 않습니다.

나는 당신이 틀린 장소에서 시작한다고 생각합니다. 첫째, 기존 기능을 함의하지 않고 계약에 코드를 추가 할 수 있습니다. 약간 조숙하다는 것을 알고 있지만 다음날에 토큰을 설계해야하는 ERC20 및 ERC223 표준에 대해 2 가지 자습서를 수행 할 계획입니다. 이렇게하면 다음 ICO 생각하고 싶지 토큰에 대한 계약을 체결 한 후

contract ERC223 { 
    uint public totalSupply; 
    function balanceOf(address who) constant returns (uint); 
    function name() constant returns (string _name); 
    function symbol() constant returns (string _symbol); 
    function decimals() constant returns (uint8 _decimals); 
    function totalSupply() constant returns (uint256 _supply); 
    function transfer(address to, uint value) returns (bool ok); 
    function transfer(address to, uint value, bytes data) returns (bool ok); 
    function transfer(address to, uint value, bytes data, string custom_fallback) returns (bool ok); 
    event Transfer(address indexed from, address indexed to, uint value, bytes indexed data); 
} 

https://www.youtube.com/channel/UCaWes1eWQ9TbzA695gl_PtA

ERC20

contract ERC20 { 
    function totalSupply() constant returns (uint totalSupply); 
    function balanceOf(address _owner) constant returns (uint balance); 
    function transfer(address _to, uint _value) returns (bool success); 
    function transferFrom(address _from, address _to, uint _value) returns (bool success); 
    function approve(address _spender, uint _value) returns (bool success); 
    function allowance(address _owner, address _spender) constant returns (uint remaining); 
    event Transfer(address indexed _from, address indexed _to, uint _value); 
    event Approval(address indexed _owner, address indexed _spender, uint _value); 
} 

ERC223에 게시됩니다. ICO를 사용하여 시작점과 끝점을 정의해야합니다. 이 위의 예에서 당신이 가지고있는 이유입니다 블록을 기반으로합니다

require(startingBlock > block.number && startingBlock < endsAt); 

require(endingBlock > block.number && endingBlock > startsAt); 

이 계약은 "Crowdsale"라는 계약에서 상속을 어디에 구현 외모의 대부분 그것이 나오는 것처럼. 이것에 대한 전체 소스 코드는 https://etherscan.io/address/0xb9aac097f4dadcd6f06761eb470346415ef28d5a#code에 있습니다.이 토큰은 ERC20 표준을 기반으로하며 상속 트리가 상당히 있습니다.

토큰에 대한 코드는 BasicToken로 수행됩니다

/** 
* @title Basic token 
* @dev Basic version of StandardToken, with no allowances. 
*/ 
contract BasicToken is ERC20Basic { 
    using SafeMath for uint; 

    mapping(address => uint) balances; 

    /** 
    * Obsolete. Removed this check based on: 
    * https://blog.coinfabrik.com/smart-contract-short-address-attack-mitigation-failure/ 
    * @dev Fix for the ERC20 short address attack. 
    * 
    * modifier onlyPayloadSize(uint size) { 
    * require(msg.data.length >= size + 4); 
    * _; 
    * } 
    */ 

    /** 
    * @dev transfer token for a specified address 
    * @param _to The address to transfer to. 
    * @param _value The amount to be transferred. 
    */ 
    function transfer(address _to, uint _value) public returns (bool success) { 
    balances[msg.sender] = balances[msg.sender].sub(_value); 
    balances[_to] = balances[_to].add(_value); 
    Transfer(msg.sender, _to, _value); 
    return true; 
    } 

    /** 
    * @dev Gets the balance of the specified address. 
    * @param _owner The address to query the the balance of. 
    * @return An uint representing the amount owned by the passed address. 
    */ 
    function balanceOf(address _owner) public constant returns (uint balance) { 
    return balances[_owner]; 
    } 

} 

원본을 따라하려는 경우가 괜찮 ERC20 및 ERC223 표준의 비트를 사용하지만, 약간의 혼란 것 같습니다 암호.