website/design/solidity-lab/generated/DeliveryAcceptance.sol

91 lines
4.8 KiB
Solidity

// SPDX-License-Identifier: MIT
// Generated by the OSS Singularity contract lab (roadmap stage 05 first slice).
// SYNTHETIC EXAMPLE — Synthetic delivery-and-acceptance example. Placeholder addresses, a digest
// over the public synthetic artifact and a future deadline; no funds, no
// deployment, no wallet. The lab explains every requested signature; it never
// requests one. Nothing signs or deploys merely because this file exists.
pragma solidity ^0.8.24;
/// @title DeliveryAcceptance — a readable delivery-and-acceptance example.
/// @notice Mirrors the coordination protocol: a contributor delivers immutable
/// revisions, the coordinator requests a revision or accepts exactly
/// the newest one before a deadline. Acceptance completes the record;
/// nothing here transfers value of any kind.
contract DeliveryAcceptance {
// ---- Roles from the agreement (synthetic placeholders) ----
address public immutable contributor = 0x0000000000000000000000000000000000000001;
address public immutable coordinator = 0x0000000000000000000000000000000000000002;
// ---- Delivery reference: sha256 over the delivered bytes ----
// The manifest digest of the synthetic artifact this example stands for.
bytes32 public constant DECLARED_DIGEST = 0x74aebc353c86c6269f80cc8509528ab19b3a1612ac3291bab40f32701454f69b;
// ---- Acceptance policy ----
uint256 public constant DEADLINE = 1830000000;
// ---- Review state: one revision at a time, immutable once recorded ----
uint16 public currentRevision; // 0 means nothing delivered yet
uint16 public acceptedRevision; // 0 means nothing accepted yet
string public revisionRequest; // the coordinator's last note
event DeliveryRecorded(uint16 indexed revision, bytes32 digest, address indexed who);
event RevisionRequested(uint16 indexed revision, string note, address indexed who);
event Accepted(uint16 indexed revision, address indexed who);
error NotContributor();
error NotCoordinator();
error NothingDelivered();
error NotNewestRevision(uint16 newest);
error DuplicateRevision(uint16 revision);
error DeadlinePassed(uint256 now_, uint256 deadline);
error AlreadyAccepted(uint16 revision);
modifier onlyContributor() {
if (msg.sender != contributor) revert NotContributor();
_;
}
modifier onlyCoordinator() {
if (msg.sender != coordinator) revert NotCoordinator();
_;
}
/// @notice The contributor records the next immutable delivery revision.
/// @dev Signature (uint16): the new revision number, one above the
/// current. Reverts for anyone but the contributor, for a repeat
/// of the current revision, or after acceptance already happened.
function recordDelivery(uint16 revision) external onlyContributor {
if (acceptedRevision != 0) revert AlreadyAccepted(acceptedRevision);
if (revision != currentRevision + 1) revert DuplicateRevision(revision);
currentRevision = revision;
emit DeliveryRecorded(revision, DECLARED_DIGEST, msg.sender);
}
/// @notice The coordinator names what a revision is missing. No state
/// beyond the note changes: a revision request never alters or
/// invalidates a recorded delivery.
/// @dev Signature (uint16, string calldata): the revision the note
/// refers to and the note itself. Reverts for anyone but the
/// coordinator or before anything was delivered.
function requestRevision(uint16 revision, string calldata note) external onlyCoordinator {
if (currentRevision == 0) revert NothingDelivered();
if (revision != currentRevision) revert NotNewestRevision(currentRevision);
revisionRequest = note;
emit RevisionRequested(revision, note, msg.sender);
}
/// @notice The coordinator accepts exactly the newest revision before the
/// deadline. Acceptance is final: it completes the record and
/// locks further deliveries, mirroring the off-chain protocol
/// where acceptance binds one exact revision.
/// @dev Signature (uint16): the revision being accepted. Reverts for
/// non-coordinators, stale revisions, a passed deadline, or when
/// acceptance already happened.
function accept(uint16 revision) external onlyCoordinator {
if (acceptedRevision != 0) revert AlreadyAccepted(acceptedRevision);
if (currentRevision == 0) revert NothingDelivered();
if (revision != currentRevision) revert NotNewestRevision(currentRevision);
if (block.timestamp > DEADLINE) revert DeadlinePassed(block.timestamp, DEADLINE);
acceptedRevision = revision;
emit Accepted(revision, msg.sender);
}
}