Add wallet_type column to distinguish exchanges from wallets

Exchanges (can receive bank deposits) vs wallets (cold storage only).
Supports ?type= filter on GET /api/wallets.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-08 15:48:41 +01:00
co-authored by Claude Opus 4.6
parent 174ea24786
commit 793c63927c
4 changed files with 19 additions and 7 deletions
@@ -0,0 +1 @@
ALTER TABLE wallets DROP COLUMN wallet_type;
@@ -0,0 +1,4 @@
ALTER TABLE wallets ADD COLUMN wallet_type TEXT NOT NULL DEFAULT 'exchange';
--;;
UPDATE wallets SET wallet_type = 'wallet'
WHERE name IN ('Cold', 'Coldcard', 'Nunchuk Multi Sig');
+7 -3
View File
@@ -70,15 +70,19 @@ SELECT rate_date, eur, dkk, eur_dkk, updated_at FROM currencies WHERE rate_date
-- :name insert-wallet! :! :n
-- :doc Insert a new wallet
INSERT INTO wallets (name) VALUES (:name)
INSERT INTO wallets (name, wallet_type) VALUES (:name, :wallet-type)
-- :name get-all-wallets :? :*
-- :doc Get all wallets
SELECT id, name, created_at FROM wallets ORDER BY name
SELECT id, name, wallet_type, created_at FROM wallets ORDER BY name
-- :name get-wallets-by-type :? :*
-- :doc Get wallets filtered by type
SELECT id, name, wallet_type, created_at FROM wallets WHERE wallet_type = :wallet-type ORDER BY name
-- :name get-wallet-by-id :? :1
-- :doc Get a wallet by ID
SELECT id, name, created_at FROM wallets WHERE id = :id
SELECT id, name, wallet_type, created_at FROM wallets WHERE id = :id
-- Events --------------------------------------------------------------------
@@ -8,14 +8,17 @@
[java.time Instant LocalDate ZoneOffset]
[java.util UUID]))
(defn list-wallets [{:keys [query-fn]} _req]
(response/ok (query-fn :get-all-wallets {})))
(defn list-wallets [{:keys [query-fn]} req]
(let [wallet-type (get-in req [:query-params "type"])]
(if wallet-type
(response/ok (query-fn :get-wallets-by-type {:wallet-type wallet-type}))
(response/ok (query-fn :get-all-wallets {})))))
(defn create-wallet! [{:keys [query-fn]} req]
(let [{:keys [name]} (:body-params req)]
(let [{:keys [name wallet_type]} (:body-params req)]
(if (str/blank? name)
(response/bad-request {:error "name is required"})
(do (query-fn :insert-wallet! {:name name})
(do (query-fn :insert-wallet! {:name name :wallet-type (or wallet_type "exchange")})
(response/created "/api/wallets" {:name name})))))
(defn get-wallet-balances [{:keys [query-fn]} _req]