github.com/klaytn/klaytn@v1.12.1/contracts/reward/contract/KlaytnReward.sol (about)

     1  // Copyright 2018 The klaytn Authors
     2  //
     3  // This file is part of the klaytn library.
     4  //
     5  // The klaytn library is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Lesser General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // The klaytn library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  // GNU Lesser General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Lesser General Public License
    16  // along with the klaytn library. If not, see <http://www.gnu.org/licenses/>.
    17  
    18  pragma solidity ^0.4.24;
    19  
    20  contract KlaytnReward {
    21  
    22      uint public totalAmount;
    23      mapping(address => uint256) public balanceOf;
    24  
    25      function KlaytnReward() public {
    26      }
    27  
    28      function () payable public {
    29          uint amount = msg.value;
    30          balanceOf[msg.sender] += amount;
    31          totalAmount += amount;
    32      }
    33  
    34      function reward(address receiver) payable public {
    35          uint amount = msg.value;
    36          balanceOf[receiver] += amount;
    37          totalAmount += amount;
    38      }
    39  
    40      function safeWithdrawal() public {
    41          uint amount = balanceOf[msg.sender];
    42          balanceOf[msg.sender] = 0;
    43          if (amount > 0) {
    44               if (msg.sender.send(amount)) {
    45  
    46               } else {
    47                  balanceOf[msg.sender] = amount;
    48               }
    49          }
    50      }
    51  }