/
bankster.clj
49 lines (39 loc) · 1.65 KB
/
bankster.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(ns
^{:doc "Bankster library, records and protocols."
:author "Paweł Wilk"
:added "1.0.0"}
io.randomseed.bankster)
;;
;; Currency record.
;;
(defrecord Currency
[^clojure.lang.Keyword id ; currency ID (e.g. :EUR or :crypto/ETH)
^long numeric ; currency numeric ID (e.g. 978 or -1 for none)
^int scale ; currency supported scale (decimal places, e.g. 2 or -1 for auto)
^clojure.lang.Keyword kind ; currency kind (e.g. :FIAT or :DECENTRALIZED)
^clojure.lang.Keyword domain ; currency domain (e.g. :ISO-4217 or :CRYPTO)
^int weight] ; currency weight (used when getting using currency code)
Object
(toString [^Currency c] (name (.id ^Currency c))))
;;
;; Registry record.
;;
(defrecord Registry
[^clojure.lang.PersistentHashMap cur-id->cur ; currency ID to currency record
^clojure.lang.PersistentHashMap cur-nr->cur ; currency numeric ID to currency record
^clojure.lang.PersistentHashMap ctr-id->cur ; country ID to currency record
^clojure.lang.PersistentHashMap cur-id->ctr-ids ; currency ID to set of country IDs
^clojure.lang.PersistentHashMap cur-id->localized ; locale ID to localized properties
^clojure.lang.PersistentHashMap cur-code->curs ; currency code to currencies (weighted)
^String version]
Object
(toString [^Registry r] (pr-str r)))
;;
;; Money record.
;;
(defrecord Money
[^Currency currency ; currency object
^BigDecimal amount] ; currency amount
Object
(toString [^Money m]
(str (.toPlainString ^BigDecimal (.amount ^Money m)) " " (.currency ^Money m))))