Last active
April 6, 2018 10:25
-
-
Save moea/876b3e73e5008cb58461b7cf4514ec0a to your computer and use it in GitHub Desktop.
scratch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(let [bid-duration (t/days 10) | |
reveal-duration (t/days 12)] | |
(fsm | |
:store {high-bid 0 | |
high-bidder nil | |
returns {} | |
created (from :time)} | |
:states [:bid (<= bid-duration (t/interval created (:time tx))) | |
:reveal (<= reveal-duration (t/interval created (:time tx))) | |
:finish | |
:cancel] | |
(place-bid [bidder value] | |
(let [store {:high-bid value | |
:high-bidder bidder}] | |
(if-not high-bidder | |
(fsm this :store store) | |
(fsm this :store | |
(assoc store | |
:returns (update returns high-bidder (fnil + 0) high-bid)))))) | |
(^:expose bid :bid [this tx bid] | |
(fsm this :store | |
{:bids (update bids (:sender tx) conj {:bid bid :deposit (:value tx)})})) | |
(^:expose reveal :reveal [this tx] | |
...))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment