如何在不调用任何函数的情况下让合约采取行动?

How to make a contract take action without calling any function?

这个问题很难解释,我会尽力的:

我写了一份更新房地产房屋所有权的合同。我有卖家(所有者)、买家和其他一些功能。

但我希望这份合同是一份临时合同。自从卖方部署它以来,买方有 30 秒(例如)来签署合同。 如果买方不及时签订合同,合同将做一些事情(例如自毁)。签名是 bool 属性 从 false 到 true 的变化。

我写了一个修饰符来解释我的目标:

 modifier upTo30Seconds
    {
        if( now-timeOfContractCreation > 30)
        {
            if(isContractPayed && buyerSign == false)
            {
                emit  notifyCancelOffer(address(this), buyerAddress , oldOwnerAddress); //notifyCancelOffer 
                selfdestruct(buyerAddress); //Destruct the contract and return ether to the buyer

            }
        }
        _;
    } 
    //'timeOfContractCreation' is another property, initialized in the constructor, and its means the time of deployment (since 01/01/1970)

    //'now' is a solidity method which returns the time passed in seconds since 01/01/1970 

这个修饰符在函数调用中效果很好,但我希望这些操作自动执行。

我的需求有点类似于线程运行。 是否可以使用 solidity 来实现?

没有交易就不可能自动更改合约status/data。但是你可以在收到下一个交易时检查时间戳,如果它从创建开始超过30秒,就忽略它并运行自毁。

另外,请注意以太坊中的时间戳不是交易创建的实际时间戳,而是该块的时间戳。