solidity - 如何在不调用任何函数的情况下让合约采取行动?
问题描述
这是一个很难解释的问题,我会尽力而为:
我写了一份更新房地产所有权的合同。我有卖家(所有者)、买家和其他一些功能。
但我希望这份合同是一份临时合同。由于卖方部署它,买方有 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来做到这一点?
解决方案
没有交易就不可能自动更改合约状态/数据。但是您可以在收到下一个事务时检查时间戳,如果它从创建开始超过 30 秒,则忽略它并运行自毁。
另外,请注意,以太坊中的时间戳不是交易创建的实际时间戳,而是该块的时间戳。
推荐阅读
- python - 无法单击弹出窗口中的子按钮
- google-bigquery - 将多行合并为 1 个事务数据
- xml - 如何使用 Pentaho 格式化 XML
- git - 没有角色选项时如何授予管理员访问私有存储库的权限
- reactjs - react-leaflet 制作多条折线
- java - 如何解析异常消息并注销?
- sql - 是否有一种 dplyr 方式来编写带有条件的汇总 SQL 查询?
- shell - 在 jenkins 中运行管道 shell 脚本时出错
- ansible - 无论标签如何,Ansible 任务仍然运行
- javascript - 如何使用 javascript 在字符串中查找逗号或其他符号?