|
| 1 | +(ns fluree.server.consensus.events |
| 2 | + "Common namespace for defining consensus event messages shared across consensus |
| 3 | + protocols") |
| 4 | + |
| 5 | +(defn create-ledger |
| 6 | + "Upon receiving a request to create a new ledger, an event |
| 7 | + message must be queued into the consensus state machine. |
| 8 | +
|
| 9 | + Format is [event-name event-body]" |
| 10 | + [ledger-id tx-id txn opts] |
| 11 | + [:ledger-create {:txn txn |
| 12 | + :size (count txn) |
| 13 | + :tx-id tx-id |
| 14 | + :ledger-id ledger-id |
| 15 | + :opts opts |
| 16 | + :instant (System/currentTimeMillis)}]) |
| 17 | + |
| 18 | +(defn commit-transaction |
| 19 | + "Upon receiving a request to create a new ledger, an event |
| 20 | + message must be queued into the consensus state machine. |
| 21 | +
|
| 22 | + Format is [event-name event-body]" |
| 23 | + [ledger-id tx-id txn opts] |
| 24 | + [:tx-queue {:txn txn |
| 25 | + :size (count txn) |
| 26 | + :tx-id tx-id |
| 27 | + :ledger-id ledger-id |
| 28 | + :opts opts |
| 29 | + :instant (System/currentTimeMillis)}]) |
| 30 | + |
| 31 | +(defn transaction-committed |
| 32 | + "Post-transaction, the message we will broadcast out and/or deliver |
| 33 | + to a client awaiting a response." |
| 34 | + ([{:keys [ledger-id tx-id] :as _event-params} |
| 35 | + {:keys [db data-file-meta commit-file-meta] :as _commit-result}] |
| 36 | + {:ledger-id ledger-id |
| 37 | + :data-file-meta data-file-meta |
| 38 | + :commit-file-meta commit-file-meta |
| 39 | + ;; below is metadata for quickly validating into the state machine, not retained |
| 40 | + :t (:t db) ;; for quickly validating this is the next 'block' |
| 41 | + :tx-id tx-id ;; for quickly removing from the queue |
| 42 | + }) |
| 43 | + ([processing-server event-params commit-result] |
| 44 | + (-> (transaction-committed event-params commit-result) |
| 45 | + (assoc :server processing-server)))) |
| 46 | + |
| 47 | +(defn error |
| 48 | + ([params exception] |
| 49 | + (-> params |
| 50 | + (select-keys [:ledger-id :tx-id]) |
| 51 | + (assoc :ex-message (ex-message exception) |
| 52 | + :ex-data (ex-data exception)))) |
| 53 | + ([processing-server params exception] |
| 54 | + (-> (error params exception) |
| 55 | + (assoc :server processing-server)))) |
0 commit comments