btc-prov/wallet: btc-provider only publishes information to the specific client that is asking for it now, except for new blocks and connection info

This commit is contained in:
Logan Allen 2021-07-02 12:59:58 -05:00
parent e6a3c948fa
commit b4ca02d911
2 changed files with 58 additions and 31 deletions

View File

@ -155,7 +155,7 @@
^- (quip card _state) ^- (quip card _state)
:_ state :_ state
?. ?|(connected.host-info ?=(%ping -.act)) ?. ?|(connected.host-info ?=(%ping -.act))
~[(send-update:hc [%| %not-connected 500])] ~[(send-update:hc [%| %not-connected 500] ~)]
:_ ~ :_ ~
%+ req-card act %+ req-card act
^- action:rpc-types ^- action:rpc-types
@ -177,7 +177,7 @@
++ rpc-wire ++ rpc-wire
|= act=action |= act=action
^- wire ^- wire
/[-.act]/[(scot %ux (cut 3 [0 20] eny.bowl))] /[-.act]/(scot %p src.bowl)/(scot %ux (cut 3 [0 20] eny.bowl))
-- --
:: ::
++ on-watch ++ on-watch
@ -198,7 +198,11 @@
== ==
[%give %fact ~ %json !>(jon)]~ [%give %fact ~ %json !>(jon)]~
:: ::
?> ?=([%clients *] pax) ?> ?| ?=([%clients ~] pax)
?& ?=([%clients @ ~] pax)
=(src.bowl (slav %p i.t.pax))
==
==
?. (is-whitelisted:hc src.bowl) ?. (is-whitelisted:hc src.bowl)
~|("btc-provider: blocked client {<src.bowl>}" !!) ~|("btc-provider: blocked client {<src.bowl>}" !!)
~& > "btc-provider: accepted client {<src.bowl>}" ~& > "btc-provider: accepted client {<src.bowl>}"
@ -248,8 +252,8 @@
(connection-error status) (connection-error status)
?^ conn-err ?^ conn-err
:_ state(connected.host-info %.n) :_ state(connected.host-info %.n)
:~ (send-status:hc [%disconnected ~]) :~ (send-status:hc [%disconnected ~] ~)
(send-update:hc [%| u.conn-err]) (send-update:hc [%| u.conn-err] ~)
== ==
:: ::
%+ handle-rpc-result wire %+ handle-rpc-result wire
@ -259,32 +263,35 @@
++ handle-rpc-result ++ handle-rpc-result
|= [=wire r=result:rpc-types] |= [=wire r=result:rpc-types]
^- (quip card _state) ^- (quip card _state)
=/ ship=(unit ship)
(slaw %p (snag 1 wire))
?+ -.wire ~|("Unexpected HTTP response" !!) ?+ -.wire ~|("Unexpected HTTP response" !!)
%address-info %address-info
?> ?=([%get-address-info *] r) ?> ?=([%get-address-info *] r)
:_ state :_ state
~[(send-update:hc [%.y %address-info +.r])] ~[(send-update:hc [%.y %address-info +.r] ship)]
:: ::
%tx-info %tx-info
?> ?=([%get-tx-vals *] r) ?> ?=([%get-tx-vals *] r)
:_ state :_ state
~[(send-update:hc [%.y %tx-info +.r])] ~[(send-update:hc [%.y %tx-info +.r] ship)]
:: ::
%raw-tx %raw-tx
?> ?=([%get-raw-tx *] r) ?> ?=([%get-raw-tx *] r)
:_ state :_ state
~[(send-update:hc [%.y %raw-tx +.r])] ~[(send-update:hc [%.y %raw-tx +.r] ship)]
:: ::
%broadcast-tx %broadcast-tx
?> ?=([%broadcast-tx *] r) ?> ?=([%broadcast-tx *] r)
:_ state :_ state
~[(send-update:hc [%.y %broadcast-tx +.r])] ~[(send-update:hc [%.y %broadcast-tx +.r] ship)]
:: ::
%ping %ping
?> ?=([%get-block-info *] r) ?> ?=([%get-block-info *] r)
:_ state(connected.host-info %.y, block.host-info block.r) :_ state(connected.host-info %.y, block.host-info block.r)
:_ ~ :_ ~
%- send-status:hc %- send-status:hc
:_ ~
?: =(block.host-info block.r) ?: =(block.host-info block.r)
[%connected network.host-info block.r fee.r] [%connected network.host-info block.r fee.r]
[%new-block network.host-info block.r fee.r blockhash.r blockfilter.r] [%new-block network.host-info block.r fee.r blockhash.r blockfilter.r]
@ -292,7 +299,7 @@
%block-info %block-info
?> ?=([%get-block-info *] r) ?> ?=([%get-block-info *] r)
:_ state :_ state
~[(send-update:hc [%.y %block-info network.host-info +.r])] ~[(send-update:hc [%.y %block-info network.host-info +.r] ship)]
== ==
:: ::
++ connection-error ++ connection-error
@ -327,21 +334,24 @@
~% %btc-provider-helper ..card ~ ~% %btc-provider-helper ..card ~
|_ =bowl:gall |_ =bowl:gall
++ send-status ++ send-status
|= =status |= [=status ship=(unit ship)]
^- card ^- card
%- ?: ?=(%new-block -.status) %- ?: ?=(%new-block -.status)
~&(>> "%new-block: {<block.status>}" same) ~&(>> "%new-block: {<block.status>}" same)
same same
[%give %fact ~[/clients] %btc-provider-status !>(status)] =- [%give %fact ~[-] %btc-provider-status !>(status)]
?~ ship /clients
/clients/(scot %p u.ship)
:: ::
++ send-update ++ send-update
|= =update |= [=update ship=(unit ship)]
^- card ^- card
=+ c=[%give %fact ~[/clients] %btc-provider-update !>(update)] %- ?: ?=(%.y -.update)
?: ?=(%.y -.update) same
c ~&(>> "prov. err: {<p.update>}" same)
~& >> "prov. err: {<p.update>}" =- [%give %fact ~[-] %btc-provider-update !>(update)]
c ?~ ship /clients
/clients/(scot %p u.ship)
:: ::
++ is-whitelisted ++ is-whitelisted
~/ %is-whitelisted ~/ %is-whitelisted

