Skip to content

Commit

Permalink
Super simple client/server app setup in new desk
Browse files Browse the repository at this point in the history
  • Loading branch information
hanfel-dovned committed Jan 24, 2024
1 parent 324f0cc commit 7302270
Show file tree
Hide file tree
Showing 20 changed files with 1,226 additions and 0 deletions.
98 changes: 98 additions & 0 deletions rpc-desk/app/rpc-provider.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/- near-rpc
/+ dbug, default-agent
::
|%
+$ versioned-state
$% state-0
==
+$ state-0 [%0 ~]
+$ card $+(card card:agent:gall)
--
::
%- agent:dbug
=| state-0
=* state -
::
^- agent:gall
::
=<
|_ =bowl:gall
+* this .
def ~(. (default-agent this %|) bowl)
hc ~(. +> [bowl ~])
++ on-init
^- (quip card _this)
=^ cards state abet:init:hc
[cards this]
::
++ on-save
^- vase
!>(state)
::
++ on-load
|= =vase
^- (quip card _this)
=^ cards state abet:(load:hc vase)
[cards this]
::
++ on-poke
|= [=mark =vase]
^- (quip card _this)
=^ cards state abet:(poke:hc mark vase)
[cards this]
::
++ on-peek
|= =path
^- (unit (unit cage))
[~ ~]
::
++ on-watch
|= =path
^- (quip card _this)
`this
::
++ on-agent
|= [=wire =sign:agent:gall]
^- (quip card _this)
`this
::
++ on-arvo on-arvo:def
++ on-fail on-fail:def
++ on-leave on-leave:def
--
|_ [=bowl:gall deck=(list card)]
+* that .
++ emit |=(=card that(deck [card deck]))
++ emil |=(lac=(list card) that(deck (welp lac deck)))
++ abet ^-((quip card _state) [(flop deck) state])
::
++ from-self =(our src):bowl
::
++ init
^+ that
that
::
++ load
|= vaz=vase
^+ that
?> ?=([%0 *] q.vaz)
that(state !<(state-0 vaz))
::
++ poke
|= [=mark =vase]
^+ that
?+ mark that
%near-rpc-ask
=+ !<(act=ask:near-rpc vase)
?- -.act
%request
~& >> "Got request"
%- emit
:* %pass /response
%agent [src.bowl %rpc-requester]
%poke %near-rpc-response
!>(`response:near-rpc`[%response ~])
==
==
==
--
110 changes: 110 additions & 0 deletions rpc-desk/app/rpc-requester.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/- near-rpc
/+ dbug, default-agent
::
|%
+$ versioned-state
$% state-0
==
+$ state-0 [%0 =provider:near-rpc queue=(set request:near-rpc)]
+$ card $+(card card:agent:gall)
--
::
%- agent:dbug
=| state-0
=* state -
::
^- agent:gall
::
=<
|_ =bowl:gall
+* this .
def ~(. (default-agent this %|) bowl)
hc ~(. +> [bowl ~])
++ on-init
^- (quip card _this)
=^ cards state abet:init:hc
[cards this]
::
++ on-save
^- vase
!>(state)
::
++ on-load
|= =vase
^- (quip card _this)
=^ cards state abet:(load:hc vase)
[cards this]
::
++ on-poke
|= [=mark =vase]
^- (quip card _this)
=^ cards state abet:(poke:hc mark vase)
[cards this]
::
++ on-peek
|= =path
^- (unit (unit cage))
[~ ~]
::
++ on-watch
|= =path
^- (quip card _this)
`this
::
++ on-agent
|= [=wire =sign:agent:gall]
^- (quip card _this)
`this
::
++ on-arvo on-arvo:def
++ on-fail on-fail:def
++ on-leave on-leave:def
--
|_ [=bowl:gall deck=(list card)]
+* that .
++ emit |=(=card that(deck [card deck]))
++ emil |=(lac=(list card) that(deck (welp lac deck)))
++ abet ^-((quip card _state) [(flop deck) state])
::
++ from-self =(our src):bowl
::
++ init
^+ that
=. provider our.bowl ::we're our own provider to start (for testing)
that
::
++ load
|= vaz=vase
^+ that
?> ?=([%0 *] q.vaz)
that(state !<(state-0 vaz))
::
++ poke
|= [=mark =vase]
^+ that
?+ mark that
%near-rpc-response
?> =(src.bowl provider)
~& > 'Got response'
that
::
%near-rpc-action
?> from-self
=+ !<(act=action:near-rpc vase)
?- -.act
%change-provider
=. provider provider.act
that
::
%send-request
=/ req [now.bowl content.act]
=. queue (~(put in queue) req)
%- emit
:* %pass /request
%agent [provider %rpc-provider]
%poke %near-rpc-ask
!>(`ask:near-rpc`[%request req])
==
==
==
--
3 changes: 3 additions & 0 deletions rpc-desk/desk.bill
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:~ %rpc-provider
%rpc-requester
==
155 changes: 155 additions & 0 deletions rpc-desk/lib/dbug.hoon
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
:: dbug: agent wrapper for generic debugging tools
::
:: usage: %-(agent:dbug your-agent)
::
|%
+$ poke
$% [%bowl ~]
[%state grab=cord]
[%incoming =about]
[%outgoing =about]
==
::
+$ about
$@ ~
$% [%ship =ship]
[%path =path]
[%wire =wire]
[%term =term]
==
::
++ agent
|= =agent:gall
^- agent:gall
!.
|_ =bowl:gall
+* this .
ag ~(. agent bowl)
::
++ on-poke
|= [=mark =vase]
^- (quip card:agent:gall agent:gall)
?. ?=(%dbug mark)
=^ cards agent (on-poke:ag mark vase)
[cards this]
=/ dbug
!<(poke vase)
=; =tang
((%*(. slog pri 1) tang) [~ this])
?- -.dbug
%bowl [(sell !>(bowl))]~
::
%state
=? grab.dbug =('' grab.dbug) '-'
=; product=^vase
[(sell product)]~
=/ state=^vase
:: if the underlying app has implemented a /dbug/state scry endpoint,
:: use that vase in place of +on-save's.
::
=/ result=(each ^vase tang)
(mule |.(q:(need (need (on-peek:ag /x/dbug/state)))))
?:(?=(%& -.result) p.result on-save:ag)
%+ slap
(slop state !>([bowl=bowl ..zuse]))
(ream grab.dbug)
::
%incoming
=; =tang
?^ tang tang
[%leaf "no matching subscriptions"]~
%+ murn
%+ sort ~(tap by sup.bowl)
|= [[* a=[=ship =path]] [* b=[=ship =path]]]
(aor [path ship]:a [path ship]:b)
|= [=duct [=ship =path]]
^- (unit tank)
=; relevant=?
?. relevant ~
`>[path=path from=ship duct=duct]<
?: ?=(~ about.dbug) &
?- -.about.dbug
%ship =(ship ship.about.dbug)
%path ?=(^ (find path.about.dbug path))
%wire %+ lien duct
|=(=wire ?=(^ (find wire.about.dbug wire)))
%term !!
==
::
%outgoing
=; =tang
?^ tang tang
[%leaf "no matching subscriptions"]~
%+ murn
%+ sort ~(tap by wex.bowl)
|= [[[a=wire *] *] [[b=wire *] *]]
(aor a b)
|= [[=wire =ship =term] [acked=? =path]]
^- (unit tank)
=; relevant=?
?. relevant ~
`>[wire=wire agnt=[ship term] path=path ackd=acked]<
?: ?=(~ about.dbug) &
?- -.about.dbug
%ship =(ship ship.about.dbug)
%path ?=(^ (find path.about.dbug path))
%wire ?=(^ (find wire.about.dbug wire))
%term =(term term.about.dbug)
==
==
::
++ on-peek
|= =path
^- (unit (unit cage))
?. ?=([@ %dbug *] path)
(on-peek:ag path)
?+ path [~ ~]
[%u %dbug ~] ``noun+!>(&)
[%x %dbug %state ~] ``noun+!>(on-save:ag)
[%x %dbug %subscriptions ~] ``noun+!>([wex sup]:bowl)
==
::
++ on-init
^- (quip card:agent:gall agent:gall)
=^ cards agent on-init:ag
[cards this]
::
++ on-save on-save:ag
::
++ on-load
|= old-state=vase
^- (quip card:agent:gall agent:gall)
=^ cards agent (on-load:ag old-state)
[cards this]
::
++ on-watch
|= =path
^- (quip card:agent:gall agent:gall)
=^ cards agent (on-watch:ag path)
[cards this]
::
++ on-leave
|= =path
^- (quip card:agent:gall agent:gall)
=^ cards agent (on-leave:ag path)
[cards this]
::
++ on-agent
|= [=wire =sign:agent:gall]
^- (quip card:agent:gall agent:gall)
=^ cards agent (on-agent:ag wire sign)
[cards this]
::
++ on-arvo
|= [=wire =sign-arvo]
^- (quip card:agent:gall agent:gall)
=^ cards agent (on-arvo:ag wire sign-arvo)
[cards this]
::
++ on-fail
|= [=term =tang]
^- (quip card:agent:gall agent:gall)
=^ cards agent (on-fail:ag term tang)
[cards this]
--
--
Loading

0 comments on commit 7302270

Please sign in to comment.