In the Ethereum Wiki it is stated that you can delay a smart contract's action in this defined way :
struct RequestedWithdrawal { uint amount; uint time; } mapping (address => uint) private balances; mapping (address => RequestedWithdrawal) private requestedWithdrawals; uint constant withdrawalWaitPeriod = 28 days; // 4 weeks function requestWithdrawal() public { if (balances[msg.sender] > 0) { uint amountToWithdraw = balances[msg.sender]; balances[msg.sender] = 0; // for simplicity, we withdraw everything; // presumably, the deposit function prevents new deposits when withdrawals are in progress requestedWithdrawals[msg.sender] = RequestedWithdrawal({ amount: amountToWithdraw, time: now }); } } function withdraw() public { if(requestedWithdrawals[msg.sender].amount > 0 && now > requestedWithdrawals[msg.sender].time + withdrawalWaitPeriod) { uint amountToWithdraw = requestedWithdrawals[msg.sender].amount; requestedWithdrawals[msg.sender].amount = 0; if(!msg.sender.send(amountToWithdraw)) { throw; } } }
Using "now", though it is stated here that :
The timestamp of the block can be manipulated by the miner, and so should not be used for critical components of the contract.
It is quite confusing, and I wonder both how one can safely delay a contract's action and how one can get trusted time from within a smart contract.