0

So basically I'm trying to make something like that. Btw. Logic is not important.

modifier validateValue(uint fee){ if(msg.value != ((0.1 ether) * fee)) revert(); _; }

modifier checkFee(address payOutAddr){
    uint begin = 30 * uint(payment[phoneBook[payOutAddr]].paymentsCount);
    uint end = begin + 15;
    uint cycleOfContract = now - startDate;
    if(begin < cycleOfContract && cycleOfContract < end){
        return validateValue(1);
    }
    else {
        uint totalFee = (int(cycleOfContract/30) + 1) * 0.02 ether;
        return validateValue(totalFee);
    }
}

I want to make a modifier returning modifier, but this can't compile. Is there a way to make something like that?

1

I think you could use a function validateValue instead of returning modifier from a modifier. I think the following code should solve the problem. I don't have your complete code so I could not test it, but hopefully, this will work.

modifier checkFee(address payOutAddr){
    uint begin = 30 * uint(payment[phoneBook[payOutAddr]].paymentsCount);
    uint end = begin + 15;
    uint cycleOfContract = now - startDate;
    if(begin < cycleOfContract && cycleOfContract < end){
        if(!validateValue(1,msg.value)) revert();
        _;
    }
    else {
        uint totalFee = (int(cycleOfContract/30) + 1) * 0.02 ether;
         if(!validateValue(totalFee,msg.value)) revert();
        _;
    }
}

function validateValue(uint fee, uint amount) constant returns (bool){
    if(amount != ((0.1 ether) * fee)) return false; 
    else return true;
}

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.