going somewhere.
This commit is contained in:
1 parent
cfb63cb473
commit
30d732f708
2 files changed
+94
-29
No files matched your search
@@ -57,8 +57,8 @@
|
||||
interest-rates (d/q '[:find ?interest-rate ?v
|
||||
:in $ ?eid
|
||||
:where [?e :skirmish.security/interest-rate ?interest-rate ?tx]
|
||||
[?e :skirmish.security/sec-id ?sec-id]
|
||||
[?tx :db/txInstant ?v]]
|
||||
[?e :skirmish.security/sec-id ?sec-id]
|
||||
[?tx :db/txInstant ?v]]
|
||||
history sec-id)]
|
||||
(sort-by second interest-rates)))
|
||||
|
||||
@@ -72,11 +72,12 @@
|
||||
(let [[amount sec-id pk date] (d/q '[:find [?amount ?sec-id ?pk ?v]
|
||||
:in $ ?account-id
|
||||
:where [?e :skirmish.ledger/owner-public-key ?account-id]
|
||||
[?e :skirmish.ledger/amount ?amount ?tx]
|
||||
[?e :skirmish.ledger/sec ?sec]
|
||||
[?sec :skirmish.security/sec-id ?sec-id]
|
||||
[?e :skirmish.ledger/owner-public-key ?pk]
|
||||
[?tx :db/txInstant ?v]] db account-id)]
|
||||
[?e :skirmish.ledger/amount ?amount ?tx]
|
||||
[?e :skirmish.ledger/sec ?sec]
|
||||
[?sec :skirmish.security/sec-id ?sec-id]
|
||||
[?e :skirmish.ledger/owner-public-key ?pk]
|
||||
[?tx :db/txInstant ?v]]
|
||||
db account-id)]
|
||||
{:amount (when (some? sec-id) (compute-face-value-from-db db amount sec-id date))
|
||||
:sec-id sec-id
|
||||
:account-public-key pk}))
|
||||
@@ -85,4 +86,43 @@
|
||||
(d/q '[:find ?s :where [?e :skirmish.security/sec-id ?s]] db))
|
||||
|
||||
(defn create-security [conn sec-id interest-rate]
|
||||
(d/transact conn [[:skirmish.ledger/create-security sec-id interest-rate]]))
|
||||
(d/transact conn [[:skirmish.ledger/create-security sec-id interest-rate]]))
|
||||
|
||||
(defn get-account [db account-id]
|
||||
(d/pull db '[*] [:skirmish.ledger/owner-public-key account-id]))
|
||||
|
||||
(defn assoc-accounts [db transaction]
|
||||
(let [from-account (get-account db (:from-account-id transaction))
|
||||
to-account (get-account db (:to-account-id transaction))
|
||||
ret (assoc transaction :from-account from-account)
|
||||
ret (assoc ret :to-account to-account)]
|
||||
ret))
|
||||
|
||||
(defn get-new-from-account-value [{amount :amount from-account :from-account} old-change]
|
||||
(if (some? old-change)
|
||||
(assoc old-change 3 (- (get old-change 3) amount))
|
||||
[:db/add
|
||||
(:db/id from-account)
|
||||
:skirmish.ledger/amount
|
||||
(- (:skirmish.ledger/amount from-account) amount)]))
|
||||
|
||||
(defn get-new-to-account-value [{amount :amount to-account :to-account} old-change]
|
||||
(if (some? old-change)
|
||||
(assoc old-change 3 (+ (get old-change 3) amount))
|
||||
[:db/add
|
||||
(:db/id to-account)
|
||||
:skirmish.ledger/amount
|
||||
(+ (:skirmish.ledger/amount to-account) amount)]))
|
||||
|
||||
(defn compute-transactions [res transaction]
|
||||
(let [res-from-account (get res (:from-account-id transaction))
|
||||
from-account (get-new-from-account-value transaction res-from-account)
|
||||
res (assoc res (:from-account-id transaction) from-account)
|
||||
res-to-account (get res (:to-account-id transaction))
|
||||
to-account (get-new-to-account-value transaction res-to-account)
|
||||
res (assoc res (:to-account-id transaction) to-account)]
|
||||
res))
|
||||
|
||||
(defn create-transactions [db transactions]
|
||||
(let [transactions (map #(assoc-accounts db %) transactions)]
|
||||
(into #{} (vals (reduce compute-transactions {} transactions)))))
|
||||
Reference in new issue
Block a user