From c46b175d24432a98a579f821b6db4645f8b9065b Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Fri, 31 May 2019 15:13:34 -0700 Subject: [PATCH 1/3] adds +handle-init to lib/tapp for an optional "boot" transaction --- lib/tapp.hoon | 57 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/lib/tapp.hoon b/lib/tapp.hoon index 7176d6f75..a54dbda2d 100644 --- a/lib/tapp.hoon +++ b/lib/tapp.hoon @@ -12,7 +12,8 @@ ++ sign sign:tapp-sur ++ contract contract:tapp-sur ++ command - $% [%poke =in-poke-data] + $% [%init ~] + [%poke =in-poke-data] [%peer =path] [%diff =dock =path =in-peer-data] [%take =sign] @@ -65,6 +66,7 @@ |= handler=tapp-core-poke-peer %- create-tapp-all |_ [=bowl:gall state=state-type] + ++ handle-init *form:tapp-async ++ handle-poke ~(handle-poke handler bowl state) ++ handle-peer ~(handle-peer handler bowl state) ++ handle-diff |=(* (async-fail:async-lib %no-diff-handler >path< ~)) @@ -89,6 +91,7 @@ |= handler=tapp-core-poke-diff %- create-tapp-all |_ [=bowl:gall state=state-type] + ++ handle-init *form:tapp-async ++ handle-poke ~(handle-poke handler bowl state) ++ handle-peer |=(* (async-fail:async-lib %no-peer-handler >path< ~)) ++ handle-diff ~(handle-diff handler bowl state) @@ -117,18 +120,57 @@ |= handler=tapp-core-poke-peer-take %- create-tapp-all |_ [=bowl:gall state=state-type] + ++ handle-init *form:tapp-async ++ handle-poke ~(handle-poke handler bowl state) ++ handle-peer ~(handle-peer handler bowl state) ++ handle-diff |=(* (async-fail:async-lib %no-diff-handler >path< ~)) ++ handle-take ~(handle-take handler bowl state) -- :: +:: The form of a tapp that only handles pokes, peers, diffs, and takes +:: +++ tapp-core-poke-peer-diff-take + $_ ^| + |_ [bowl:gall state-type] + ++ handle-poke + |~ in-poke-data + *form:tapp-async + :: + ++ handle-peer + |~ path + *form:tapp-async + :: + ++ handle-diff + |~ [dock path in-peer-data] + *form:tapp-async + :: + ++ handle-take + |~ sign + *form:tapp-async + -- +:: +++ create-tapp-poke-peer-diff-take + |= handler=tapp-core-poke-peer-diff-take + %- create-tapp-all + |_ [=bowl:gall state=state-type] + ++ handle-init *form:tapp-async + ++ handle-poke ~(handle-poke handler bowl state) + ++ handle-peer ~(handle-peer handler bowl state) + ++ handle-diff ~(handle-diff handler bowl state) + ++ handle-take ~(handle-take handler bowl state) + -- +:: :: The form of a tapp :: ++ tapp-core-all $_ ^| |_ [bowl:gall state-type] :: + :: Initialization + :: + ++ handle-init + *form:tapp-async + :: :: Input :: ++ handle-poke @@ -159,12 +201,18 @@ |_ [=bowl:gall tapp-state] ++ this-tapp . ++ prep - |= old-state=* + |= old-state=(unit) ^- (quip move _this-tapp) - ~& [%tapp-loaded dap.bowl] - =/ old ((soft tapp-state) old-state) + ?~ old-state + ~& [%tapp-init dap.bowl] + =. waiting (~(put to waiting) %init ~) + start-async + :: + =/ old ((soft tapp-state) u.old-state) ?~ old + ~& [%tapp-reset dap.bowl] `this-tapp + ~& [%tapp-loaded dap.bowl] `this-tapp(+<+ u.old) :: :: Start a command @@ -310,6 +358,7 @@ %- from-form:eval:tapp-async ^- form:tapp-async ?- -.u.next + %init ~(handle-init handler bowl app-state) %poke (~(handle-poke handler bowl app-state) +.u.next) %peer (~(handle-peer handler bowl app-state) +.u.next) %diff (~(handle-diff handler bowl app-state) +.u.next) From 36be16e8b31b9711e52a4fadaec52342cfde1ae1 Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Fri, 31 May 2019 15:33:51 -0700 Subject: [PATCH 2/3] adds +handle-peek for lib/tapp namespace reads --- app/example-tapp-fetch.hoon | 3 ++- app/example-tapp-subscribe.hoon | 3 ++- lib/tapp.hoon | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/app/example-tapp-fetch.hoon b/app/example-tapp-fetch.hoon index f6294672d..fcecce41e 100644 --- a/app/example-tapp-fetch.hoon +++ b/app/example-tapp-fetch.hoon @@ -12,13 +12,14 @@ +$ state $: top-comments=(list tape) == + +$ peek-data _!! +$ in-poke-data [%noun =cord] +$ out-poke-data ~ +$ in-peer-data ~ +$ out-peer-data $% [%comments (list tape)] == - ++ tapp (^tapp state in-poke-data out-poke-data in-peer-data out-peer-data) + ++ tapp (^tapp state peek-data in-poke-data out-poke-data in-peer-data out-peer-data) ++ stdio (^stdio out-poke-data out-peer-data) -- => diff --git a/app/example-tapp-subscribe.hoon b/app/example-tapp-subscribe.hoon index 78927d708..42b10f86f 100644 --- a/app/example-tapp-subscribe.hoon +++ b/app/example-tapp-subscribe.hoon @@ -8,13 +8,14 @@ +$ state $: subscription=(unit subscription-state) == + +$ peek-data _!! +$ in-poke-data [%noun =cord] +$ out-poke-data [%noun =cord] +$ out-peer-data ~ +$ in-peer-data $% [%comments comments=(list tape)] == - ++ tapp (^tapp state in-poke-data out-poke-data in-peer-data out-peer-data) + ++ tapp (^tapp state peek-data in-poke-data out-poke-data in-peer-data out-peer-data) ++ stdio (^stdio out-poke-data out-peer-data) -- =, async=async:tapp diff --git a/lib/tapp.hoon b/lib/tapp.hoon index a54dbda2d..129ae5cd7 100644 --- a/lib/tapp.hoon +++ b/lib/tapp.hoon @@ -1,6 +1,7 @@ /- tapp-sur=tapp /+ async |* $: state-type=mold + peek-data=mold in-poke-data=mold out-poke-data=mold in-peer-data=mold @@ -29,6 +30,8 @@ active=(unit eval-form:eval:tapp-async) app-state=state-type == ++$ tapp-peek + [%noun ?(? (set contract))] :: :: The form of a tapp that only handles pokes :: @@ -68,6 +71,7 @@ |_ [=bowl:gall state=state-type] ++ handle-init *form:tapp-async ++ handle-poke ~(handle-poke handler bowl state) + ++ handle-peek _~ ++ handle-peer ~(handle-peer handler bowl state) ++ handle-diff |=(* (async-fail:async-lib %no-diff-handler >path< ~)) ++ handle-take |=(* (async-fail:async-lib %no-take-handler >path< ~)) @@ -93,6 +97,7 @@ |_ [=bowl:gall state=state-type] ++ handle-init *form:tapp-async ++ handle-poke ~(handle-poke handler bowl state) + ++ handle-peek _~ ++ handle-peer |=(* (async-fail:async-lib %no-peer-handler >path< ~)) ++ handle-diff ~(handle-diff handler bowl state) ++ handle-take |=(* (async-fail:async-lib %no-take-handler >path< ~)) @@ -122,6 +127,7 @@ |_ [=bowl:gall state=state-type] ++ handle-init *form:tapp-async ++ handle-poke ~(handle-poke handler bowl state) + ++ handle-peek _~ ++ handle-peer ~(handle-peer handler bowl state) ++ handle-diff |=(* (async-fail:async-lib %no-diff-handler >path< ~)) ++ handle-take ~(handle-take handler bowl state) @@ -155,6 +161,7 @@ |_ [=bowl:gall state=state-type] ++ handle-init *form:tapp-async ++ handle-poke ~(handle-poke handler bowl state) + ++ handle-peek _~ ++ handle-peer ~(handle-peer handler bowl state) ++ handle-diff ~(handle-diff handler bowl state) ++ handle-take ~(handle-take handler bowl state) @@ -177,6 +184,12 @@ |~ in-poke-data *form:tapp-async :: + :: Read + :: + ++ handle-peek + |~ path + *(unit (unit peek-data)) + :: :: Subscription request :: ++ handle-peer @@ -226,6 +239,22 @@ `this-tapp start-async :: + :: Read from tapp state + :: + ++ peek + |= =path + ^- (unit (unit ?(tapp-peek peek-data))) + ?- path + [%x %tapp %active ~] + [~ ~ %noun ?=(^ active)] + :: + [%x %tapp %contracts ~] + [~ ~ %noun ?~(active ~ contracts.u.active)] + :: + * + (~(handle-peek handler bowl app-state) path) + == + :: :: Receive subscription request :: ++ peer From 284e8319253e7429fe2ff7c563e2fa52a9a1acfc Mon Sep 17 00:00:00 2001 From: Joe Bryan Date: Sat, 1 Jun 2019 11:17:02 -0700 Subject: [PATCH 3/3] rejects automatic %peer /sole from lib/drum --- lib/tapp.hoon | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/tapp.hoon b/lib/tapp.hoon index 129ae5cd7..4a1b607b5 100644 --- a/lib/tapp.hoon +++ b/lib/tapp.hoon @@ -48,7 +48,11 @@ %- create-tapp-poke-peer |_ [=bowl:gall state=state-type] ++ handle-poke ~(handle-poke handler bowl state) - ++ handle-peer |=(* (async-fail:async-lib %no-peer-handler >path< ~)) + ++ handle-peer + |= * + ~| %default-tapp-no-sole + ?< ?=([%sole *] +<) + (async-fail:async-lib %no-peer-handler >path< ~) -- :: :: The form of a tapp that only handles pokes and peers