PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, July 28, 2022

[FIXED] How to use conditionals with modifiers?

 July 28, 2022     blockchain, ethereum, evm, remix, solidity     No comments   

Issue

I need to complete this task to let the function work only if the modifiers (that should be correct) work as shown in the image. Basically compPurch has always to be true and also realBuyer OR timeBought have to be true.

    modifier compPurch() {
        require(state == State.Locked, "it's not locked");
        _;
        time = block.timestamp;
    }

    modifier realBuyer() {
        require(msg.sender == buyer, "you're not the buyer");
        _;
    }

    modifier timeBought() {
        require(block.timestamp >= time + 5, "wait 5 mins fro purchase");
        _;
    }
}

I created all modifiers, but I don't know how to use AND & OR conditionals to make them work as intended in the task


Solution

Multiple modifiers are always joined with the AND operator.

So you can use one modifier for the 1st condition, and one modifier for the 2nd condition. The subconditions within the 2nd condition need to be in the same modifier.

modifier compPurch() {
    // ...
}

modifier realBuyerOrTimeBought() {
    // explicit OR in the condition
    require(msg.sender == buyer || block.timestamp >= time + 5);
    // ...
}

// implicitly joined with the AND operator
function foo() public compPurch realBuyerOrTimeBought {
}


Answered By - Petr Hejda
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing