Skip to content

Instantly share code, notes, and snippets.

@moea
Last active April 6, 2018 10:25
Show Gist options
  • Save moea/876b3e73e5008cb58461b7cf4514ec0a to your computer and use it in GitHub Desktop.
Save moea/876b3e73e5008cb58461b7cf4514ec0a to your computer and use it in GitHub Desktop.
scratch
(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