Skip to content

Commit 366b5a8

Browse files
committed
wip
1 parent 88a8a77 commit 366b5a8

13 files changed

+347
-160
lines changed

desk/app/hodl.hoon

+133-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+
do ~(. +> 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,143 @@
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:do !<(action:a vase)) :: TODO do these action need to be namesspaced?
88+
%transaction-action (poke-transaction-action:do !<(action:t vase))
89+
%wallet-action (poke-wallet-action:do !<(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
99+
:: TODO: should the updates be scoped to each model?
100+
:: ?: ?=([%updates ~] path)
101+
:: :_ this
102+
:: [%give %fact ~ %hodl-update !>(update)]~
103+
:: (on-watch:def path)
135104
==
136105
::
137-
:: TODO: add scries for accounts and wallets
138106
++ on-peek
139107
|= =path
140108
^- (unit (unit cage))
141109
?> (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-
==
110+
?+ path (on-peek:def path)
111+
[%x %accounts @t ~] ``noun+!>((~(get by acts) i.t.t.path))
112+
[%x %accounts ~] ``noun+!>(acts)
113+
[%x %transactions @t ~] ``noun+!>((~(get by txns) i.t.t.path))
114+
[%x %transactions ~] ``noun+!>(txns)
115+
[%x %wallets @t ~] ``noun+!>((~(get by wlts) i.t.t.path))
116+
[%x %wallets ~] ``noun+!>(wlts)
150117
==
151118
::
152119
++ on-leave on-leave:def
153120
++ on-agent on-agent:def
154121
++ on-arvo on-arvo:def
155122
++ on-fail on-fail:def
156123
--
124+
:: helper core
125+
|_ =bowl:gall
126+
++ poke-account-action
127+
|= act=action:a
128+
^- _state
129+
?- -.act
130+
%add
131+
?< (~(has by acts) id.act)
132+
=/ =acct:a
133+
:* id=id.act
134+
wallet-id=wallet-id.act
135+
name=name.act
136+
note=note.act
137+
==
138+
state(acts (~(put by acts) id.act acct))
139+
::
140+
%edit
141+
?> (~(has by acts) id.act)
142+
=/ =acct:a
143+
:* id=id.act :: TODO: should all fields be editable? probably not id
144+
wallet-id=wallet-id.act
145+
name=name.act
146+
note=note.act
147+
==
148+
state(acts (~(put by acts) id.act acct))
149+
::
150+
%del
151+
?> (~(has by acts) id.act)
152+
state(acts (~(del by acts) id.act))
153+
==
154+
::
155+
++ poke-transaction-action
156+
|= act=action:t
157+
^- _state
158+
?- -.act
159+
%add
160+
?< (~(has by txns) id.act)
161+
=/ =txn:t
162+
:* id=id.act
163+
coin-id=coin-id.act
164+
date=date.act
165+
note=note.act
166+
amount=amount.act
167+
cost-basis=cost-basis.act
168+
type=type.act
169+
account-id=account-id.act
170+
==
171+
state(txns (~(put by txns) id.act txn))
172+
::
173+
%edit
174+
?> (~(has by txns) id.act)
175+
=/ =txn:t
176+
:* id=id.act :: TODO: should all fields be editable? probably not id
177+
coin-id=coin-id.act
178+
date=date.act
179+
note=note.act
180+
amount=amount.act
181+
cost-basis=cost-basis.act
182+
type=type.act
183+
account-id=account-id.act
184+
==
185+
state(txns (~(put by txns) id.act txn))
186+
::
187+
%del
188+
?> (~(has by txns) id.act)
189+
state(txns (~(del by txns) id.act))
190+
==
191+
::
192+
++ poke-wallet-action
193+
|= act=action:w
194+
^- _state
195+
?- -.act
196+
%add
197+
?< (~(has by wlts) id.act)
198+
=/ =wllt:w
199+
:* id=id.act
200+
name=name.act
201+
note=note.act
202+
==
203+
state(wlts (~(put by wlts) id.act wllt))
204+
::
205+
%edit
206+
?> (~(has by wlts) id.act)
207+
=/ =wllt:w
208+
:* id=id.act :: TODO: should all fields be editable? probably not id
209+
name=name.act
210+
note=note.act
211+
==
212+
state(wlts (~(put by wlts) id.act wllt))
213+
::
214+
%del
215+
?> (~(has by wlts) id.act)
216+
state(wlts (~(del by wlts) id.act))
217+
==
218+
--

desk/lib/account.hoon

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
==
21+
++ acts
22+
|= ud=[=accounts]
23+
^- json
24+
%- pairs
25+
%+ turn ~(tap by accounts.ud)
26+
|= act=[=id =acct]
27+
^- (pair @t json)
28+
[id.act (acjs acct.act)]
29+
++ acjs
30+
|= [id=@tas wallet-id=@tas name=@tas note=@tas]
31+
^- json
32+
%- pairs
33+
:~ id/s+id
34+
wallet-id/s+wallet-id
35+
name/s+name
36+
note/s+note
37+
==
38+
--
39+
--

0 commit comments

Comments
 (0)