ping works

This commit is contained in:
timlucmiptev 2020-11-07 17:51:31 +02:00 committed by ixv
parent 31b7ab9051
commit 65379105d0
3 changed files with 38 additions and 39 deletions

View File

@ -4,7 +4,7 @@ The below requires norsyr's fix to `decompress-point` in order to work.
## Set Credentials and Ping Servers ## Set Credentials and Ping Servers
(don't need password if all run on localhost) (don't need password if all run on localhost)
``` ```
=rpc-pass '302a586ef1d1d4d93f22b1c69cadfdfc8323b984c0f469356529b1a8fdd2558e' =rpc-pass '57a6662a8ddb792a557e9fe6d1a731f954db6c35e75a91e823ab20ea7a33585b'
:btc-provider|command [%set-credentials [rpc-url='http://localhost:8332' rpc-user='__cookie__' rpc-pass] [rpc-url='http://localhost:50002']] :btc-provider|command [%set-credentials [rpc-url='http://localhost:8332' rpc-user='__cookie__' rpc-pass] [rpc-url='http://localhost:50002']]
:btc-provider|action [%watch-address [%bech32 'bc1q59u5epktervh6fxqay2dlph0wxu9hjnx6v8n66'']] :btc-provider|action [%watch-address [%bech32 'bc1q59u5epktervh6fxqay2dlph0wxu9hjnx6v8n66'']]

View File

