Contract-Invocation

這是一個具有固定供應的正確契約程式碼嗎?

  • November 3, 2017

誰能告訴我常量私有 unite256 的功能是什麼?是否可以選擇增加此契約中的供應量?

pragma solidity ^0.4.17;

library SafeMathMod {// Partial SafeMath Library

   function sub(uint256 a, uint256 b) internal pure returns (uint256 c) {
       require((c = a - b) < a);
   }

   function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
       require((c = a + b) > a);
   }
}

contract ETHDEX {//is inherently ERC20
   using SafeMathMod for uint256;

   /**
   * @constant name The name of the token
   * @constant symbol  The symbol used to display the currency
   * @constant decimals  The number of decimals used to dispay a balance
   * @constant totalSupply The total number of tokens times 10^ of the number of decimals
   * @constant MAX_UINT256 Magic number for unlimited allowance
   * @storage balanceOf Holds the balances of all token holders
   * @storage allowed Holds the allowable balance to be transferable by another address.
   */

   string constant public name = "ETHDEX";

   string constant public symbol = "EDEX";

   uint8 constant public decimals = 8;

   uint256 constant public totalSupply = 21000000e8;

   uint256 constant private MAX_UINT256 = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;

   mapping (address => uint256) public balanceOf;

   mapping (address => mapping (address => uint256)) public allowed;

   event Transfer(address indexed _from, address indexed _to, uint256 _value);

   event TransferFrom(address indexed _spender, address indexed _from, address indexed _to, uint256 _value);

   event Approval(address indexed _owner, address indexed _spender, uint256 _value);

   function ETHDEX() public {balanceOf[msg.sender] = totalSupply;}

   /**
   * @notice send `_value` token to `_to` from `msg.sender`
   *
   * @param _to The address of the recipient
   * @param _value The amount of token to be transferred
   * @return Whether the transfer was successful or not
   */
   function transfer(address _to, uint256 _value) public returns (bool success) {
       /* Ensures that tokens are not sent to address "0x0" */
       require(_to != address(0));
       /* Prevents sending tokens directly to contracts. */
       require(isNotContract(_to));

       /* SafeMathMOd.sub will throw if there is not enough balance and if the transfer value is 0. */
       balanceOf[msg.sender] = balanceOf[msg.sender].sub(_value);
       balanceOf[_to] = balanceOf[_to].add(_value);
       Transfer(msg.sender, _to, _value);
       return true;
   }

   /**
   * @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
   *
   * @param _from The address of the sender
   * @param _to The address of the recipient
   * @param _value The amount of token to be transferred
   * @return Whether the transfer was successful or not
   */
   function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
       /* Ensures that tokens are not sent to address "0x0" */
       require(_to != address(0));
       /* Ensures tokens are not sent to this contract */
       require(_to != address(this));

       uint256 allowance = allowed[_from][msg.sender];
       /* Ensures sender has enough available allowance OR sender is balance holder allowing single transsaction send to contracts*/
       require(_value <= allowance || _from == msg.sender);

       /* Use SafeMathMod to add and subtract from the _to and _from addresses respectively. Prevents under/overflow and 0 transfers */
       balanceOf[_to] = balanceOf[_to].add(_value);
       balanceOf[_from] = balanceOf[_from].sub(_value);

       /* Only reduce allowance if not MAX_UINT256 in order to save gas on unlimited allowance */
       /* Balance holder does not need allowance to send from self. */
       if (allowed[_from][msg.sender] != MAX_UINT256 && _from != msg.sender) {
           allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
       }
       Transfer(_from, _to, _value);
       return true;
   }

   /**
   * @dev Transfer the specified amounts of tokens to the specified addresses.
   * @dev Be aware that there is no check for duplicate recipients.
   *
   * @param _toAddresses Receiver addresses.
   * @param _amounts Amounts of tokens that will be transferred.
   */
   function multiPartyTransfer(address[] _toAddresses, uint256[] _amounts) public {
       /* Ensures _toAddresses array is less than or equal to 255 */
       require(_toAddresses.length <= 255);
       /* Ensures _toAddress and _amounts have the same number of entries. */
       require(_toAddresses.length == _amounts.length);

       for (uint8 i = 0; i < _toAddresses.length; i++) {
           transfer(_toAddresses[i], _amounts[i]);
       }
   }

   /**
   * @dev Transfer the specified amounts of tokens to the specified addresses from authorized balance of sender.
   * @dev Be aware that there is no check for duplicate recipients.
   *
   * @param _from The address of the sender
   * @param _toAddresses The addresses of the recipients (MAX 255)
   * @param _amounts The amounts of tokens to be transferred
   */
   function multiPartyTransferFrom(address _from, address[] _toAddresses, uint256[] _amounts) public {
       /* Ensures _toAddresses array is less than or equal to 255 */
       require(_toAddresses.length <= 255);
       /* Ensures _toAddress and _amounts have the same number of entries. */
       require(_toAddresses.length == _amounts.length);

       for (uint8 i = 0; i < _toAddresses.length; i++) {
           transferFrom(_from, _toAddresses[i], _amounts[i]);
       }
   }

   /**
   * @notice `msg.sender` approves `_spender` to spend `_value` tokens
   *
   * @param _spender The address of the account able to transfer the tokens
   * @param _value The amount of tokens to be approved for transfer
   * @return Whether the approval was successful or not
   */
   function approve(address _spender, uint256 _value) public returns (bool success) {
       /* Ensures address "0x0" is not assigned allowance. */
       require(_spender != address(0));

       allowed[msg.sender][_spender] = _value;
       Approval(msg.sender, _spender, _value);
       return true;
   }

   /**
   * @param _owner The address of the account owning tokens
   * @param _spender The address of the account able to transfer the tokens
   * @return Amount of remaining tokens allowed to spent
   */
   function allowance(address _owner, address _spender) public view returns (uint256 remaining) {
       remaining = allowed[_owner][_spender];
   }

   function isNotContract(address _addr) private view returns (bool) {
       uint length;
       assembly {
       /* retrieve the size of the code on target address, this needs assembly */
       length := extcodesize(_addr)
       }
       return (length == 0);
   }

   // revert on eth transfers to this contract
   function() public payable {revert();}
}

是否可以選擇增加本契約中的供應量

不可以。由於您的總供應量標記為不變,因此無法增加(甚至減少)。

常量私有unite256的作用是什麼

  • **常量:**狀態變數可以聲明為常量,編譯器不會為這些變數保留儲存槽,每次出現都會被它們的常量值替換。
  • 私有: 私有函式和狀態變數僅對定義它們的合約可見,而在派生合約中不可見。
  • int / uint:各種大小的有符號和無符號整數。關鍵字 uint8 到 uint256,步長為 8(無符號 8 到 256 位)和 int8 到 int256。uint 和 int 分別是 uint256 和 int256 的別名。

**注意:**所有外部觀察者都可以看到契約中的所有內容。將某些東西設為私有隻會阻止其他合約訪問和修改資訊,但它仍然對區塊鏈之外的整個世界可見。

引用自:https://ethereum.stackexchange.com/questions/29870