简体   繁体   English

如何制作在每个合约调用中调用的 function? – 坚固性

[英]How do I make a function that is called on every contract call? – Solidity

I need to make a function that will be called each time someone called my contract.我需要制作一个 function ,每次有人打电话给我的合同时都会调用它。 And I need to do it without using modifiers because there are many functions in my contract and I use third-party contracts.而且我需要在不使用修饰符的情况下这样做,因为我的合约中有很多功能,而且我使用第三方合约。

How can I do it?我该怎么做?

You can inherit third-party contracts and make a new child contract and then modify each function with a modifier you defined in the child contract, that's the only way to do.您可以继承第三方合约并创建新的子合约,然后使用您在子合约中定义的修饰符修改每个 function,这是唯一的方法。

Example:例子:

Contract ThirdParty {
    address owner;

    function f() public {}
}


Contract Child is ThirdParty {

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }

    function f() public onlyOwner {}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM