Skip to content

Commit ca3f299

Browse files
committed
wip
1 parent 87e590f commit ca3f299

13 files changed

+422
-158
lines changed

desk/app/hodl.hoon

+128-71
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
:: mainly for orchestration. But, first focus on getting a working TX CRUD
77
:: agent before optimizing. So, one day :)
88
::
9-
/+ *account, *transaction, *wallet
10-
/+ default-agent, dbug, agentio, verb
9+
/+ a=account, t=transaction, w=wallet
10+
/+ default-agent, dbug, verb
1111
|%
1212
+$ card card:agent:gall
1313
+$ versioned-state
@@ -18,19 +18,21 @@
1818
:: acts: map of account-id --> account
1919
:: txns: map of transaction-id --> transaction
2020
:: wlts: map of wallet-id --> wallets
21-
+$ state-0 [%0 txns=transactions:zero:past]
22-
+$ state-1 [%1 acts=accounts txns=transactions wlts=wallets]
21+
+$ state-0 [%0 txns=transactions:zero:past:t]
22+
+$ state-1 [%1 acts=accounts:a txns=transactions:t wlts=wallets:w]
2323
--
2424
=| state-1
2525
=* state -
2626
::
2727
%- agent:dbug
2828
%+ verb & :: TODO: disable before production
2929
^- agent:gall
30+
::
31+
=< :: app core
3032
|_ =bowl:gall
3133
+* this .
34+
help ~(. +> bowl)
3235
def ~(. (default-agent this %.n) bowl)
33-
io ~(. agentio bowl)
3436
::
3537
++ on-init on-init:def
3638
::
@@ -42,30 +44,29 @@
4244
|= old-state=vase
4345
^- (quip card _this)
4446
=/ old !<(versioned-state old-state)
47+
|^
4548
?- -.old
46-
%1
47-
`this(state old)
48-
%0
49-
`this(state-0-to-1 old)
49+
%1 `this(state old)
50+
%0 `this(state (state-0-to-1 old))
5051
==
5152
++ state-0-to-1
5253
|= zer=state-0
5354
^- state-1
5455
:* %1
55-
acts *accounts
56+
acts *accounts:a
5657
txns (transactions-0-to-1 txns.zer)
57-
wlts *wallets
58+
wlts *wallets:w
5859
==
5960
++ transactions-0-to-1
60-
|= txns=transactions:zero:past
61-
^- transactions
61+
|= txns=transactions:zero:past:t
62+
^- transactions:t
6263
%- ~(run by txns)
63-
|= [id=@t txn=transaction:zero:past]
64-
^- [id=@t txn=transaction]
64+
|= [id=@t txn=transaction:zero:past:t]
65+
^- [id=@t txn=transaction:t]
6566
[id (transaction-0-to-1 txn)]
6667
++ transaction-0-to-1
67-
|= txn=transaction:zero:past
68-
^- ^transaction :: TODO: which transaction to point to? should use the ket to traverse up the tree?
68+
|= txn=transaction:zero:past:t
69+
^- transaction:t
6970
:* id.txn
7071
coin-id.txn
7172
date.txn
@@ -75,82 +76,138 @@
7576
type.txn
7677
~
7778
==
79+
--
7880
::
79-
:: TODO: add pokes for accounts and wallets
8081
++ on-poke
8182
|= [=mark =vase]
8283
^- (quip card _this)
83-
|^
8484
?> (team:title our.bowl src.bowl)
85-
?. ?=(%hodl-action mark) (on-poke:def mark vase)
86-
=/ act !<(action vase)
87-
=. state (poke-action act)
88-
:_ this
89-
~[(fact:io hodl-update+!>(`update`[act]) ~[/updates])]
90-
::
91-
++ poke-action
92-
|= act=action
93-
^- _state
94-
?- -.act
95-
%add
96-
?< (~(has by txns) id.act)
97-
=/ txn=txn
98-
:* id=id.act
99-
coin-id=coin-id.act
100-
date=date.act
101-
note=note.act
102-
amount=amount.act
103-
cost-basis=cost-basis.act
104-
type=type.act
105-
account-id=account-id.act
106-
==
107-
state(txns (~(put by txns) id.act txn))
108-
::
109-
%edit
110-
?> (~(has by txns) id.act)
111-
=/ txn=txn
112-
:* id=id.act
113-
coin-id=coin-id.act
114-
date=date.act
115-
note=note.act
116-
amount=amount.act
117-
cost-basis=cost-basis.act
118-
type=type.act
119-
account-id=account-id.act
120-
==
121-
state(txns (~(put by txns) id.act txn)) :: TODO: should all fields be editable? probably not id
122-
::
123-
%del
124-
?> (~(has by txns) id.act)
125-
state(txns (~(del by txns) id.act))
85+
=^ cards state
86+
?+ mark (on-poke:def mark vase)
87+
%account-action (poke-account-action:help !<(action:a vase)) :: TODO do these action need to be namesspaced?
88+
%transaction-action (poke-transaction-action:help !<(action:t vase))
89+
%wallet-action (poke-wallet-action:help !<(action:w vase))
12690
==
127-
--
91+
[cards this]
12892
::
12993
++ on-watch
13094
|= =path
13195
^- (quip card _this)
13296
?> (team:title our.bowl src.bowl)
13397
?+ path (on-watch:def path)
134-
[%updates ~] `this
98+
[%updates ~] `this :: TODO: should the updates be scoped to each model?
13599
==
136100
::
137-
:: TODO: add scries for accounts and wallets
138101
++ on-peek
139102
|= =path
140103
^- (unit (unit cage))
141104
?> (team:title our.bowl src.bowl)
142-
?+ path (on-peek:def path)
143-
[%x %transactions *]
144-
?+ t.t.path (on-peek:def path)
145-
[%all ~]
146-
:^ ~ ~ %hodl-update
147-
!> ^- update
148-
[%txns txns]
149-
==
105+
?+ path (on-peek:def path)
106+
[%x %account @t ~] ``noun+!>((~(get by acts) i.t.t.path))
107+
[%x %accounts ~] ``noun+!>(acts)
108+
[%x %transaction @t ~] ``noun+!>((~(get by txns) i.t.t.path))
109+
[%x %transactions ~] ``noun+!>(txns)
110+
[%x %wallet @t ~] ``noun+!>((~(get by wlts) i.t.t.path))
111+
[%x %wallets ~] ``noun+!>(wlts)
150112
==
151113
::
152114
++ on-leave on-leave:def
153115
++ on-agent on-agent:def
154116
++ on-arvo on-arvo:def
155117
++ on-fail on-fail:def
156118
--
119+
:: helper core
120+
|_ =bowl:gall
121+
++ poke-account-action
122+
|= act=action:a
123+
^- _state
124+
?- -.act
125+
%add
126+
?< (~(has by acts) id.act)
127+
=/ =acct:a
128+
:* id=id.act
129+
wallet-id=wallet-id.act
130+
name=name.act
131+
note=note.act
132+
==
133+
state(acts (~(put by acts) id.act acct))
134+
::
135+
%edit
136+
?> (~(has by acts) id.act)
137+
=/ =acct:a
138+
:* id=id.act :: TODO: should all fields be editable? probably not id
139+
wallet-id=wallet-id.act
140+
name=name.act
141+
note=note.act
142+
==
143+
state(acts (~(put by acts) id.act acct))
144+
::
145+
%del
146+
?> (~(has by acts) id.act)
147+
state(acts (~(del by acts) id.act))
148+
==
149+
::
150+
++ poke-transaction-action
151+
|= act=action:t
152+
^- _state
153+
?- -.act
154+
%add
155+
?< (~(has by txns) id.act)
156+
=/ =txn:t
157+
:* id=id.act
158+
coin-id=coin-id.act
159+
date=date.act
160+
note=note.act
161+
amount=amount.act
162+
cost-basis=cost-basis.act
163+
type=type.act
164+
account-id=account-id.act
165+
==
166+
state(txns (~(put by txns) id.act txn))
167+
::
168+
%edit
169+
?> (~(has by txns) id.act)
170+
=/ =txn:t
171+
:* id=id.act :: TODO: should all fields be editable? probably not id
172+
coin-id=coin-id.act
173+
date=date.act
174+
note=note.act
175+
amount=amount.act
176+
cost-basis=cost-basis.act
177+
type=type.act
178+
account-id=account-id.act
179+
==
180+
state(txns (~(put by txns) id.act txn))
181+
::
182+
%del
183+
?> (~(has by txns) id.act)
184+
state(txns (~(del by txns) id.act))
185+
==
186+
::
187+
++ poke-wallet-action
188+
|= act=action:w
189+
^- _state
190+
?- -.act
191+
%add
192+
?< (~(has by wlts) id.act)
193+
=/ =wllt:w
194+
:* id=id.act
195+
name=name.act
196+
note=note.act
197+
==
198+
state(wlts (~(put by wlts) id.act wllt))
199+
::
200+
%edit
201+
?> (~(has by wlts) id.act)
202+
=/ =wllt:w
203+
:* id=id.act :: TODO: should all fields be editable? probably not id
204+
name=name.act
205+
note=note.act
206+
==
207+
state(wlts (~(put by wlts) id.act wllt))
208+
::
209+
%del
210+
?> (~(has by wlts) id.act)
211+
state(wlts (~(del by wlts) id.act))
212+
==
213+
--

desk/lib/account.hoon

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/- *account
2+
|%
3+
++ dejs-action
4+
=, dejs:format
5+
|= jon=json
6+
^- action
7+
%. jon
8+
%- of
9+
:~ [%add (ot ~[id+so wallet-id+so name+so note+so])]
10+
[%edit (ot ~[id+so wallet-id+so name+so note+so])]
11+
[%del (ot ~[id+so])]
12+
==
13+
++ enjs-update
14+
=, enjs:format
15+
|= upd=update
16+
^- json
17+
|^
18+
?- -.upd
19+
%accts (acts +.upd)
20+
%add (add +.upd)
21+
%edit (edit +.upd)
22+
%del (del +.upd)
23+
==
24+
++ acts
25+
|= ud=[=accounts]
26+
^- json
27+
%- pairs
28+
%+ turn ~(tap by accounts.ud)
29+
|= act=[=id =acct]
30+
^- (pair @t json)
31+
[id.act (acjs acct.act)]
32+
++ add
33+
|= ud=[id=@tas wallet-id=@tas name=@tas note=@tas]
34+
^- json
35+
%- pairs
36+
:~ add/(acjs ud)
37+
==
38+
++ edit
39+
|= ud=[id=@tas wallet-id=@tas name=@tas note=@tas]
40+
^- json
41+
%- pairs
42+
:~ edit/(acjs ud)
43+
==
44+
++ del
45+
|= ud=[id=@tas]
46+
^- json
47+
%- pairs
48+
:~ del/s+id.ud
49+
==
50+
++ acjs
51+
|= [id=@tas wallet-id=@tas name=@tas note=@tas]
52+
^- json
53+
%- pairs
54+
:~ id/s+id
55+
wallet-id/s+wallet-id
56+
name/s+name
57+
note/s+note
58+
==
59+
--
60+
--

0 commit comments

Comments
 (0)