@ -2,7 +2,7 @@
:: Proxy that serves a BTC full node and ElectRS address indexer :: Proxy that serves a BTC full node and ElectRS address indexer
:: ::
:: Subscriptions: none :: Subscriptions: none
:: To Subscribers: :: To Subscribers: /clients
:: current connection state :: current connection state
:: results/errors of RPC calls :: results/errors of RPC calls
:: ::
@ -32,8 +32,7 @@
~& > '%btc-provider initialized successfully' ~& > '%btc-provider initialized successfully'
:: ping every 30s to see whether connected to RPC :: ping every 30s to see whether connected to RPC
:: ::
:- ~[(start-ping-timer:hc ~s30)] `this(host-info [*credentials connected=%.n clients=*(set ship)], whitelist *(set ship))
this(host-info [*credentials connected=%.n clients=*(set ship)], whitelist *(set ship))
++ on-save ++ on-save
^- vase ^- vase
!>(state) !>(state)
@ -60,6 +59,7 @@
++ on-watch ++ on-watch
|= pax=path |= pax=path
^- (quip card _this) ^- (quip card _this)
?> ?=([%clients *] pax)
?> (is-whitelisted:hc src.bowl) ?> (is-whitelisted:hc src.bowl)
~& > "btc-provider: added client {<src.bowl>}" ~& > "btc-provider: added client {<src.bowl>}"
`this(clients.host-info (~(put in clients.host-info) src.bowl)) `this(clients.host-info (~(put in clients.host-info) src.bowl))
@ -70,7 +70,8 @@
++ on-arvo ++ on-arvo
|= [=wire =sign-arvo] |= [=wire =sign-arvo]
^- (quip card _this) ^- (quip card _this)
:: check for connectivity every 30 seconds :: check for connectivity every 30 seconds with %ping
::
?: ?=([%ping-timer *] wire) ?: ?=([%ping-timer *] wire)
:_ this :_ this
:~ :* %pass /ping/[(scot %da now.bowl)] %agent :~ :* %pass /ping/[(scot %da now.bowl)] %agent
@ -82,7 +83,7 @@
=^ cards state =^ cards state
?+ +<.sign-arvo (on-arvo:def wire sign-arvo) ?+ +<.sign-arvo (on-arvo:def wire sign-arvo)
%http-response %http-response
(handle-response:hc wire client-response.sign-arvo) (handle-rpc-response:hc wire client-response.sign-arvo)
== ==
[cards this] [cards this]
:: ::
@ -90,22 +91,35 @@
-- --
:: helper core :: helper core
|_ =bowl:gall |_ =bowl:gall
++ handle-command
|= comm=command
^- (quip card _state)
?- -.comm
%set-credentials
:- ~[(start-ping-timer ~s30)]
state(host-info [creds.comm connected=%.y clients=*(set ship)])
::
%whitelist-clients
`state(whitelist (~(uni in whitelist) clients.comm))
==
++ start-ping-timer ++ start-ping-timer
|= interval=@dr ^- card |= interval=@dr ^- card
[%pass /ping-timer %arvo %b %wait (add now.bowl interval)] [%pass /ping-timer %arvo %b %wait (add now.bowl interval)]
:: only %ping works if we're not connected
::
++ handle-action ++ handle-action
|= act=action |= act=action
|^ ^- (quip card _state) |^ ^- (quip card _state)
?: ?=(%ping -.act) ?: ?&(?!(connected.host-info) ?!(=(-.act %ping)))
~& >> "ping action"
`state
?. connected.host-info
~& >>> "Not connected to RPC" ~& >>> "Not connected to RPC"
[~[(send-update [%| [%not-connected 500]])] state] [~[(send-update [%| [%not-connected 500]])] state]
=/ ract=action:rpc =/ ract=action:rpc
?- -.act ?- -.act
%watch-address %watch-address
[%erpc %get-address-utxos address.act] [%erpc %get-address-utxos address.act]
::
%ping
[%brpc %get-block-count ~]
== ==
[~[(req-card ract)] state] [~[(req-card ract)] state]
++ req-card ++ req-card
@ -115,17 +129,13 @@
(gen-request host-info ract) (gen-request host-info ract)
[%pass /[-.act]/[-.ract]/[(scot %da now.bowl)] %arvo %i %request req out] [%pass /[-.act]/[-.ract]/[(scot %da now.bowl)] %arvo %i %request req out]
-- --
++ handle-command :: wire structure
|= comm=command :: /action-tas/rpc-action-tas/timestamp
^- (quip card _state) ::
?- -.comm :: TODO use the 2 below to handle responses
%set-credentials :: ~& > (parse-response:btc-rpc:blib rpc-resp)
`state(host-info [creds.comm connected=%.y clients=*(set ship)]) :: ~& >> (to-response (rpc-response [%erpc (parse-response:electrum-rpc:elib rpc-resp)]))
:: ++ handle-rpc-response
%whitelist-clients
`state(whitelist (~(uni in whitelist) clients.comm))
==
++ handle-response
|= [=wire response=client-response:iris] |= [=wire response=client-response:iris]
^- (quip card _state) ^- (quip card _state)
?. ?=(%finished -.response) `state ?. ?=(%finished -.response) `state
@ -147,9 +157,12 @@
:: ::
?+ wire ~|("Unexpected HTTP response" !!) ?+ wire ~|("Unexpected HTTP response" !!)
[%watch-address %erpc *] [%watch-address %erpc *]
:: use the %erpc parser here
~& >> +<.wire :: %brpc/%erpc ~& >> +<.wire :: %brpc/%erpc
~& > rpc-resp ~& > rpc-resp
`state `state
[%ping %brpc *]
`state(connected.host-info %.y)
== ==
:: ::
++ connection-error ++ connection-error
@ -160,6 +173,8 @@
[~ state] [~ state]
%400 %400
[`[%bad-request status] state] [`[%bad-request status] state]
%401
[`[%no-auth status] state]
%502 %502
[`[%not-connected status] state(connected.host-info %.y)] [`[%not-connected status] state(connected.host-info %.y)]
%504 %504
@ -232,21 +247,4 @@
:~ ['code' (uf '' no)] :~ ['code' (uf '' no)]
['message' (uf '' so)] ['message' (uf '' so)]
== == == ==
::
:: TODO: BELOW are deprecated. Rip out their functionality
++ btc-http-response
|= [status=@ud rpc-resp=response:rpc:jstd]
^- (quip card _state)
?. ?=([%result *] rpc-resp)
~& [%error +.rpc-resp]
[~ state]
:: ~& > (parse-response:btc-rpc:blib rpc-resp)
[~ state]
::
++ electrum-http-response
|= [status=@ud rpc-resp=response:rpc:jstd]
^- (quip card _state)
:: ~& >> (to-response (rpc-response [%erpc (parse-response:electrum-rpc:elib rpc-resp)]))
`state
::
-- --

View File

@ -14,6 +14,7 @@
+$ error +$ error
$% [%not-connected status=@ud] $% [%not-connected status=@ud]
[%bad-request status=@ud] [%bad-request status=@ud]
[%no-auth status=@ud]
[%http-error status=@ud] [%http-error status=@ud]
[%rpc-error ~] [%rpc-error ~]
== ==