Skip to content

Why not use revert() in the refund code? #1

Description

@aleybovich

@sandeeppanda92

In the following code:

function () external payable {
      uint256 tokensThatWillBeMintedAfterPurchase = msg.value.mul(rate);
      if ((stage == CrowdsaleStage.PreICO) && (token.totalSupply() + tokensThatWillBeMintedAfterPurchase > totalTokensForSaleDuringPreICO)) {
        msg.sender.transfer(msg.value); // Refund them
        EthRefunded("PreICO Limit Hit");
        return;
      }

      buyTokens(msg.sender);

      if (stage == CrowdsaleStage.PreICO) {
          totalWeiRaisedDuringPreICO = totalWeiRaisedDuringPreICO.add(msg.value);
      }
  }

why are you sending ETH back like msg.sender.transfer(msg.value); (which will spend the contract's own gas) instead of simply calling revert() - that will revert the whole transaction, refunding the user their ETH and gas leftovers if any.

Disclaimer: I am only learning Solidity and Ehereum smart contracts, so there is a good possibility that I am wrong. In that case, please explain me why - that will be very helpful for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions