// SPDX-License-Identifier: MIT pragma solidity ^0.8.24; contract Nook { struct Lockbox {address funder;address recipient;uint64 unlock;uint256 amount;bool released;bytes32 noteHash;} Lockbox[] public lockboxes; bool private entered; event Locked(uint256 indexed id,address indexed funder,address indexed recipient,uint256 amount,uint64 unlock,bytes32 noteHash); event Released(uint256 indexed id,address indexed recipient,address indexed executor,uint256 amount); modifier guard(){require(!entered,"Reentrant");entered=true;_;entered=false;} function lockboxCount() external view returns(uint256){return lockboxes.length;} function create(address recipient,uint64 unlock,bytes32 noteHash) external payable guard returns(uint256 id){ require(recipient!=address(0),"Recipient required");require(msg.value>0,"Amount required"); require(unlock>block.timestamp&&unlock<=block.timestamp+730 days,"Invalid unlock time"); id=lockboxes.length;lockboxes.push(Lockbox(msg.sender,recipient,unlock,msg.value,false,noteHash)); emit Locked(id,msg.sender,recipient,msg.value,unlock,noteHash); } function release(uint256 id) external guard { Lockbox storage box=lockboxes[id];require(!box.released&&block.timestamp>=box.unlock,"Still locked or released"); box.released=true;(bool ok,)=payable(box.recipient).call{value:box.amount}("");require(ok,"Release failed"); emit Released(id,box.recipient,msg.sender,box.amount); } }