如何使合同在不调用任何函数的情况下执行操作



这是一个很难解释的问题,我会尽我所能:

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

但我希望这份合同是一份临时合同。由于卖方部署了它,买方有30秒的时间(例如(签署合同。如果买方不及时签署合同,合同就会有所作为(例如自毁(。签名是布尔属性从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 

这个修饰符在函数调用中非常有效,但我希望这些操作能够自动执行。

我的要求有点类似于线程运行。用坚固性做这件事可能吗?

如果没有交易,就不可能自动更改合同状态/数据。但是,您可以在接收下一个事务时检查时间戳,如果它从创建起已经超过30秒,则忽略它并运行自毁。

此外,请注意,以太坊中的时间戳不是事务创建的实际时间戳,而是该块的时间戳。

最新更新