View File

@ -23,6 +23,7 @@
+$ versioned-state +$ versioned-state
$% state-0 $% state-0
state-1 state-1
state-2
== ==
:: ::
+$ state-0 +$ state-0
@ -40,9 +41,8 @@
ahistorical-txs=(set txid) ahistorical-txs=(set txid)
== ==
:: ::
+$ state-1 +$ base-state
$: %1 $: prov=(unit provider)
prov=(unit provider)
walts=(map xpub:bc walt) walts=(map xpub:bc walt)
=btc-state =btc-state
=history =history
@ -54,8 +54,11 @@
=poym =poym
ahistorical-txs=(set txid) ahistorical-txs=(set txid)
== ==
::
+$ state-1 [%1 base-state]
+$ state-2 [%2 base-state]
-- --
=| state-1 =| state-2
=* state - =* state -
%- agent:dbug %- agent:dbug
^- agent:gall ^- agent:gall
@ -113,8 +116,17 @@
=| cards=(list card) =| cards=(list card)
|- |-
?- -.ver ?- -.ver
%1 %2
[cards this(state ver)] [cards this(state ver)]
::
%1
=? cards ?=(^ prov.ver)
:_ cards
=/ =dock [u.prov.ver %btc-provider]
=/ wir=wire /set-provider/(scot %p u.prov.ver)
=/ priv-wire=^wire (welp wir [%priv ~])
[%pass priv-wire %agent dock %watch /clients/(scot %p our.bowl)]
$(-.ver %2)
:: ::
%0 %0
=/ new-walts=(map xpub:bc walt) =/ new-walts=(map xpub:bc walt)
@ -161,10 +173,11 @@
== ==
:_ state(prov `[u.provider.comm %.n]) :_ state(prov `[u.provider.comm %.n])
?~ prov ?~ prov
[(watch-provider:hc u.provider.comm)]~ (watch-provider:hc u.provider.comm)
:~ (leave-provider host.u.prov) %- zing
:~ (leave-provider host.u.prov)^~
(watch-provider:hc u.provider.comm) (watch-provider:hc u.provider.comm)
(give-update:hc %change-provider `[u.provider.comm %.n]) (give-update:hc %change-provider `[u.provider.comm %.n])^~
== ==
:: ::
++ leave-provider ++ leave-provider
@ -646,8 +659,9 @@
== ==
`this `this
:_ this(prov [~ src.bowl %.n]) :_ this(prov [~ src.bowl %.n])
%- zing
:~ (watch-provider:hc src.bowl) :~ (watch-provider:hc src.bowl)
(give-update:hc %change-provider `[src.bowl %.n]) (give-update:hc %change-provider `[src.bowl %.n])^~
== ==
:: ::
%fact %fact
@ -1208,10 +1222,13 @@
:: ::
++ watch-provider ++ watch-provider
|= who=@p |= who=@p
^- card ^- (list card)
:* %pass /set-provider/[(scot %p who)] %agent [who %btc-provider] =/ =dock [who %btc-provider]
%watch /clients =/ wir=wire /set-provider/(scot %p who)
== =/ priv-wire=^wire (welp wir [%priv ~])
:+ [%pass wir %agent dock %watch /clients]
[%pass priv-wire %agent dock %watch /clients/(scot %p our.bowl)]
~
:: ::
++ give-initial ++ give-initial
^- card ^- card