Time-Windows Exercise
- Reading time: 2 mins
- Discuss on Slack
In the previous chapter, you learned about enforcing a time-window to ensure that a transaction is notarized within a range of acceptable times.
Now, how do you use this enforcement of a time-window to make the car sales flow more robust and enforce the expiration date on the sales proposal? What you want to achieve is:
- The proposal has an expiration date.
- The buyer can only accept before this date.
- And the seller can only reject the acceptance after this date.
Try to implement that on your own before looking below.
The way to go is:
- The
SalesProposal
defines an expiration date as a point in time in the future. - The offer flow adds to the transaction a time-window with an “until” end.
- On
Offer
, the contract checks that the expiration date is after this “until” end. If it is not, the buyer is not able to buy. - The accept flow adds to the transaction a time-window with an “until” end too.
- On
Accept
, the contract checks that the expiration date is after this “until” end. - The reject flow adds to the transaction a time-window with a “from” end too.
- On
Reject
, the contract checks that the expiration date is before this “from” end.
As you can see:
- The contract verifies that the time-window is on the right side of the expiration date.
- The notary verifies that it is signed within the time-window.
The interaction of these 2 attestations in effect enforces the expiration date.
Go ahead and add an expiration date to your project before moving on to the next chapter for an example solution.