1

I have a function that is payable. Upon some checks, if it meet the condition, it should write some changes BUT refund the payable amount that was just sent.

See:

function rent(uint256 tokenId, uint256 period, address payable owner) onlyOffPause() payable public returns (bool) {


require(period > minMonthBasic && period <= maxMonthBasic);

require(owner == ownerOf(tokenId));




//this allow owner to change renting price so it can be used when due date care.

//if marked as rented, require the sender to be the actual renter. this allow renew priority under 31 grace before evict. If not rented, accept anyone to start a rent.
if(plotdata[tokenId]._rented){
    require(msg.sender == renterOf(tokenId));

    //require the basic care date to be due, this giving a 31 days grace for any owner or even renter

    require(checkBasicCare(tokenId) == true);

    //if rentingPrice 0, removing renter and refunding them for the period left AND CANCEL THIS FUNCTION

    if(plotdata[tokenId]._lastRentingPrice == 0){
        plotdata[tokenId]._rented = false;

        plotdata[tokenId]._renterOf = address(0);

        // !!! IT SHOULD NOT ACCEPT THE MONEY AT THIS POINT BUT STILL KEEP THE PREVIOUS CHANGE AT THE RENTER OF AND RENTED

    }

}

...
  • 1
    So what exactly is the question? You can simply do msg.sender.transfer(msg.value) if that's what you're asking (didn't see a single question mark in this post). – goodvibration Sep 10 at 22:09
  • Oh much appreciated. I thought it was better to not assume money would be received in the contract – btc4cash Sep 10 at 22:10
  • 1
    @btc4cash It sound like a wrong abstraction to me, isn't it better to create a separate function that doesn't accept payments for that particular case? – Ismael Sep 11 at 3:26
  • yeah but that would require to base on the fact user may never call it. Best for us at this point is to send back msg.value – btc4cash Sep 12 at 23:58
1

So what exactly is the question? You can simply do msg.sender.transfer(msg.value) if that's what you're asking (didn't see a single question mark in this post). – goodvibration

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.