2021-02-12 17:37:21 +03:00
|
|
|
:: btc-wallet
|
|
|
|
::
|
|
|
|
:: Scrys
|
|
|
|
:: x/scanned: (list xpub) of all scanned wallets
|
|
|
|
:: x/balance/xpub: balance (in sats) of wallet
|
2021-03-27 00:12:20 +03:00
|
|
|
/- *btc-wallet, bp=btc-provider, file-server, launch-store
|
2021-02-21 13:13:50 +03:00
|
|
|
/+ dbug, default-agent, bl=btc, bc=bitcoin, bip32
|
2021-02-12 17:37:21 +03:00
|
|
|
|%
|
|
|
|
++ defaults
|
|
|
|
|%
|
|
|
|
++ params
|
|
|
|
:* batch-size=20
|
|
|
|
fam-limit=10
|
|
|
|
piym-limit=3
|
|
|
|
==
|
|
|
|
++ confs 6
|
2021-02-13 15:14:50 +03:00
|
|
|
++ fee 100
|
2021-02-12 17:37:21 +03:00
|
|
|
--
|
|
|
|
::
|
|
|
|
+$ versioned-state
|
|
|
|
$% state-0
|
|
|
|
==
|
|
|
|
:: batch-size: how many addresses to send out at once for checking
|
|
|
|
:: last-block: most recent block seen by the store
|
|
|
|
::
|
|
|
|
+$ state-0
|
|
|
|
$: %0
|
|
|
|
prov=(unit provider)
|
2021-02-21 13:13:50 +03:00
|
|
|
walts=(map xpub:bc walt)
|
2021-02-12 17:37:21 +03:00
|
|
|
=btc-state
|
|
|
|
=history
|
2021-02-21 13:13:50 +03:00
|
|
|
curr-xpub=(unit xpub:bc)
|
2021-02-12 17:37:21 +03:00
|
|
|
=scans
|
|
|
|
=params
|
|
|
|
feybs=(map ship sats)
|
|
|
|
=piym
|
|
|
|
=poym
|
2021-04-09 02:11:31 +03:00
|
|
|
ahistorical-txs=(set txid)
|
2021-02-12 17:37:21 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
+$ card card:agent:gall
|
|
|
|
::
|
|
|
|
--
|
|
|
|
=| state-0
|
|
|
|
=* state -
|
|
|
|
%- agent:dbug
|
|
|
|
^- agent:gall
|
|
|
|
=<
|
|
|
|
|_ =bowl:gall
|
|
|
|
+* this .
|
|
|
|
def ~(. (default-agent this %|) bowl)
|
|
|
|
hc ~(. +> bowl)
|
|
|
|
::
|
|
|
|
++ on-init
|
|
|
|
^- (quip card _this)
|
|
|
|
~& > '%btc-wallet initialized'
|
2021-03-27 00:12:20 +03:00
|
|
|
=/ file
|
|
|
|
[%file-server-action !>([%serve-dir /'~btc' /app/btc-wallet %.n %.n])]
|
|
|
|
=/ tile
|
|
|
|
:- %launch-action
|
|
|
|
!> :+ %add
|
|
|
|
%btc-wallet
|
|
|
|
[[%basic 'Wallet' '/~btc/img/tile.png' '/~btc'] %.y]
|
|
|
|
:- :~ [%pass /btc-wallet-server %agent [our.bowl %file-server] %poke file]
|
|
|
|
[%pass /btc-wallet-tile %agent [our.bowl %launch] %poke tile]
|
|
|
|
==
|
2021-02-12 17:37:21 +03:00
|
|
|
%_ this
|
|
|
|
state
|
|
|
|
:* %0
|
|
|
|
~
|
2021-02-21 13:13:50 +03:00
|
|
|
*(map xpub:bc walt)
|
2021-02-12 17:37:21 +03:00
|
|
|
*^btc-state
|
|
|
|
*^history
|
|
|
|
~
|
|
|
|
*^scans
|
2021-02-13 15:14:50 +03:00
|
|
|
params:defaults
|
2021-02-12 17:37:21 +03:00
|
|
|
*(map ship sats)
|
|
|
|
*^piym
|
|
|
|
*^poym
|
2021-04-09 02:11:31 +03:00
|
|
|
~
|
2021-02-12 17:37:21 +03:00
|
|
|
==
|
|
|
|
==
|
|
|
|
++ on-save
|
|
|
|
^- vase
|
|
|
|
!>(state)
|
|
|
|
++ on-load
|
|
|
|
|= old-state=vase
|
|
|
|
^- (quip card _this)
|
|
|
|
~& > '%btc-wallet recompiled'
|
|
|
|
`this(state !<(versioned-state old-state))
|
|
|
|
++ on-poke
|
|
|
|
|= [=mark =vase]
|
|
|
|
^- (quip card _this)
|
|
|
|
=^ cards state
|
|
|
|
?+ mark (on-poke:def mark vase)
|
|
|
|
%btc-wallet-command
|
2021-02-18 15:13:06 +03:00
|
|
|
?> =(our.bowl src.bowl)
|
2021-02-13 15:14:50 +03:00
|
|
|
(handle-command:hc !<(command vase))
|
2021-02-18 15:13:06 +03:00
|
|
|
::
|
|
|
|
%btc-wallet-action
|
|
|
|
?< =(our.bowl src.bowl)
|
|
|
|
(handle-action:hc !<(action vase))
|
|
|
|
::
|
|
|
|
%btc-wallet-internal
|
|
|
|
?> =(our.bowl src.bowl)
|
|
|
|
(handle-internal:hc !<(internal vase))
|
2021-02-12 17:37:21 +03:00
|
|
|
==
|
|
|
|
[cards this]
|
|
|
|
++ on-peek
|
|
|
|
|= pax=path
|
|
|
|
^- (unit (unit cage))
|
|
|
|
?+ pax (on-peek:def pax)
|
2021-04-02 01:33:27 +03:00
|
|
|
[%x %configured ~]
|
|
|
|
=/ provider=json
|
|
|
|
?~ prov ~
|
|
|
|
[%s (scot %p host.u.prov)]
|
|
|
|
=/ result=json
|
|
|
|
%- pairs:enjs:format
|
|
|
|
:~ [%'provider' provider]
|
|
|
|
[%'hasWallet' b+?=(^ walts)]
|
|
|
|
==
|
|
|
|
``json+!>(result)
|
|
|
|
::
|
2021-02-12 17:37:21 +03:00
|
|
|
[%x %scanned ~]
|
|
|
|
``noun+!>(scanned-wallets)
|
|
|
|
::
|
|
|
|
[%x %balance @ ~]
|
2021-02-21 13:13:50 +03:00
|
|
|
``noun+!>((balance:hc (xpub:bc +>-.pax)))
|
2021-02-12 17:37:21 +03:00
|
|
|
==
|
|
|
|
++ on-agent
|
|
|
|
|= [=wire =sign:agent:gall]
|
|
|
|
^- (quip card _this)
|
|
|
|
?+ -.sign (on-agent:def wire sign)
|
|
|
|
%kick
|
|
|
|
~& >>> "kicked from prov {<src.bowl>}"
|
|
|
|
?~ prov `this
|
|
|
|
?: ?& ?=(%set-provider -.wire)
|
|
|
|
=(host.u.prov src.bowl)
|
|
|
|
==
|
|
|
|
`this(prov ~)
|
|
|
|
`this
|
|
|
|
::
|
|
|
|
%fact
|
|
|
|
=^ cards state
|
|
|
|
?+ p.cage.sign `state
|
|
|
|
%btc-provider-status
|
|
|
|
(handle-provider-status:hc !<(status:bp q.cage.sign))
|
|
|
|
::
|
|
|
|
%btc-provider-update
|
|
|
|
(handle-provider-update:hc !<(update:bp q.cage.sign))
|
2021-04-02 01:33:27 +03:00
|
|
|
::
|
|
|
|
%json
|
|
|
|
?> ?=([%permitted @ ~] wire)
|
|
|
|
=/ who (slav %p i.t.wire)
|
|
|
|
:_ state
|
|
|
|
:~ [%give %fact ~[/all] cage.sign]
|
|
|
|
[%pass wire %agent [who %btc-provider] %leave ~]
|
|
|
|
==
|
2021-02-12 17:37:21 +03:00
|
|
|
==
|
|
|
|
[cards this]
|
|
|
|
==
|
|
|
|
::
|
2021-04-02 01:33:27 +03:00
|
|
|
++ on-watch
|
|
|
|
|= =path
|
|
|
|
^- (quip card _this)
|
|
|
|
?> (team:title our.bowl src.bowl)
|
|
|
|
?> ?=([%all ~] path)
|
|
|
|
=/ provider=json
|
|
|
|
?~ prov ~
|
|
|
|
[%s (scot %p host.u.prov)]
|
|
|
|
=/ cb=(unit sats) current-balance:hc
|
|
|
|
=/ wallet=json
|
|
|
|
?~ walts ~
|
|
|
|
%- pairs:enjs:format
|
|
|
|
:~ balance+?~(cb ~ (numb:enjs:format u.cb))
|
|
|
|
==
|
|
|
|
=/ initial=json
|
|
|
|
%+ frond:enjs:format
|
|
|
|
%initial
|
|
|
|
%- pairs:enjs:format
|
|
|
|
:~ [%'provider' provider]
|
|
|
|
[%'hasWallet' b+?=(^ walts)]
|
|
|
|
[%wallet wallet]
|
|
|
|
==
|
|
|
|
:_ this
|
|
|
|
[%give %fact ~ %json !>(initial)]~
|
|
|
|
::
|
2021-02-12 17:37:21 +03:00
|
|
|
++ on-leave on-leave:def
|
|
|
|
++ on-arvo on-arvo:def
|
|
|
|
++ on-fail on-fail:def
|
|
|
|
--
|
|
|
|
|_ =bowl:gall
|
|
|
|
++ handle-command
|
2021-02-18 17:09:06 +03:00
|
|
|
|= comm=command
|
2021-02-12 17:37:21 +03:00
|
|
|
^- (quip card _state)
|
|
|
|
?- -.comm
|
|
|
|
%set-provider
|
|
|
|
=* sub-card
|
2021-02-15 14:59:14 +03:00
|
|
|
:* %pass /set-provider/[(scot %p provider.comm)]
|
2021-02-15 11:23:56 +03:00
|
|
|
%agent [provider.comm %btc-provider] %watch /clients
|
|
|
|
==
|
2021-02-12 17:37:21 +03:00
|
|
|
:_ state(prov [~ provider.comm %.n])
|
|
|
|
?~ prov ~[sub-card]
|
2021-02-15 14:59:14 +03:00
|
|
|
:~ [%pass /set-provider/[(scot %p host.u.prov)] %agent [host.u.prov %btc-provider] %leave ~]
|
2021-02-12 17:37:21 +03:00
|
|
|
sub-card
|
|
|
|
==
|
2021-04-02 01:33:27 +03:00
|
|
|
::
|
|
|
|
%check-provider
|
|
|
|
=/ pax /permitted/(scot %p provider.comm)
|
|
|
|
:_ state
|
|
|
|
[%pass pax %agent [provider.comm %btc-provider] %watch pax]~
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
%set-current-wallet
|
2021-02-14 13:17:58 +03:00
|
|
|
(set-curr-xpub xpub.comm)
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
%add-wallet
|
2021-02-13 15:14:50 +03:00
|
|
|
?~ (~(has by walts) xpub.comm)
|
|
|
|
((slog ~[leaf+"xpub already in wallet"]) `state)
|
2021-02-21 13:13:50 +03:00
|
|
|
=/ w=walt (from-xpub:bl +.comm)
|
2021-02-12 17:37:21 +03:00
|
|
|
=. walts (~(put by walts) xpub.comm w)
|
2021-02-14 13:17:58 +03:00
|
|
|
=^ c1 state (init-batches xpub.comm (dec max-gap.w))
|
|
|
|
=^ c2 state (set-curr-xpub xpub.comm)
|
|
|
|
[(weld c1 c2) state]
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
%delete-wallet
|
|
|
|
=* cw curr-xpub.state
|
|
|
|
=? cw ?&(?=(^ cw) =(u.cw xpub.comm))
|
|
|
|
~
|
2021-02-15 11:23:56 +03:00
|
|
|
=. scans (~(del by scans) [xpub.comm %0])
|
|
|
|
=. scans (~(del by scans) [xpub.comm %1])
|
2021-02-12 17:37:21 +03:00
|
|
|
`state(walts (~(del by walts) xpub.comm))
|
|
|
|
::
|
|
|
|
:: overwrites any payment being built in poym
|
|
|
|
::
|
2021-03-01 12:13:07 +03:00
|
|
|
%init-payment
|
2021-02-12 17:37:21 +03:00
|
|
|
~| "Can't pay ourselves; no comets; can't do while tx is being signed"
|
|
|
|
?< =(src.bowl payee.comm)
|
|
|
|
?< ?=(%pawn (clan:title payee.comm))
|
|
|
|
?< is-broadcasting
|
|
|
|
:_ state(poym ~, feybs (~(put by feybs) payee.comm feyb.comm))
|
2021-02-18 15:13:06 +03:00
|
|
|
~[(poke-peer payee.comm [%gen-pay-address value.comm])]
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
%broadcast-tx
|
|
|
|
?~ prov ~|("Provider not connected" !!)
|
2021-02-21 13:13:50 +03:00
|
|
|
=+ signed=(from-cord:hxb:bc txhex.comm)
|
2021-02-12 17:37:21 +03:00
|
|
|
=/ tx-match=?
|
|
|
|
?~ poym %.n
|
2021-02-21 13:13:50 +03:00
|
|
|
=((get-id:txu:bc (decode:txu:bc signed)) ~(get-txid txb:bl u.poym))
|
2021-02-12 17:37:21 +03:00
|
|
|
:- ?. tx-match
|
|
|
|
((slog leaf+"txid didn't match txid in wallet") ~)
|
|
|
|
~[(poke-provider [%broadcast-tx signed])]
|
|
|
|
?. tx-match state
|
|
|
|
?~ poym state
|
2021-02-13 15:14:50 +03:00
|
|
|
state(signed-tx.u.poym `signed)
|
2021-02-12 17:37:21 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
++ handle-action
|
|
|
|
|= act=action
|
|
|
|
^- (quip card _state)
|
|
|
|
?- -.act
|
2021-02-18 15:13:06 +03:00
|
|
|
:: comets can't pay (could spam address requests)
|
2021-02-13 15:14:50 +03:00
|
|
|
:: reuses payment address for ship if ship in piym already
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
%gen-pay-address
|
2021-02-18 15:13:06 +03:00
|
|
|
~| "no comets"
|
2021-02-12 17:37:21 +03:00
|
|
|
?< ?=(%pawn (clan:title src.bowl))
|
2021-02-18 15:13:06 +03:00
|
|
|
?~ curr-xpub ~|("btc-wallet: no curr-xpub set" !!)
|
|
|
|
|^
|
|
|
|
=^ cards state reuse-address
|
|
|
|
?^ cards [cards state] :: if cards returned, means we already have an address
|
2021-02-21 13:13:50 +03:00
|
|
|
=+ f=(fam:bl our.bowl now.bowl src.bowl)
|
2021-02-12 17:37:21 +03:00
|
|
|
=+ n=(~(gut by num-fam.piym) f 0)
|
2021-02-12 20:43:25 +03:00
|
|
|
?: (gte n fam-limit.params)
|
|
|
|
~|("More than {<fam-limit.params>} addresses for moons + planet" !!)
|
2021-02-12 17:37:21 +03:00
|
|
|
=. state state(num-fam.piym (~(put by num-fam.piym) f +(n)))
|
2021-02-13 15:14:50 +03:00
|
|
|
=^ a=address state
|
|
|
|
(generate-address u.curr-xpub %0)
|
2021-03-01 12:13:07 +03:00
|
|
|
:- ~[(poke-peer src.bowl [%give-pay-address a value.act])]
|
2021-02-13 15:14:50 +03:00
|
|
|
state(ps.piym (~(put by ps.piym) src.bowl [~ u.curr-xpub a src.bowl value.act]))
|
|
|
|
::
|
|
|
|
++ generate-address
|
2021-02-21 13:13:50 +03:00
|
|
|
|= [=xpub:bc =chyg]
|
2021-02-13 15:14:50 +03:00
|
|
|
=/ uw=(unit walt) (~(get by walts) xpub)
|
|
|
|
?: ?|(?=(~ uw) ?!(scanned.u.uw))
|
|
|
|
~|("no wallet with xpub or wallet not scanned yet" !!)
|
|
|
|
=/ [addr=address =idx w=walt]
|
2021-02-21 13:13:50 +03:00
|
|
|
~(gen-address wad:bl u.uw chyg)
|
2021-02-13 15:14:50 +03:00
|
|
|
[addr state(walts (~(put by walts) xpub w))]
|
2021-02-18 15:13:06 +03:00
|
|
|
::
|
|
|
|
++ reuse-address
|
|
|
|
^- (quip card _state)
|
|
|
|
=* payer src.bowl
|
|
|
|
=+ p=(~(get by ps.piym) payer)
|
|
|
|
?~ p `state
|
|
|
|
?^ pend.u.p ~|("%gen-address: {<payer>} already has pending payment to us" !!)
|
|
|
|
=+ newp=u.p(value value.act)
|
|
|
|
:_ state(ps.piym (~(put by ps.piym) payer newp))
|
2021-03-01 12:13:07 +03:00
|
|
|
~[(poke-peer payer [%give-pay-address address.newp value.act])]
|
2021-02-13 15:14:50 +03:00
|
|
|
--
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
2021-03-01 12:13:07 +03:00
|
|
|
%give-pay-address
|
2021-02-12 17:37:21 +03:00
|
|
|
?: =(src.bowl our.bowl) ~|("Can't pay ourselves" !!)
|
|
|
|
?: is-broadcasting ~|("Broadcasting a transaction" !!)
|
|
|
|
?~ curr-xpub ~|("btc-wallet-hook: no curr-xpub set" !!)
|
2021-02-13 15:14:50 +03:00
|
|
|
=+ feyb=(~(gut by feybs) src.bowl ?~(fee.btc-state fee:defaults u.fee.btc-state))
|
|
|
|
|^
|
2021-02-12 17:37:21 +03:00
|
|
|
=^ tb=(unit txbu) state
|
2021-02-13 15:14:50 +03:00
|
|
|
(generate-txbu u.curr-xpub `src.bowl feyb ~[[address.act value.act ~]])
|
|
|
|
:_ state(poym tb)
|
2021-02-12 17:37:21 +03:00
|
|
|
?~ tb ~
|
|
|
|
%+ turn txis.u.tb
|
2021-02-14 13:17:58 +03:00
|
|
|
|=(=txi (poke-provider [%raw-tx txid.utxo.txi]))
|
2021-02-13 15:14:50 +03:00
|
|
|
::
|
|
|
|
++ generate-txbu
|
2021-02-21 13:13:50 +03:00
|
|
|
|= [=xpub:bc payee=(unit ship) feyb=sats txos=(list txo)]
|
2021-02-13 15:14:50 +03:00
|
|
|
^- [(unit txbu) _state]
|
|
|
|
=/ uw (~(get by walts) xpub)
|
|
|
|
?: ?|(?=(~ uw) ?!(scanned.u.uw))
|
|
|
|
~|("no wallet with xpub or wallet not scanned yet" !!)
|
|
|
|
=/ [tb=(unit txbu) chng=(unit sats)]
|
2021-02-21 13:13:50 +03:00
|
|
|
%~ with-change sut:bl
|
2021-02-13 15:14:50 +03:00
|
|
|
[u.uw eny.bowl block.btc-state payee feyb txos]
|
2021-02-14 13:17:58 +03:00
|
|
|
?~ tb ((slog ~[leaf+"insufficient balance or not enough confirmed balance"]) [tb state])
|
2021-02-13 15:14:50 +03:00
|
|
|
:: if no change, return txbu; else add change output to txbu
|
|
|
|
::
|
|
|
|
?~ chng [tb state]
|
2021-02-18 15:13:06 +03:00
|
|
|
=/ [addr=address =idx w=walt]
|
2021-02-21 13:13:50 +03:00
|
|
|
~(nixt-address wad:bl u.uw %1)
|
|
|
|
:- `(~(add-output txb:bl u.tb) addr u.chng `(~(hdkey wad:bl w %1) idx))
|
2021-02-13 15:14:50 +03:00
|
|
|
state(walts (~(put by walts) xpub w))
|
|
|
|
--
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
:: %expect-payment
|
|
|
|
:: - check that payment is in piym
|
|
|
|
:: - replace pend.payment with incoming txid (lock)
|
2021-02-14 13:17:58 +03:00
|
|
|
:: - add txid to pend.piym
|
2021-02-12 17:37:21 +03:00
|
|
|
:: - request tx-info from provider
|
|
|
|
::
|
|
|
|
%expect-payment
|
|
|
|
|^
|
|
|
|
=+ pay=(~(get by ps.piym) src.bowl)
|
|
|
|
~| "%expect-payment: matching payment not in piym"
|
|
|
|
?~ pay !!
|
|
|
|
?> (piym-matches u.pay)
|
|
|
|
:_ (update-pend-piym txid.act u.pay(pend `txid.act))
|
|
|
|
?~ prov ~
|
2021-02-12 20:43:25 +03:00
|
|
|
~[(poke-provider [%tx-info txid.act])]
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
++ piym-matches
|
|
|
|
|= p=payment
|
|
|
|
?& =(payer.p src.bowl)
|
|
|
|
=(value.p value.act)
|
|
|
|
==
|
2021-03-01 12:13:07 +03:00
|
|
|
::
|
|
|
|
++ update-pend-piym
|
|
|
|
|= [txid=hexb p=payment]
|
|
|
|
^- _state
|
|
|
|
?~ pend.p ~|("update-pend-piym: no pending payment" !!)
|
|
|
|
%= state
|
|
|
|
ps.piym (~(put by ps.piym) payer.p p)
|
|
|
|
pend.piym (~(put by pend.piym) txid p)
|
|
|
|
==
|
2021-02-12 17:37:21 +03:00
|
|
|
--
|
|
|
|
==
|
|
|
|
::
|
2021-02-18 15:13:06 +03:00
|
|
|
++ handle-internal
|
|
|
|
|= intr=internal
|
|
|
|
^- (quip card _state)
|
|
|
|
?- -.intr
|
|
|
|
%add-poym-raw-txi
|
2021-03-01 12:13:07 +03:00
|
|
|
|^
|
2021-02-18 15:13:06 +03:00
|
|
|
?> =(src.bowl our.bowl)
|
|
|
|
?~ poym `state
|
|
|
|
=. txis.u.poym
|
|
|
|
(update-poym-txis txis.u.poym +.intr)
|
|
|
|
:_ state
|
2021-02-21 13:13:50 +03:00
|
|
|
=+ pb=~(to-psbt txb:bl u.poym)
|
2021-02-18 15:13:06 +03:00
|
|
|
?~ pb ~
|
2021-02-21 13:13:50 +03:00
|
|
|
=+ vb=~(vbytes txb:bl u.poym)
|
|
|
|
=+ fee=~(fee txb:bl u.poym)
|
2021-02-18 15:13:06 +03:00
|
|
|
~& >> "{<vb>} vbytes, {<(div fee vb)>} sats/byte, {<fee>} sats fee"
|
|
|
|
%- (slog [%leaf "PSBT: {<u.pb>}"]~)
|
2021-04-12 19:24:27 +03:00
|
|
|
=/ psbt=json
|
|
|
|
(frond:enjs:format %psbt [%s u.pb])
|
|
|
|
[%give %fact ~[/all] %json !>(psbt)]~
|
2021-03-01 12:13:07 +03:00
|
|
|
:: update outgoing payment with a rawtx, if the txid is in poym's txis
|
|
|
|
::
|
|
|
|
++ update-poym-txis
|
|
|
|
|= [txis=(list txi) txid=hexb rawtx=hexb]
|
|
|
|
^- (list txi)
|
|
|
|
=| i=@
|
|
|
|
|- ?: (gte i (lent txis)) txis
|
|
|
|
=/ ith=txi (snag i txis)
|
|
|
|
=? txis =(txid txid.utxo.ith)
|
|
|
|
(snap txis i `txi`ith(rawtx `rawtx))
|
|
|
|
$(i +(i))
|
|
|
|
--
|
2021-02-18 15:13:06 +03:00
|
|
|
:: delete an incoming/outgoing payment when we see it included in a tx
|
|
|
|
::
|
|
|
|
%close-pym
|
|
|
|
?> =(src.bowl our.bowl)
|
2021-02-18 15:59:32 +03:00
|
|
|
|^
|
2021-02-18 15:13:06 +03:00
|
|
|
=^ cards state
|
|
|
|
?. included.ti.intr
|
|
|
|
`state
|
|
|
|
?: (~(has by pend.piym) txid.ti.intr)
|
|
|
|
(piym-to-history ti.intr)
|
|
|
|
?: (poym-has-txid txid.ti.intr)
|
|
|
|
(poym-to-history ti.intr)
|
|
|
|
`state
|
|
|
|
:- cards
|
|
|
|
(handle-tx-info ti.intr)
|
2021-02-18 15:59:32 +03:00
|
|
|
::
|
|
|
|
++ poym-has-txid
|
|
|
|
|= txid=hexb
|
|
|
|
^- ?
|
|
|
|
?~ poym %.n
|
|
|
|
?~ signed-tx.u.poym %.n
|
2021-02-21 13:13:50 +03:00
|
|
|
=(txid (get-id:txu:bc (decode:txu:bc u.signed-tx.u.poym)))
|
2021-02-18 15:59:32 +03:00
|
|
|
:: - checks whether poym has a signed tx
|
|
|
|
:: - checks whether the txid matches that signed tx, if not, skip
|
|
|
|
:: - clears poym
|
|
|
|
:: - returns card that adds hest to history
|
|
|
|
::
|
|
|
|
++ poym-to-history
|
|
|
|
|= ti=info:tx
|
|
|
|
^- (quip card _state)
|
|
|
|
|^
|
|
|
|
?~ poym `state
|
|
|
|
?~ signed-tx.u.poym `state
|
|
|
|
?. (poym-has-txid txid.ti)
|
|
|
|
`state
|
|
|
|
=+ vout=(get-vout txos.u.poym)
|
|
|
|
?~ vout ~|("poym-to-history: poym should always have an output" !!)
|
|
|
|
:- ~
|
|
|
|
%= state
|
|
|
|
poym ~
|
|
|
|
history
|
|
|
|
(add-history-entry ti xpub.u.poym our.bowl payee.u.poym u.vout)
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ get-vout
|
|
|
|
|= txos=(list txo)
|
|
|
|
^- (unit @ud)
|
|
|
|
=| idx=@ud
|
|
|
|
|- ?~ txos ~
|
|
|
|
?~ hk.i.txos `idx
|
|
|
|
$(idx +(idx), txos t.txos)
|
|
|
|
--
|
|
|
|
:: - checks whether txid in pend.piym
|
|
|
|
:: - checks whether ti has a matching value output to piym
|
|
|
|
:: - if no match found, just deletes pend.piym with this tx
|
|
|
|
:: stops peer from spamming txids
|
|
|
|
:: - returns card that adds hest to history
|
|
|
|
::
|
|
|
|
++ piym-to-history
|
|
|
|
|= ti=info:tx
|
|
|
|
|^ ^- (quip card _state)
|
|
|
|
=+ pay=(~(get by pend.piym) txid.ti)
|
|
|
|
?~ pay `state
|
|
|
|
:: if no matching output in piym, delete from pend.piym to stop DDOS of txids
|
|
|
|
::
|
|
|
|
=+ vout=(get-vout value.u.pay)
|
|
|
|
?~ vout
|
|
|
|
`(del-pend-piym txid.ti)
|
|
|
|
=. state (del-all-piym txid.ti payer.u.pay)
|
|
|
|
`state(history (add-history-entry [ti xpub.u.pay payer.u.pay `our.bowl u.vout]))
|
|
|
|
::
|
|
|
|
++ get-vout
|
|
|
|
|= value=sats
|
|
|
|
^- (unit @ud)
|
|
|
|
=| idx=@ud
|
|
|
|
=+ os=outputs.ti
|
|
|
|
|- ?~ os ~
|
|
|
|
?: =(value.i.os value)
|
|
|
|
`idx
|
|
|
|
$(os t.os, idx +(idx))
|
|
|
|
::
|
|
|
|
::
|
|
|
|
++ del-pend-piym
|
|
|
|
|= txid=hexb
|
|
|
|
^- _state
|
|
|
|
state(pend.piym (~(del by pend.piym) txid.ti))
|
|
|
|
::
|
|
|
|
++ del-all-piym
|
|
|
|
|= [txid=hexb payer=ship]
|
|
|
|
^- _state
|
|
|
|
=+ nf=(~(gut by num-fam.piym) payer 1)
|
|
|
|
%= state
|
|
|
|
pend.piym (~(del by pend.piym) txid)
|
|
|
|
ps.piym (~(del by ps.piym) payer)
|
|
|
|
num-fam.piym (~(put by num-fam.piym) payer (dec nf))
|
|
|
|
==
|
|
|
|
--
|
|
|
|
::
|
|
|
|
++ add-history-entry
|
2021-02-21 13:13:50 +03:00
|
|
|
|= [ti=info:tx =xpub:bc payer=ship payee=(unit ship) vout=@ud]
|
2021-02-18 15:59:32 +03:00
|
|
|
^- ^history
|
|
|
|
=/ =hest
|
|
|
|
:* xpub
|
|
|
|
txid.ti
|
|
|
|
confs.ti
|
|
|
|
recvd.ti
|
|
|
|
(turn inputs.ti |=(i=val:tx [i `payer]))
|
|
|
|
%+ turn outputs.ti
|
|
|
|
|= o=val:tx
|
|
|
|
?: =(pos.o vout) :: check whether this is the output that went to payee
|
|
|
|
[o payee]
|
|
|
|
[o `payer]
|
|
|
|
==
|
|
|
|
(~(put by history) txid.hest hest)
|
|
|
|
--
|
2021-02-18 15:13:06 +03:00
|
|
|
::
|
|
|
|
%fail-broadcast-tx
|
|
|
|
?> =(src.bowl our.bowl)
|
|
|
|
~& >>> "%fail-broadcast-tx"
|
|
|
|
`state(poym ~)
|
|
|
|
::
|
|
|
|
%succeed-broadcast-tx
|
|
|
|
?> =(src.bowl our.bowl)
|
|
|
|
~& > "%succeed-broadcast-tx"
|
|
|
|
:_ state
|
|
|
|
?~ prov ~
|
|
|
|
:- (poke-provider [%tx-info txid.intr])
|
|
|
|
?~ poym ~
|
|
|
|
?~ payee.u.poym ~
|
|
|
|
:_ ~
|
|
|
|
%- poke-peer
|
|
|
|
:* u.payee.u.poym
|
|
|
|
%expect-payment
|
|
|
|
txid.intr
|
|
|
|
value:(snag 0 txos.u.poym)
|
|
|
|
==
|
|
|
|
==
|
|
|
|
::
|
2021-02-12 17:37:21 +03:00
|
|
|
:: +handle-provider-status: handle connectivity updates from provider
|
2021-02-14 13:17:58 +03:00
|
|
|
:: - retry pend.piym on any %connected event, since we're checking mempool
|
2021-02-12 17:37:21 +03:00
|
|
|
:: - if status is %connected, retry all pending address lookups
|
|
|
|
:: - only retry all if previously disconnected
|
|
|
|
:: - if block is updated, retry all address reqs
|
2021-02-15 11:23:56 +03:00
|
|
|
:: - if provider's network doesn't match network in our state, leave
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
++ handle-provider-status
|
|
|
|
|= s=status:bp
|
|
|
|
^- (quip card _state)
|
|
|
|
|^
|
2021-04-02 01:33:27 +03:00
|
|
|
=^ cards state
|
|
|
|
?~ prov `state
|
|
|
|
?. =(host.u.prov src.bowl) `state
|
|
|
|
?- -.s
|
|
|
|
%new-block
|
|
|
|
(on-connected u.prov network.s block.s fee.s `blockhash.s `blockfilter.s)
|
|
|
|
::
|
|
|
|
%connected
|
|
|
|
(on-connected u.prov network.s block.s fee.s ~ ~)
|
|
|
|
::
|
|
|
|
%disconnected
|
|
|
|
`state(prov `u.prov(connected %.n))
|
|
|
|
==
|
|
|
|
:_ state
|
|
|
|
:_ cards
|
|
|
|
[%give %fact ~[/all] %btc-provider-status !>(s)]
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
2021-02-15 11:23:56 +03:00
|
|
|
++ on-connected
|
2021-02-12 17:37:21 +03:00
|
|
|
|= $: p=provider
|
2021-02-15 11:23:56 +03:00
|
|
|
=network
|
2021-02-12 17:37:21 +03:00
|
|
|
block=@ud
|
|
|
|
fee=(unit sats)
|
|
|
|
blockhash=(unit hexb)
|
|
|
|
blockfilter=(unit hexb)
|
|
|
|
==
|
|
|
|
^- (quip card _state)
|
|
|
|
:_ %_ state
|
2021-02-15 11:23:56 +03:00
|
|
|
prov `p(connected %.y)
|
|
|
|
btc-state [block fee now.bowl]
|
2021-02-12 17:37:21 +03:00
|
|
|
==
|
|
|
|
?: ?|(?!(connected.p) (lth block.btc-state block))
|
2021-02-15 11:23:56 +03:00
|
|
|
;: weld
|
2021-04-09 02:11:31 +03:00
|
|
|
(retry-pend-piym network)
|
|
|
|
(retry-poym network)
|
|
|
|
(retry-addrs network)
|
|
|
|
(retry-txs network)
|
|
|
|
(retry-scans network)
|
|
|
|
retry-ahistorical-txs
|
2021-02-15 11:23:56 +03:00
|
|
|
==
|
2021-04-09 02:11:31 +03:00
|
|
|
;: weld
|
|
|
|
retry-ahistorical-txs
|
|
|
|
(retry-pend-piym network)
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ retry-ahistorical-txs
|
|
|
|
^- (list card)
|
|
|
|
%+ turn ~(tap in ahistorical-txs)
|
|
|
|
|= =txid
|
|
|
|
(poke-provider [%tx-info txid])
|
2021-02-18 15:13:06 +03:00
|
|
|
::
|
|
|
|
++ retry-scans
|
|
|
|
|= =network
|
|
|
|
^- (list card)
|
|
|
|
%- zing
|
|
|
|
%+ murn ~(tap by scans)
|
2021-02-21 13:13:50 +03:00
|
|
|
|= [[=xpub:bc =chyg] =batch]
|
2021-02-18 15:13:06 +03:00
|
|
|
?. =(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
|
|
|
|
%+ murn ~(val by walts)
|
|
|
|
|= w=walt
|
|
|
|
?. =(network network.w) ~
|
|
|
|
^- (unit (list card))
|
|
|
|
:- ~
|
2021-04-09 00:37:06 +03:00
|
|
|
%+ turn ~(tap by wach.w)
|
|
|
|
|= [a=address *]
|
|
|
|
(poke-provider [%address-info a])
|
2021-02-18 15:13:06 +03:00
|
|
|
:: +retry-txs: get info on txs without enough confirmations
|
|
|
|
::
|
|
|
|
++ retry-txs
|
|
|
|
|= =network
|
|
|
|
^- (list card)
|
|
|
|
%+ murn ~(tap by history)
|
|
|
|
|= [=txid =hest]
|
|
|
|
=/ 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])]
|
|
|
|
%+ turn txis.u.poym
|
|
|
|
|= =txi
|
2021-02-21 13:13:50 +03:00
|
|
|
(poke-provider [%raw-tx ~(get-txid txb:bl u.poym)])
|
2021-02-18 15:13:06 +03:00
|
|
|
:: +retry-pend-piym: check whether txids in pend-piym are in mempool
|
|
|
|
::
|
|
|
|
++ retry-pend-piym
|
|
|
|
|= =network
|
|
|
|
^- (list card)
|
|
|
|
%+ murn ~(tap by pend.piym)
|
|
|
|
|= [=txid p=payment]
|
|
|
|
=/ w (~(get by walts) xpub.p)
|
|
|
|
?~ w ~
|
|
|
|
?. =(network network.u.w) ~
|
|
|
|
`(poke-provider [%tx-info txid])
|
2021-02-18 15:59:32 +03:00
|
|
|
--
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
++ handle-provider-update
|
|
|
|
|= upd=update:bp
|
|
|
|
^- (quip card _state)
|
2021-02-15 11:23:56 +03:00
|
|
|
?~ prov `state
|
|
|
|
?. =(host.u.prov src.bowl) `state
|
2021-02-12 17:37:21 +03:00
|
|
|
?. ?=(%.y -.upd) `state
|
|
|
|
?- -.p.upd
|
|
|
|
%address-info
|
2021-02-18 15:59:32 +03:00
|
|
|
:: located in the helper in Scan Logic to keep all of that unified
|
|
|
|
::
|
2021-02-12 17:37:21 +03:00
|
|
|
(handle-address-info address.p.upd utxos.p.upd used.p.upd)
|
|
|
|
::
|
|
|
|
%tx-info
|
2021-02-18 15:13:06 +03:00
|
|
|
:- ~[(poke-internal [%close-pym info.p.upd])]
|
2021-02-12 17:37:21 +03:00
|
|
|
(handle-tx-info info.p.upd)
|
|
|
|
::
|
|
|
|
%raw-tx
|
|
|
|
:_ state
|
2021-02-18 15:13:06 +03:00
|
|
|
~[(poke-internal [%add-poym-raw-txi +.p.upd])]
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
%broadcast-tx
|
|
|
|
?~ poym `state
|
2021-02-21 13:13:50 +03:00
|
|
|
?. =(~(get-txid txb:bl u.poym) txid.p.upd)
|
2021-02-12 17:37:21 +03:00
|
|
|
`state
|
|
|
|
:_ state
|
|
|
|
?: ?|(broadcast.p.upd included.p.upd)
|
2021-02-18 15:13:06 +03:00
|
|
|
~[(poke-internal [%succeed-broadcast-tx txid.p.upd])]
|
|
|
|
~[(poke-internal [%fail-broadcast-tx txid.p.upd])]
|
2021-02-12 17:37:21 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
++ handle-tx-info
|
|
|
|
|= ti=info:tx
|
|
|
|
^- _state
|
|
|
|
|^
|
|
|
|
=/ h (~(get by history) txid.ti)
|
2021-04-09 02:11:31 +03:00
|
|
|
=. ahistorical-txs (~(del in ahistorical-txs) txid.ti)
|
2021-02-14 13:17:58 +03:00
|
|
|
=/ our-addrs=(set address) :: all our addresses in inputs/outputs of tx
|
2021-02-18 15:13:06 +03:00
|
|
|
%- silt
|
2021-02-14 13:17:58 +03:00
|
|
|
%+ skim
|
|
|
|
%+ turn (weld inputs.ti outputs.ti)
|
|
|
|
|=(=val:tx address.val)
|
|
|
|
is-our-address
|
|
|
|
?: =(0 ~(wyt in our-addrs)) state
|
|
|
|
=/ =xpub
|
2021-02-21 13:13:50 +03:00
|
|
|
xpub.w:(need (address-coords:bl (snag 0 ~(tap in our-addrs)) ~(val by walts)))
|
2021-02-14 13:17:58 +03:00
|
|
|
?~ h :: addresses in wallets, but tx not in history
|
2021-02-12 17:37:21 +03:00
|
|
|
=. history
|
|
|
|
%+ ~(put by history) txid.ti
|
2021-02-14 13:17:58 +03:00
|
|
|
(mk-hest xpub our-addrs)
|
2021-02-12 17:37:21 +03:00
|
|
|
state
|
2021-02-14 13:17:58 +03:00
|
|
|
?. included.ti :: tx in history, but not in mempool/blocks
|
2021-02-12 17:37:21 +03:00
|
|
|
state(history (~(del by history) txid.ti))
|
|
|
|
%_ state
|
|
|
|
history
|
|
|
|
%+ ~(put by history) txid.ti
|
|
|
|
u.h(confs confs.ti, recvd recvd.ti)
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ mk-hest
|
|
|
|
:: has tx-info
|
2021-02-21 13:13:50 +03:00
|
|
|
|= [=xpub:bc our-addrs=(set address)]
|
2021-02-12 17:37:21 +03:00
|
|
|
^- hest
|
|
|
|
:* xpub
|
|
|
|
txid.ti
|
|
|
|
confs.ti
|
|
|
|
recvd.ti
|
2021-02-14 13:17:58 +03:00
|
|
|
(turn inputs.ti |=(v=val:tx (is-our-ship our-addrs v)))
|
|
|
|
(turn outputs.ti |=(v=val:tx (is-our-ship our-addrs v)))
|
2021-02-12 17:37:21 +03:00
|
|
|
==
|
|
|
|
::
|
2021-02-14 13:17:58 +03:00
|
|
|
++ is-our-ship
|
2021-02-18 15:13:06 +03:00
|
|
|
|= [as=(set address) v=val:tx]
|
2021-02-12 17:37:21 +03:00
|
|
|
^- [=val:tx s=(unit ship)]
|
|
|
|
[v ?:((~(has in as) address.v) `our.bowl ~)]
|
|
|
|
::
|
2021-02-14 13:17:58 +03:00
|
|
|
++ is-our-address
|
2021-02-21 13:13:50 +03:00
|
|
|
|=(a=address ?=(^ (address-coords:bl a ~(val by walts))))
|
2021-02-12 17:37:21 +03:00
|
|
|
--
|
2021-02-14 13:17:58 +03:00
|
|
|
++ set-curr-xpub
|
|
|
|
|= =xpub
|
|
|
|
^- (quip card _state)
|
|
|
|
?~ (find ~[xpub] scanned-wallets) `state
|
|
|
|
`state(curr-xpub `xpub)
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
2021-02-13 15:14:50 +03:00
|
|
|
::
|
2021-02-12 17:37:21 +03:00
|
|
|
:: Scan Logic
|
|
|
|
::
|
2021-02-13 15:14:50 +03:00
|
|
|
:: Algorithm
|
|
|
|
:: Initiate a batch for each chyg, with max-gap idxs in it
|
|
|
|
:: Watch all of the addresses made from idxs
|
|
|
|
:: Request info on all addresses from provider
|
|
|
|
:: When an %address-info comes back:
|
|
|
|
:: - remove that idx from todo.batch
|
|
|
|
:: - run check-scan to check whether that chyg is done
|
|
|
|
:: - if it isn't, refill it with max-gap idxs to scan
|
|
|
|
::
|
2021-02-12 17:37:21 +03:00
|
|
|
:: +handle-address-info: updates scans and wallet with address info
|
|
|
|
::
|
|
|
|
++ handle-address-info
|
|
|
|
|= [=address utxos=(set utxo) used=?]
|
|
|
|
^- (quip card _state)
|
2021-02-21 13:13:50 +03:00
|
|
|
=/ ac (address-coords:bl address ~(val by walts))
|
2021-04-09 02:11:31 +03:00
|
|
|
?~ ac
|
|
|
|
`state
|
2021-02-13 15:14:50 +03:00
|
|
|
=/ [w=walt =chyg =idx] u.ac
|
2021-02-12 17:37:21 +03:00
|
|
|
=. walts
|
|
|
|
%+ ~(put by walts) xpub.w
|
2021-02-21 13:13:50 +03:00
|
|
|
%+ ~(update-address wad:bl w chyg)
|
2021-02-12 17:37:21 +03:00
|
|
|
address
|
|
|
|
[used chyg idx utxos]
|
2021-04-09 02:11:31 +03:00
|
|
|
:: if transactions haven't made it into history, request transaction info
|
|
|
|
::
|
|
|
|
=^ cards=(list card) ahistorical-txs
|
|
|
|
%+ roll ~(tap in utxos)
|
|
|
|
|= [u=utxo cad=(list card) ah=(set txid)]
|
|
|
|
^- [(list card) (set txid)]
|
|
|
|
?: (~(has by history) txid.u)
|
|
|
|
[cad ah]
|
|
|
|
:- [(poke-provider [%tx-info txid.u]) cad]
|
|
|
|
(~(put by ah) txid.u)
|
2021-02-12 17:37:21 +03:00
|
|
|
:: if the wallet+chyg is being scanned, update the scan batch
|
|
|
|
::
|
2021-02-12 20:43:25 +03:00
|
|
|
=/ b (~(get by scans) [xpub.w chyg])
|
2021-04-09 02:11:31 +03:00
|
|
|
?~ b
|
|
|
|
[cards state]
|
2021-02-12 17:37:21 +03:00
|
|
|
=. scans
|
|
|
|
(del-scanned u.b(has-used ?|(used has-used.u.b)) xpub.w chyg idx)
|
|
|
|
?: empty:(scan-status xpub.w chyg)
|
2021-04-09 02:11:31 +03:00
|
|
|
=^ scan-cards=(list card) state
|
|
|
|
(check-scan xpub.w)
|
|
|
|
[(weld scan-cards cards) state]
|
|
|
|
::
|
|
|
|
[cards state]
|
2021-02-13 15:14:50 +03:00
|
|
|
:: +req-scan
|
|
|
|
:: - adds addresses in batch to wallet's watch map as un-used addresses
|
|
|
|
:: - returns provider %address-info request cards
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
++ req-scan
|
2021-02-21 13:13:50 +03:00
|
|
|
|= [b=batch =xpub:bc =chyg]
|
2021-02-13 15:14:50 +03:00
|
|
|
^- (quip card _state)
|
2021-02-12 17:37:21 +03:00
|
|
|
=/ w=walt (~(got by walts) xpub)
|
2021-02-13 15:14:50 +03:00
|
|
|
=/ as=(list [address [? ^chyg idx (set utxo)]])
|
|
|
|
%+ turn ~(tap in todo.b)
|
2021-02-21 13:13:50 +03:00
|
|
|
|=(=idx [(~(mk-address wad:bl w chyg) idx) [%.n chyg idx *(set utxo)]])
|
2021-02-13 15:14:50 +03:00
|
|
|
=. w
|
|
|
|
|- ?~ as w
|
2021-02-21 13:13:50 +03:00
|
|
|
$(as t.as, w (~(update-address wad:bl w chyg) -.i.as +.i.as))
|
2021-02-13 15:14:50 +03:00
|
|
|
:- (turn as |=([a=address *] (poke-provider [%address-info a])))
|
|
|
|
%= state
|
|
|
|
scans
|
|
|
|
(~(put by scans) [xpub chyg] b)
|
|
|
|
walts
|
2021-04-09 02:11:31 +03:00
|
|
|
(~(put by walts) xpub w)
|
2021-02-13 15:14:50 +03:00
|
|
|
==
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
++ scan-status
|
2021-02-21 13:13:50 +03:00
|
|
|
|= [=xpub:bc =chyg]
|
2021-02-12 17:37:21 +03:00
|
|
|
^- [empty=? done=?]
|
|
|
|
=/ b=batch (~(got by scans) [xpub chyg])
|
|
|
|
=/ empty=? =(0 ~(wyt in todo.b))
|
|
|
|
:- empty
|
|
|
|
?&(empty ?!(has-used.b))
|
|
|
|
::
|
|
|
|
++ init-batches
|
2021-02-21 13:13:50 +03:00
|
|
|
|= [=xpub:bc endpoint=idx]
|
2021-02-12 17:37:21 +03:00
|
|
|
^- (quip card _state)
|
|
|
|
=/ b=batch
|
2021-02-18 15:13:06 +03:00
|
|
|
[(silt (gulf 0 endpoint)) endpoint %.n]
|
2021-02-13 15:14:50 +03:00
|
|
|
=^ cards0 state (req-scan b xpub %0)
|
|
|
|
=^ cards1 state (req-scan b xpub %1)
|
|
|
|
[(weld cards0 cards1) state]
|
2021-02-12 17:37:21 +03:00
|
|
|
:: +bump-batch
|
|
|
|
:: if the batch is done but the wallet isn't done scanning,
|
|
|
|
:: returns new address requests and updated batch
|
|
|
|
::
|
|
|
|
++ bump-batch
|
2021-02-21 13:13:50 +03:00
|
|
|
|= [=xpub:bc =chyg]
|
2021-02-13 15:14:50 +03:00
|
|
|
^- (quip card _state)
|
2021-02-12 17:37:21 +03:00
|
|
|
=/ b=batch (~(got by scans) xpub chyg)
|
|
|
|
=/ s (scan-status xpub chyg)
|
|
|
|
?. ?&(empty.s ?!(done.s))
|
2021-02-13 15:14:50 +03:00
|
|
|
`state
|
2021-02-12 17:37:21 +03:00
|
|
|
=/ w=walt (~(got by walts) xpub)
|
|
|
|
=/ newb=batch
|
2021-02-18 15:13:06 +03:00
|
|
|
:* (silt (gulf +(endpoint.b) (add endpoint.b max-gap.w)))
|
2021-02-12 17:37:21 +03:00
|
|
|
(add endpoint.b max-gap.w)
|
|
|
|
%.n
|
|
|
|
==
|
2021-02-13 15:14:50 +03:00
|
|
|
(req-scan newb xpub chyg)
|
2021-02-12 17:37:21 +03:00
|
|
|
:: +del-scanned: delete scanned idxs
|
|
|
|
::
|
|
|
|
++ del-scanned
|
2021-02-21 13:13:50 +03:00
|
|
|
|= [b=batch =xpub:bc =chyg to-delete=idx]
|
2021-02-12 17:37:21 +03:00
|
|
|
^- ^scans
|
|
|
|
%+ ~(put by scans) [xpub chyg]
|
|
|
|
b(todo (~(del in todo.b) to-delete))
|
|
|
|
:: delete the xpub from scans and set wallet to scanned
|
|
|
|
::
|
|
|
|
++ end-scan
|
2021-02-21 13:13:50 +03:00
|
|
|
|= [=xpub:bc]
|
2021-02-12 17:37:21 +03:00
|
|
|
^- (quip card _state)
|
|
|
|
=/ w=walt (~(got by walts) xpub)
|
|
|
|
=. scans (~(del by scans) [xpub %0])
|
|
|
|
=. scans (~(del by scans) [xpub %1])
|
2021-02-13 15:14:50 +03:00
|
|
|
%- (slog ~[leaf+"Scanned xpub {<xpub>}"])
|
2021-02-14 13:17:58 +03:00
|
|
|
=. state state(walts (~(put by walts) xpub w(scanned %.y)))
|
|
|
|
(set-curr-xpub xpub)
|
2021-02-12 17:37:21 +03:00
|
|
|
:: +check-scan: initiate a scan if one hasn't started
|
|
|
|
:: check status of scan if one is running
|
|
|
|
::
|
|
|
|
++ check-scan
|
2021-02-21 13:13:50 +03:00
|
|
|
|= =xpub:bc
|
2021-02-12 17:37:21 +03:00
|
|
|
^- (quip card _state)
|
|
|
|
=/ s0 (scan-status xpub %0)
|
|
|
|
=/ s1 (scan-status xpub %1)
|
|
|
|
?: ?&(empty.s0 done.s0 empty.s1 done.s1)
|
|
|
|
(end-scan xpub)
|
2021-02-13 15:14:50 +03:00
|
|
|
=^ cards0=(list card) state
|
2021-02-12 17:37:21 +03:00
|
|
|
(bump-batch xpub %0)
|
2021-02-13 15:14:50 +03:00
|
|
|
=^ cards1=(list card) state
|
2021-02-12 17:37:21 +03:00
|
|
|
(bump-batch xpub %1)
|
2021-02-13 15:14:50 +03:00
|
|
|
[(weld cards0 cards1) state]
|
|
|
|
::
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
2021-02-13 15:14:50 +03:00
|
|
|
::
|
2021-02-12 17:37:21 +03:00
|
|
|
++ poke-provider
|
|
|
|
|= [act=action:bp]
|
|
|
|
^- card
|
|
|
|
?~ prov ~|("provider not set" !!)
|
|
|
|
:* %pass /[(scot %da now.bowl)]
|
|
|
|
%agent [host.u.prov %btc-provider]
|
|
|
|
%poke %btc-provider-action !>([act])
|
|
|
|
==
|
|
|
|
::
|
2021-02-18 15:13:06 +03:00
|
|
|
++ poke-peer
|
2021-02-12 17:37:21 +03:00
|
|
|
|= [target=ship act=action]
|
|
|
|
^- card
|
|
|
|
:* %pass /[(scot %da now.bowl)] %agent
|
|
|
|
[target %btc-wallet] %poke
|
|
|
|
%btc-wallet-action !>(act)
|
|
|
|
==
|
2021-02-18 15:13:06 +03:00
|
|
|
++ poke-internal
|
|
|
|
|= [intr=internal]
|
|
|
|
^- card
|
|
|
|
:* %pass /[(scot %da now.bowl)] %agent
|
|
|
|
[our.bowl %btc-wallet] %poke
|
|
|
|
%btc-wallet-internal !>(intr)
|
2021-02-18 15:59:32 +03:00
|
|
|
==
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
++ is-broadcasting
|
|
|
|
^- ?
|
|
|
|
?~ poym %.n
|
2021-02-13 15:14:50 +03:00
|
|
|
?=(^ signed-tx.u.poym)
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
:: Scry Helpers
|
|
|
|
::
|
|
|
|
++ scanned-wallets
|
2021-02-21 13:13:50 +03:00
|
|
|
^- (list xpub:bc)
|
2021-02-12 17:37:21 +03:00
|
|
|
%+ murn ~(tap by walts)
|
2021-02-21 13:13:50 +03:00
|
|
|
|= [=xpub:bc w=walt]
|
|
|
|
^- (unit xpub:bc)
|
|
|
|
?:(scanned.w `xpub ~)
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
++ balance
|
2021-02-21 13:13:50 +03:00
|
|
|
|= =xpub:bc
|
2021-02-12 17:37:21 +03:00
|
|
|
^- (unit sats)
|
|
|
|
=/ w (~(get by walts) xpub)
|
|
|
|
?~ w ~
|
|
|
|
=/ values=(list sats)
|
|
|
|
%+ turn ~(val by wach.u.w)
|
|
|
|
|= =addi ^- sats
|
|
|
|
%+ roll
|
|
|
|
%+ turn ~(tap by utxos.addi)
|
|
|
|
|=(=utxo value.utxo)
|
|
|
|
add
|
|
|
|
`(roll values add)
|
|
|
|
::
|
2021-04-02 01:33:27 +03:00
|
|
|
::
|
|
|
|
++ current-balance
|
|
|
|
^- (unit sats)
|
|
|
|
?~ curr-xpub ~
|
|
|
|
(balance u.curr-xpub)
|
|
|
|
::
|
2021-02-12 17:37:21 +03:00
|
|
|
--
|