Package escrow holds the rules of a single-builder bounty escrow: the Quest type, its states and every legal move between them.
The package is pure. It holds no coins, no banker and no storage. A realm that imports it keeps the *Quest values, moves the coins, and asks this package whether a move is allowed. Every move takes the acting address and the current block height as arguments, so the rules can be tested without a chain and cannot be bypassed by the caller's own logic.
Moves that can release money (Cancel, Unclaim, Release, Approve, Reject, ClaimPayout) return a Payout telling the realm exactly whom to pay and how much; a zero Payout (Due() == false) means no coins move. A non-zero Payout is only ever returned together with a move into a final state (Paid or Cancelled), and a final quest accepts no further move, so a quest can produce at most one non-zero Payout.
A realm using this package must:
- lock exactly Reward() in its own balance before calling NewQuest,
- apply the move first and send the coins of the returned Payout after,
- treat any returned error as fatal (panic) so the transaction reverts.
States and moves:
Example
1(none) Post (NewQuest) anyone -> Open
2Open Claim anyone except the poster -> Claimed
3Open Cancel poster -> Cancelled refund Reward to poster
4Claimed Cancel ("close") poster -> Claimed, closing
5Submitted Cancel ("close") poster -> Submitted, closing
6Claimed Submit(link) builder, until work deadline -> Submitted
7Claimed Unclaim builder -> Open (closing: Cancelled, refund)
8Claimed Release anyone, after work deadline -> Open (closing: Cancelled, refund)
9Submitted Approve poster -> Paid pay Reward to builder
10Submitted Reject(reason) poster, until review deadline -> Open (closing: Cancelled, refund)
11Submitted ClaimPayout builder, after review deadline-> Paid pay Reward to builder
Closing: a poster cannot take the reward back while a builder holds the quest, but can close it. The current builder keeps every right (submit, get approved, claim the timeout payout); any move that would put the quest back to Open ends it instead and refunds the poster. So a builder can hold a closing quest for at most one work window, and nobody can re-claim it. Closing cannot be undone.
Deadlines are block heights. "Until" a deadline includes the deadline block itself; "after" a deadline starts at the next block.