WIP: check network on provider updates

This commit is contained in:
timlucmiptev 2021-02-15 12:23:56 +04:00 committed by ixv
parent a191d8fb8b
commit 5ec7e7f579
5 changed files with 87 additions and 41 deletions

View File

@ -18,7 +18,7 @@ On `~zod`. Uses "abandon abandon..." mnemonic
|start %btc-wallet
:btc-provider|command [%set-credentials api-url='http://localhost:50002' network]
:btc-wallet|command [%set-provider ~zod network]
:btc-wallet|command [%set-provider ~zod]
:btc-provider|command [%add-whitelist %users `(set ship)`(sy ~[~dopzod])]
=fprint [%4 0xbeef.dead]
@ -28,12 +28,10 @@ On `~zod`. Uses "abandon abandon..." mnemonic
On `~dopzod`. Uses "absurd sick..." mnemonic from PRIVATE.scratch.md
```
=network %main
=network %testnet
|commit %home
|start %btc-wallet
:btc-wallet|command [%set-provider ~zod network]
:btc-wallet|command [%set-provider ~zod]
=fprint [%4 0xdead.beef]
=xpubmain 'zpub6r8dKyWJ31XF6n69KKeEwLjVC5ruqAbiJ4QCqLsrV36Mvx9WEjUaiPNPGFLHNCCqgCdy6iZC8ZgHsm6a1AUTVBMVbKGemNcWFcwBGSjJKbD'

View File

@ -146,7 +146,7 @@
%groups
state(groups.whitelist (~(dif in groups.whitelist) groups.wt.comm))
==
`state(clients.host-info clean-client-list)
clean-client-list
==
:: if not connected, only %ping action is allowed
::
@ -156,8 +156,11 @@
?. ?|(connected.host-info =(-.act %ping))
~& >>> "Not connected to RPC"
[~[(send-update [%| %not-connected 500])] state]
?: ?&(?=(%check-network -.act) ?!(=(network.act network.host-info)))
%- (slog ~[leaf+"network mismatch with client {<src.bowl>}"])
(kick-client src.bowl)
=/ ract=action:rpc-types
?- -.act
?+ -.act ~|("Invalid action" !!)
%address-info
[%get-address-info address.act]
::
@ -187,6 +190,13 @@
|= act=action ^- wire
/[-.act]/[(scot %ux (cut 3 [0 20] eny.bowl))]
::
++ kick-client
|= client=ship
^- (quip card _state)
~& >>> "dropping client {<client>}"
:- ~[[%give %kick ~[/clients] `client]]
state(clients.host-info (~(dif in clients.host-info) (sy ~[client])))
::
:: Handles HTTP responses from RPC servers. Parses for errors, then handles response.
:: For actions that require collating multiple RPC calls, uses req-card to call out
:: to RPC again if more information is required.
@ -252,8 +262,8 @@
?> ?=([%get-block-info *] r)
:_ state(connected.host-info %.y, block.host-info block.r)
?: =(block.host-info block.r)
~[(send-status [%connected block.r fee.r])]
~[(send-status [%new-block block.r fee.r blockhash.r blockfilter.r])]
~[(send-status [%connected network.host-info block.r fee.r])]
~[(send-status [%new-block network.host-info block.r fee.r blockhash.r blockfilter.r])]
==
::
++ send-status
@ -297,11 +307,15 @@
:: called after a whitelist change
::
++ clean-client-list
^- (set ship)
^- (quip card _state)
=/ to-kick=(set ship)
%- sy
%+ murn ~(tap in clients.host-info)
|= c=ship ^- (unit ship)
?:((is-whitelisted c) `c ~)
?:((is-whitelisted c) ~ `c)
:_ state(clients.host-info (~(dif in clients.host-info) to-kick))
%+ turn ~(tap in to-kick)
|=(c=ship [%give %kick ~[/clients] `c])
::
++ is-client
|= user=ship ^- ?

View File

