【问题标题】:How to make a contract take action without calling any function?如何在不调用任何函数的情况下让合约采取行动?
【发布时间】:2019-11-20 13:56:45
【问题描述】:

这是一个很难解释的问题,我会尽力而为:

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

但我希望这份合同是临时合同。由于卖方部署它,买方有 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来做到这一点?

【问题讨论】:

    标签: solidity


    【解决方案1】:

    没有交易就不可能自动更改合约状态/数据。但是你可以在收到下一笔交易的时候检查时间戳,如果超过了30秒,就忽略它,运行self destruct。

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

    【讨论】:

    • 我明白了。这篇文章是未来solidity开发者思考的一个点
    猜你喜欢
    • 2020-11-25
    • 1970-01-01
    • 1970-01-01
    • 2018-02-23
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多