Reputation: 522
This is a tough issue to explain, I will try my best:
I wrote a contract that updates the ownership of real estate house. I have a seller (owner), buyer and some other functions.
But I want this contract to be a temporary contract. Since the seller deployed it, the buyer has 30 seconds (for example) to sign the contract. If the buyer will not sign the contract in time, the contract will do something (Self-destruction for example). The signing is a change of bool property from false to true.
I wrote a modifier that explains my goal:
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
This modifier works great in a function call, But I want these actions to be performed automatically.
My requirement is a little bit similar to a thread run. Is it possible to do it using solidity?
Upvotes: 1
Views: 253
Reputation: 1740
It's impossible to automatically change the contract status/data without a transaction. But you can check the timestamp when receiving the next transaction, and if it has exceeded 30 sec from creation, just ignore it and run self destruct.
Also, notice that the timestamp in ethereum is not the actual timestamp of the transaction creation but the timestamp of that block.
Upvotes: 1