@ -1,3 +1,4 @@
:: btc-wallet
::
:: Scrys
@ -136,10 +137,13 @@
?- -.comm
%set-provider
=* sub-card
[%pass /set-provider %agent [provider.comm %btc-provider] %watch /clients]
:* %pass /set-provider/[(scot %da now.bowl)]
%agent [provider.comm %btc-provider] %watch /clients
==
:_ state(prov [~ provider.comm %.n])
?~ prov ~[sub-card]
:~ [%pass /set-provider %agent [host.u.prov %btc-provider] %leave ~]
~& >>> "%leave"
:~ [%pass /clients %agent [host.u.prov %btc-provider] %leave ~]
sub-card
==
::
@ -159,6 +163,8 @@
=* cw curr-xpub.state
=? cw ?&(?=(^ cw) =(u.cw xpub.comm))
~
=. scans (~(del by scans) [xpub.comm %0])
=. scans (~(del by scans) [xpub.comm %1])
`state(walts (~(del by walts) xpub.comm))
::
:: overwrites any payment being built in poym
@ -332,6 +338,7 @@
:: - if status is %connected, retry all pending address lookups
:: - only retry all if previously disconnected
:: - if block is updated, retry all address reqs
:: - if provider's network doesn't match network in our state, leave
::
++ handle-provider-status
|= s=status:bp
@ -341,17 +348,18 @@
?. =(host.u.prov src.bowl) `state
?- -.s
%new-block
(connected u.prov block.s fee.s `blockhash.s `blockfilter.s)
(on-connected u.prov network.s block.s fee.s `blockhash.s `blockfilter.s)
::
%connected
(connected u.prov block.s fee.s ~ ~)
(on-connected u.prov network.s block.s fee.s ~ ~)
::
%disconnected
`state(prov `[host.u.prov %.n])
`state(prov `u.prov(connected %.n))
==
::
++ connected
++ on-connected
|= $: p=provider
=network
block=@ud
fee=(unit sats)
blockhash=(unit hexb)
@ -359,17 +367,24 @@
==
^- (quip card _state)
:_ %_ state
prov `[host.p %.y]
prov `p(connected %.y)
btc-state [block fee now.bowl]
==
?: ?|(?!(connected.p) (lth block.btc-state block))
;:(weld retry-pend-piym retry-addrs retry-txs retry-scans)
retry-pend-piym
;: weld
(retry-pend-piym network)
(retry-addrs network)
(retry-txs network)
(retry-scans network)
==
(retry-pend-piym network)
--
::
++ handle-provider-update
|= upd=update:bp
^- (quip card _state)
?~ prov `state
?. =(host.u.prov src.bowl) `state
?. ?=(%.y -.upd) `state
?- -.p.upd
%address-info
@ -728,19 +743,24 @@
::
::
++ retry-scans
|= =network
^- (list card)
%- zing
%+ turn ~(tap by scans)
%+ murn ~(tap by scans)
|= [[=xpub =chyg] =batch]
-:(req-scan batch xpub chyg)
?. =(network network:(~(got by walts) xpub)) ~
`-:(req-scan batch xpub chyg)
:: +retry-addrs: get info on addresses with unconfirmed UTXOs
::
++ retry-addrs
|= =network
^- (list card)
%- zing
%+ turn ~(val by walts)
%+ murn ~(val by walts)
|= w=walt
^- (list card)
?. =(network network.w) ~
^- (unit (list card))
:- ~
%+ murn ~(tap by wach.w)
|= [a=address ad=addi]
?: %+ levy ~(tap in utxos.ad)
@ -750,17 +770,23 @@
:: +retry-txs: get info on txs without enough confirmations
::
++ retry-txs
|= =network
^- (list card)
%+ murn ~(tap by history)
|= [=txid =hest]
=/ w=(unit walt) (~(get by walts) xpub.hest)
=/ nconfs=@ud ?^(w confs.u.w confs:defaults)
?: (gte confs.hest nconfs) ~
=/ w (~(get by walts) xpub.hest)
?~ w ~
?. =(network network.u.w) ~
?: (gte confs.hest confs.u.w) ~
`(poke-provider [%tx-info txid])
::
++ retry-poym
|= =network
^- (list card)
?~ poym ~
=/ w (~(get by walts) xpub.u.poym)
?~ w ~
?. =(network network.u.w) ~
%+ weld
?~ signed-tx.u.poym ~
~[(poke-provider [%broadcast-tx u.signed-tx.u.poym])]
@ -770,9 +796,14 @@
:: +retry-pend-piym: check whether txids in pend-piym are in mempool
::
++ retry-pend-piym
|= =network
^- (list card)
%+ turn ~(tap in ~(key by pend.piym))
|=(=txid (poke-provider [%tx-info txid]))
%+ murn ~(tap by pend.piym)
|= [=txid p=payment]
=/ w (~(get by walts) xpub.p)
?~ w ~
?. =(network network.u.w) ~
`(poke-provider [%tx-info txid])
::
++ poke-provider
|= [act=action:bp]

View File

@ -31,7 +31,10 @@
[%raw-tx txid=hexb]
[%broadcast-tx rawtx=hexb]
[%ping ~]
check-network
==
+$ check-network [%check-network =network]
::
+$ result
$% [%address-info =address utxos=(set utxo) used=? block=@ud]
[%tx-info =info:tx]
@ -46,8 +49,8 @@
==
+$ update (each result error)
+$ status
$% [%connected block=@ud fee=(unit sats)]
[%new-block block=@ud fee=(unit sats) blockhash=hexb blockfilter=hexb]
$% [%connected =network block=@ud fee=(unit sats)]
[%new-block =network block=@ud fee=(unit sats) blockhash=hexb blockfilter=hexb]
[%disconnected ~]
==
::

View File

@ -10,7 +10,7 @@
+$ poym (unit txbu)
::
+$ command
$% [%set-provider provider=ship =network]
$% [%set-provider provider=ship]
[%set-current-wallet =xpub]
[%add-wallet =xpub =fprint scan-to=(unit scon) max-gap=(unit @ud) confs=(unit @ud)]
[%delete-wallet =xpub]