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-08-26 06:00:58 +03:00
|
|
|
/- *btc-wallet, bp=btc-provider, settings
|
2021-10-21 21:03:05 +03:00
|
|
|
/+ dbug, default-agent, bl=btc, bc=bitcoin, bcu=bitcoin-utils, bip32, agentio
|
2021-06-24 20:39:33 +03:00
|
|
|
~% %btc-wallet-top ..part ~
|
2021-02-12 17:37:21 +03:00
|
|
|
|%
|
2021-06-24 20:39:33 +03:00
|
|
|
+$ card card:agent:gall
|
|
|
|
::
|
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
|
2021-06-01 22:30:13 +03:00
|
|
|
state-1
|
2021-07-02 20:59:58 +03:00
|
|
|
state-2
|
2021-10-21 21:03:05 +03:00
|
|
|
state-3
|
2021-02-12 17:37:21 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
+$ state-0
|
|
|
|
$: %0
|
2021-06-01 22:30:13 +03:00
|
|
|
prov=(unit provider)
|
|
|
|
walts=(map xpub:bc walt-0)
|
|
|
|
=btc-state
|
|
|
|
=history
|
|
|
|
curr-xpub=(unit xpub:bc)
|
|
|
|
=scans
|
|
|
|
=params
|
|
|
|
feybs=(map ship sats)
|
|
|
|
=piym
|
|
|
|
=poym
|
|
|
|
ahistorical-txs=(set txid)
|
|
|
|
==
|
|
|
|
::
|
2021-07-02 20:59:58 +03:00
|
|
|
+$ base-state
|
|
|
|
$: 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
|
|
|
==
|
2021-07-02 20:59:58 +03:00
|
|
|
::
|
|
|
|
+$ state-1 [%1 base-state]
|
|
|
|
+$ state-2 [%2 base-state]
|
2021-10-21 21:03:05 +03:00
|
|
|
+$ state-3 [%3 base-state]
|
2021-02-12 17:37:21 +03:00
|
|
|
--
|
2021-10-21 21:03:05 +03:00
|
|
|
=| state-3
|
2021-02-12 17:37:21 +03:00
|
|
|
=* state -
|
|
|
|
%- agent:dbug
|
|
|
|
^- agent:gall
|
|
|
|
=<
|
2021-06-24 20:39:33 +03:00
|
|
|
~% %btc-wallet-agent ..retry-filtered-addrs ~
|
2021-02-12 17:37:21 +03:00
|
|
|
|_ =bowl:gall
|
|
|
|
+* this .
|
|
|
|
def ~(. (default-agent this %|) bowl)
|
|
|
|
hc ~(. +> bowl)
|
2021-10-21 21:03:05 +03:00
|
|
|
io ~(. agentio bowl)
|
|
|
|
pass pass:io
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
++ on-init
|
|
|
|
^- (quip card _this)
|
|
|
|
~& > '%btc-wallet initialized'
|
2021-06-30 04:03:34 +03:00
|
|
|
::
|
2021-09-13 04:18:22 +03:00
|
|
|
=/ warning=event:settings [%put-entry q.byk.bowl %btc-wallet %warning %b %.y]
|
|
|
|
=/ currency=event:settings [%put-entry q.byk.bowl %btc-wallet %currency %s 'USD']
|
2021-06-30 04:03:34 +03:00
|
|
|
=/ cards=(list card)
|
2021-06-30 22:48:14 +03:00
|
|
|
:~ (poke-our:hc %settings-store %settings-event !>(warning))
|
|
|
|
(poke-our:hc %settings-store %settings-event !>(currency))
|
2021-06-30 04:03:34 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
:- cards
|
2021-02-12 17:37:21 +03:00
|
|
|
%_ this
|
|
|
|
state
|
2021-10-21 21:03:05 +03:00
|
|
|
:* %3
|
2021-02-12 17:37:21 +03:00
|
|
|
~
|
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
|
|
|
==
|
|
|
|
==
|
2021-04-26 23:12:11 +03:00
|
|
|
::
|
2021-02-12 17:37:21 +03:00
|
|
|
++ on-save
|
|
|
|
^- vase
|
|
|
|
!>(state)
|
2021-04-26 23:12:11 +03:00
|
|
|
::
|
2021-02-12 17:37:21 +03:00
|
|
|
++ on-load
|
|
|
|
|= old-state=vase
|
|
|
|
^- (quip card _this)
|
|
|
|
~& > '%btc-wallet recompiled'
|
2021-04-26 23:12:11 +03:00
|
|
|
=/ ver !<(versioned-state old-state)
|
|
|
|
=| cards=(list card)
|
|
|
|
|-
|
|
|
|
?- -.ver
|
2021-10-21 21:03:05 +03:00
|
|
|
%3
|
|
|
|
[(flop cards) this(state ver)]
|
|
|
|
::
|
2021-10-07 16:08:01 +03:00
|
|
|
%2
|
2021-10-21 21:03:05 +03:00
|
|
|
%_ $
|
|
|
|
-.ver %3
|
|
|
|
cards :_(cards (~(wait pass /migrate-settings) (add now.bowl ~s1)))
|
|
|
|
==
|
2021-07-02 20:59:58 +03:00
|
|
|
::
|
|
|
|
%1
|
|
|
|
=? cards ?=(^ prov.ver)
|
|
|
|
:_ cards
|
2021-07-03 00:24:35 +03:00
|
|
|
=/ =dock [host.u.prov.ver %btc-provider]
|
|
|
|
=/ wir=wire /set-provider/(scot %p host.u.prov.ver)
|
2021-07-02 20:59:58 +03:00
|
|
|
=/ priv-wire=^wire (welp wir [%priv ~])
|
|
|
|
[%pass priv-wire %agent dock %watch /clients/(scot %p our.bowl)]
|
|
|
|
$(-.ver %2)
|
2021-06-01 22:30:13 +03:00
|
|
|
::
|
|
|
|
%0
|
|
|
|
=/ new-walts=(map xpub:bc walt)
|
|
|
|
%- ~(run by walts.ver)
|
|
|
|
|= old-walt=walt-0
|
|
|
|
^- walt
|
|
|
|
old-walt(wilt +6:wilt.old-walt)
|
|
|
|
$(ver [%1 +.ver(walts new-walts)])
|
2021-04-26 23:12:11 +03:00
|
|
|
==
|
|
|
|
::
|
2021-02-12 17:37:21 +03:00
|
|
|
++ on-poke
|
2021-06-24 20:39:33 +03:00
|
|
|
~/ %on-poke
|
2021-02-12 17:37:21 +03:00
|
|
|
|= [=mark =vase]
|
|
|
|
^- (quip card _this)
|
2021-06-24 20:39:33 +03:00
|
|
|
|^
|
2021-02-12 17:37:21 +03:00
|
|
|
=^ cards state
|
2021-06-24 20:39:33 +03:00
|
|
|
?+ mark (on-poke:def mark vase)
|
2021-10-21 21:03:05 +03:00
|
|
|
::
|
|
|
|
%noun
|
|
|
|
?> =(our.bowl src.bowl)
|
|
|
|
(handle-noun q.vase)
|
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
%btc-wallet-command
|
|
|
|
?> =(our.bowl src.bowl)
|
|
|
|
(handle-command !<(command vase))
|
|
|
|
::
|
|
|
|
%btc-wallet-action
|
|
|
|
?< =(our.bowl src.bowl)
|
|
|
|
(handle-action !<(action vase))
|
|
|
|
::
|
|
|
|
%btc-wallet-internal
|
|
|
|
?> =(our.bowl src.bowl)
|
|
|
|
(handle-internal !<(internal vase))
|
|
|
|
==
|
|
|
|
[cards this]
|
|
|
|
::
|
2021-10-21 21:03:05 +03:00
|
|
|
++ handle-noun
|
|
|
|
|= non=*
|
|
|
|
?> ?=(%migrate-settings non)
|
|
|
|
:_ state
|
|
|
|
^- (list card)
|
|
|
|
=/ bas=path /(scot %p our.bowl)/settings-store/(scot %da now.bowl)
|
|
|
|
?. .^(? %gu bas)
|
|
|
|
~& [dap.bowl %settings-store-mia]
|
|
|
|
~
|
|
|
|
?. .^(? %gx (weld bas /has-bucket/landscape/btc-wallet/noun))
|
|
|
|
~
|
|
|
|
=/ dat
|
|
|
|
.^(data:settings %gx (weld bas /bucket/landscape/btc-wallet/noun))
|
|
|
|
?> ?=(%bucket -.dat)
|
|
|
|
|^ :- =/ del=event:settings [%del-bucket %landscape %btc-wallet]
|
|
|
|
(poke-our:hc %settings-store %settings-event !>(del))
|
2021-10-21 22:09:51 +03:00
|
|
|
(murn ~(tap by bucket.dat) copy-if-missing)
|
2021-10-21 21:03:05 +03:00
|
|
|
::
|
|
|
|
++ copy-if-missing
|
|
|
|
|= [=key:settings =val:settings]
|
|
|
|
^- (unit card)
|
|
|
|
=/ hav=?
|
|
|
|
.^(? %gx (weld bas /has-entry/[q.byk.bowl]/btc-wallet/[key]/noun))
|
|
|
|
?: hav ~
|
|
|
|
~& [dap.bowl %importing-previous-setting key]
|
|
|
|
=/ put=event:settings [%put-entry q.byk.bowl %btc-wallet key val]
|
|
|
|
`(poke-our:hc %settings-store %settings-event !>(put))
|
|
|
|
--
|
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ handle-command
|
|
|
|
|= comm=command
|
|
|
|
^- (quip card _state)
|
|
|
|
?> (team:title our.bowl src.bowl)
|
|
|
|
?- -.comm
|
|
|
|
%set-provider
|
2021-06-25 02:12:46 +03:00
|
|
|
|^
|
2021-06-24 20:39:33 +03:00
|
|
|
?~ provider.comm
|
|
|
|
?~ prov `state
|
|
|
|
:_ state(prov ~)
|
2021-07-03 00:24:35 +03:00
|
|
|
%- zing
|
2021-06-24 20:39:33 +03:00
|
|
|
:~ (leave-provider host.u.prov)
|
2021-07-03 00:24:35 +03:00
|
|
|
(give-update:hc %change-provider ~)^~
|
2021-06-24 20:39:33 +03:00
|
|
|
==
|
|
|
|
:_ state(prov `[u.provider.comm %.n])
|
|
|
|
?~ prov
|
2021-07-02 20:59:58 +03:00
|
|
|
(watch-provider:hc u.provider.comm)
|
|
|
|
%- zing
|
2021-06-24 20:39:33 +03:00
|
|
|
:~ (leave-provider host.u.prov)
|
|
|
|
(watch-provider:hc u.provider.comm)
|
2021-07-02 20:59:58 +03:00
|
|
|
(give-update:hc %change-provider `[u.provider.comm %.n])^~
|
2021-06-24 20:39:33 +03:00
|
|
|
==
|
2021-06-25 02:12:46 +03:00
|
|
|
::
|
|
|
|
++ leave-provider
|
|
|
|
|= who=@p
|
2021-07-03 00:24:35 +03:00
|
|
|
^- (list card)
|
|
|
|
=/ wir=wire /set-provider/(scot %p who)
|
|
|
|
=/ priv-wir=wire (welp wir %priv^~)
|
|
|
|
:+ [%pass wir %agent who^%btc-provider %leave ~]
|
|
|
|
[%pass priv-wir %agent who^%btc-provider %leave ~]
|
|
|
|
~
|
2021-06-25 02:12:46 +03:00
|
|
|
--
|
2021-02-18 15:13:06 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
%check-provider
|
|
|
|
=/ pax /permitted/(scot %p provider.comm)
|
|
|
|
:_ state
|
|
|
|
[%pass pax %agent [provider.comm %btc-provider] %watch pax]~
|
2021-02-18 15:13:06 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
%check-payee
|
|
|
|
=/ pax /check-payee/(scot %p payee.comm)
|
|
|
|
:_ state
|
|
|
|
[%pass pax %agent [payee.comm %btc-wallet] %watch pax]~
|
|
|
|
::
|
|
|
|
%set-current-wallet
|
|
|
|
(set-curr-xpub:hc xpub.comm)
|
|
|
|
::
|
|
|
|
%add-wallet
|
2021-06-25 02:12:46 +03:00
|
|
|
|^
|
2021-06-24 20:39:33 +03:00
|
|
|
?~ (~(has by walts) xpub.comm)
|
|
|
|
((slog ~[leaf+"xpub already in wallet"]) `state)
|
|
|
|
=/ w=walt (from-xpub:bl +.comm)
|
|
|
|
=. walts (~(put by walts) xpub.comm w)
|
|
|
|
=^ c1 state (init-batches xpub.comm (dec max-gap.w))
|
|
|
|
=^ c2 state (set-curr-xpub:hc xpub.comm)
|
|
|
|
[(weld c1 c2) state]
|
2021-06-25 02:12:46 +03:00
|
|
|
::
|
|
|
|
++ init-batches
|
|
|
|
|= [=xpub:bc endpoint=idx]
|
|
|
|
^- (quip card _state)
|
|
|
|
=/ b=batch
|
|
|
|
[(silt (gulf 0 endpoint)) endpoint %.n]
|
|
|
|
=^ cards0 state (req-scan:hc b xpub %0)
|
|
|
|
=^ cards1 state (req-scan:hc b xpub %1)
|
2021-07-02 09:14:09 +03:00
|
|
|
:_ state
|
|
|
|
[(scan-progress:hc xpub) (weld cards0 cards1)]
|
2021-06-25 02:12:46 +03:00
|
|
|
--
|
2021-06-24 20:39:33 +03:00
|
|
|
::
|
|
|
|
%delete-wallet
|
|
|
|
=* cw curr-xpub.state
|
|
|
|
=? cw ?&(?=(^ cw) =(u.cw xpub.comm))
|
|
|
|
~
|
|
|
|
=. scans (~(del by scans) [xpub.comm %0])
|
|
|
|
=: scans (~(del by scans) [xpub.comm %1])
|
|
|
|
walts (~(del by walts) xpub.comm)
|
|
|
|
history
|
|
|
|
%- ~(rep by history)
|
|
|
|
|= [[=txid =hest] out=_history]
|
|
|
|
?: =(xpub.hest xpub.comm)
|
|
|
|
(~(del by out) txid)
|
|
|
|
out
|
|
|
|
==
|
|
|
|
[[give-initial:hc]~ state]
|
|
|
|
::
|
|
|
|
%init-payment-external
|
|
|
|
?: is-broadcasting:hc
|
|
|
|
%- (slog ~[leaf+"broadcasting a transaction"])
|
|
|
|
[[(give-update:hc %error %tx-being-signed)]~ state]
|
2021-06-25 19:05:58 +03:00
|
|
|
?~ curr-xpub
|
|
|
|
~|("btc-wallet: no curr-xpub set" !!)
|
2021-06-24 20:39:33 +03:00
|
|
|
?: (is-dust:hc value.comm address.comm)
|
|
|
|
%- (slog ~[leaf+"sending dust"])
|
|
|
|
[[(give-update:hc %error %no-dust)]~ state]
|
|
|
|
::
|
|
|
|
~| "no wallet with xpub"
|
|
|
|
=/ wal (~(got by walts) u.curr-xpub)
|
|
|
|
~| "wallet not scanned yet"
|
2021-06-25 04:56:24 +03:00
|
|
|
?> scanned.wal
|
2021-06-24 20:39:33 +03:00
|
|
|
=/ [tb=(unit txbu) chng=(unit sats)]
|
|
|
|
%~ with-change sut:bl
|
|
|
|
:* wal eny.bowl
|
|
|
|
block.btc-state ~
|
|
|
|
feyb.comm ~[[address.comm value.comm ~]]
|
|
|
|
==
|
|
|
|
?~ tb
|
|
|
|
%- %- slog
|
|
|
|
~[leaf+"insufficient balance or not enough confirmed balance"]
|
|
|
|
[[(give-update:hc %error %insufficient-balance)]~ state]
|
|
|
|
=^ tb=(unit txbu) state
|
|
|
|
?~ chng `state
|
|
|
|
=/ [addr=address =idx w=walt]
|
|
|
|
~(nixt-address wad:bl wal %1)
|
|
|
|
:_ state(walts (~(put by walts) u.curr-xpub w))
|
|
|
|
`(~(add-output txb:bl u.tb) addr u.chng `(~(hdkey wad:bl w %1) idx))
|
|
|
|
=/ po=^poym
|
|
|
|
?~(tb [~ ~] [tb note.comm])
|
|
|
|
:_ state(poym po)
|
|
|
|
?~ tb ~
|
|
|
|
%+ turn txis.u.tb
|
|
|
|
|=(=txi (poke-provider:hc %raw-tx txid.utxo.txi))
|
|
|
|
::
|
|
|
|
:: overwrites any payment being built in poym
|
|
|
|
::
|
|
|
|
%init-payment
|
|
|
|
?: =(src.bowl payee.comm)
|
|
|
|
%- (slog ~[leaf+"can't pay ourselves"])
|
|
|
|
[[(give-update:hc %error %cant-pay-ourselves)]~ state]
|
|
|
|
?: ?=(%pawn (clan:title payee.comm))
|
|
|
|
%- (slog ~[leaf+"no comets"])
|
|
|
|
[[(give-update:hc %error %no-comets)]~ state]
|
|
|
|
?: is-broadcasting:hc
|
|
|
|
%- (slog ~[leaf+"broadcasting a transaction"])
|
|
|
|
[[(give-update:hc %error %tx-being-signed)]~ state]
|
|
|
|
=: poym `note.comm
|
|
|
|
feybs (~(put by feybs) payee.comm feyb.comm)
|
|
|
|
==
|
|
|
|
:_ state
|
|
|
|
~[(poke-peer:hc payee.comm [%gen-pay-address value.comm note.comm])]
|
|
|
|
::
|
|
|
|
%broadcast-tx
|
|
|
|
?~ prov ~|("Provider not connected" !!)
|
|
|
|
=+ signed=(from-cord:hxb:bcu txhex.comm)
|
|
|
|
=/ tx-match=?
|
|
|
|
?~ txbu.poym %.n
|
|
|
|
=((get-id:txu:bc (decode:txu:bc signed)) ~(get-txid txb:bl u.txbu.poym))
|
|
|
|
:- ?. tx-match
|
|
|
|
%- (slog leaf+"txid didn't match txid in wallet")
|
|
|
|
[(give-update:hc %error %broadcast-fail)]~
|
|
|
|
~[(poke-provider:hc [%broadcast-tx signed])]
|
|
|
|
?. tx-match state
|
|
|
|
?~ txbu.poym state
|
|
|
|
state(signed-tx.u.txbu.poym `signed)
|
|
|
|
::
|
|
|
|
%gen-new-address
|
2021-06-25 19:05:58 +03:00
|
|
|
?~ curr-xpub
|
|
|
|
~|("btc-wallet: no curr-xpub set" !!)
|
2021-06-24 20:39:33 +03:00
|
|
|
~| "no wallet with xpub"
|
|
|
|
=/ wal (~(got by walts) u.curr-xpub)
|
|
|
|
~| "wallet not scanned yet"
|
2021-06-25 04:56:24 +03:00
|
|
|
?> scanned.wal
|
2021-06-24 20:39:33 +03:00
|
|
|
=/ [addr=address =idx w=walt]
|
|
|
|
~(gen-address wad:bl wal %0)
|
|
|
|
:_ state(walts (~(put by walts) u.curr-xpub w))
|
|
|
|
[(give-update:hc %new-address addr)]~
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ handle-action
|
|
|
|
|= act=action
|
|
|
|
^- (quip card _state)
|
|
|
|
?- -.act
|
|
|
|
:: comets can't pay (could spam address requests)
|
|
|
|
:: reuses payment address for ship if ship in piym already
|
|
|
|
::
|
|
|
|
%gen-pay-address
|
|
|
|
~| "no comets"
|
|
|
|
?< ?=(%pawn (clan:title src.bowl))
|
2021-06-25 19:05:58 +03:00
|
|
|
?~ curr-xpub
|
|
|
|
~|("btc-wallet: no curr-xpub set" !!)
|
2021-06-24 20:39:33 +03:00
|
|
|
|^
|
|
|
|
=^ cards state reuse-address
|
|
|
|
?^ cards
|
|
|
|
:: if cards returned, means we already have an address
|
|
|
|
[cards state]
|
|
|
|
=+ f=(fam:bl our.bowl now.bowl src.bowl)
|
|
|
|
=+ n=(~(gut by num-fam.piym) f 0)
|
|
|
|
?: (gte n fam-limit.params)
|
|
|
|
~|("More than {<fam-limit.params>} addresses for moons + planet" !!)
|
2021-06-25 19:05:58 +03:00
|
|
|
=. num-fam.piym (~(put by num-fam.piym) f +(n))
|
2021-06-24 20:39:33 +03:00
|
|
|
=^ a=address state
|
|
|
|
(generate-address u.curr-xpub %0)
|
|
|
|
:- ~[(poke-peer:hc src.bowl [%give-pay-address a value.act])]
|
|
|
|
%_ state
|
|
|
|
ps.piym
|
|
|
|
%+ ~(put by ps.piym) src.bowl
|
|
|
|
`[u.curr-xpub a src.bowl value.act note.act]
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ generate-address
|
|
|
|
|= [=xpub:bc =chyg]
|
|
|
|
~| "no wallet with xpub"
|
|
|
|
=/ wal=walt (~(got by walts) xpub)
|
|
|
|
~| "wallet not scanned yet"
|
2021-06-25 04:56:24 +03:00
|
|
|
?> scanned.wal
|
2021-06-24 20:39:33 +03:00
|
|
|
=/ [addr=address =idx w=walt]
|
|
|
|
~(gen-address wad:bl wal chyg)
|
|
|
|
[addr state(walts (~(put by walts) xpub w))]
|
|
|
|
::
|
|
|
|
++ 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))
|
|
|
|
~[(poke-peer:hc payer [%give-pay-address address.newp value.act])]
|
|
|
|
--
|
|
|
|
::
|
|
|
|
%give-pay-address
|
|
|
|
~| "Can't pay ourselves"
|
2021-06-25 04:56:24 +03:00
|
|
|
?< =(src.bowl our.bowl)
|
2021-06-24 20:39:33 +03:00
|
|
|
~| "Broadcasting a transaction"
|
2021-06-25 04:56:24 +03:00
|
|
|
?< is-broadcasting:hc
|
2021-06-25 19:05:58 +03:00
|
|
|
?~ curr-xpub
|
|
|
|
~|("btc-wallet-hook: no curr-xpub set" !!)
|
2021-06-24 20:39:33 +03:00
|
|
|
?: (is-dust:hc value.act address.act)
|
|
|
|
%- (slog ~[leaf+"sending dust"])
|
|
|
|
[[(give-update:hc %error %no-dust)]~ state]
|
|
|
|
::
|
|
|
|
=/ feyb
|
|
|
|
%+ ~(gut by feybs)
|
|
|
|
src.bowl
|
|
|
|
?~(fee.btc-state fee:defaults u.fee.btc-state)
|
|
|
|
|^
|
|
|
|
=^ tb=(unit txbu) state
|
|
|
|
(generate-txbu u.curr-xpub `src.bowl feyb ~[[address.act value.act ~]])
|
|
|
|
=/ po=^poym
|
|
|
|
?~(tb [~ ~] [tb note.poym])
|
|
|
|
:_ state(poym po)
|
|
|
|
?~ tb [(give-update:hc %error %insufficient-balance)]~
|
|
|
|
%+ turn txis.u.tb
|
|
|
|
|=(=txi (poke-provider:hc [%raw-tx txid.utxo.txi]))
|
|
|
|
::
|
|
|
|
++ generate-txbu
|
|
|
|
|= [=xpub:bc payee=(unit ship) feyb=sats txos=(list txo)]
|
|
|
|
^- [(unit txbu) _state]
|
|
|
|
~| "no wallet with xpub"
|
|
|
|
=/ wal (~(got by walts) xpub)
|
|
|
|
~| "wallet not scanned yet"
|
2021-06-25 04:56:24 +03:00
|
|
|
?> scanned.wal
|
2021-06-24 20:39:33 +03:00
|
|
|
=/ [tb=(unit txbu) chng=(unit sats)]
|
|
|
|
%~ with-change sut:bl
|
|
|
|
[wal eny.bowl block.btc-state payee feyb txos]
|
|
|
|
?~ tb
|
|
|
|
%- %- slog
|
|
|
|
~[leaf+"insufficient balance or not enough confirmed balance"]
|
|
|
|
[tb state]
|
|
|
|
:: if no change, return txbu; else add change output to txbu
|
|
|
|
::
|
|
|
|
?~ chng [tb state]
|
|
|
|
=/ [addr=address =idx w=walt]
|
|
|
|
~(nixt-address wad:bl wal %1)
|
|
|
|
:_ state(walts (~(put by walts) xpub w))
|
|
|
|
`(~(add-output txb:bl u.tb) addr u.chng `(~(hdkey wad:bl w %1) idx))
|
|
|
|
--
|
|
|
|
::
|
|
|
|
:: %expect-payment
|
|
|
|
:: - check that payment is in piym
|
|
|
|
:: - replace pend.payment with incoming txid (lock)
|
|
|
|
:: - add txid to pend.piym
|
|
|
|
:: - request tx-info from provider
|
|
|
|
::
|
|
|
|
%expect-payment
|
|
|
|
|^
|
|
|
|
~| "%expect-payment: matching payment not in piym"
|
2021-06-25 19:05:58 +03:00
|
|
|
=/ pay (~(got by ps.piym) src.bowl)
|
|
|
|
?> (piym-matches pay)
|
|
|
|
:_ (update-pend-piym txid.act pay(pend `txid.act))
|
2021-06-24 20:39:33 +03:00
|
|
|
?~ prov ~
|
|
|
|
~[(poke-provider:hc [%tx-info txid.act])]
|
|
|
|
::
|
|
|
|
++ piym-matches
|
|
|
|
|= p=payment
|
|
|
|
?& =(payer.p src.bowl)
|
|
|
|
=(value.p value.act)
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ 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)
|
|
|
|
==
|
|
|
|
--
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ handle-internal
|
|
|
|
|= intr=internal
|
|
|
|
^- (quip card _state)
|
|
|
|
?- -.intr
|
|
|
|
%add-poym-raw-txi
|
|
|
|
|^
|
|
|
|
?> =(src.bowl our.bowl)
|
|
|
|
?~ txbu.poym `state
|
|
|
|
=. txis.u.txbu.poym
|
|
|
|
(update-poym-txis txis.u.txbu.poym +.intr)
|
|
|
|
:_ state
|
|
|
|
=+ pb=~(to-psbt txb:bl u.txbu.poym)
|
|
|
|
?~ pb ~
|
|
|
|
=+ vb=~(vbytes txb:bl u.txbu.poym)
|
|
|
|
=+ fee=~(fee txb:bl u.txbu.poym)
|
|
|
|
~& >> "{<vb>} vbytes, {<(div fee vb)>} sats/byte, {<fee>} sats fee"
|
|
|
|
%- (slog [%leaf "PSBT: {<u.pb>}"]~)
|
|
|
|
[(give-update:hc [%psbt u.pb fee])]~
|
|
|
|
:: 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-06-25 02:12:46 +03:00
|
|
|
::
|
|
|
|
:: delete an incoming/outgoing payment when we see it included in a tx
|
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
%close-pym
|
|
|
|
?> =(src.bowl our.bowl)
|
|
|
|
|^
|
|
|
|
=^ 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
|
|
|
|
=^ cards2 state
|
|
|
|
(handle-tx-info:hc ti.intr)
|
|
|
|
:_ state
|
|
|
|
(weld cards cards2)
|
|
|
|
::
|
|
|
|
++ poym-has-txid
|
|
|
|
|= txid=hexb
|
|
|
|
^- ?
|
|
|
|
?~ txbu.poym %.n
|
|
|
|
?~ signed-tx.u.txbu.poym %.n
|
|
|
|
=(txid (get-id:txu:bc (decode:txu:bc u.signed-tx.u.txbu.poym)))
|
|
|
|
:: - 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)
|
|
|
|
|^
|
|
|
|
?~ txbu.poym `state
|
|
|
|
?~ signed-tx.u.txbu.poym `state
|
|
|
|
?. (poym-has-txid txid.ti)
|
|
|
|
`state
|
|
|
|
=+ vout=(get-vout txos.u.txbu.poym)
|
|
|
|
?~ vout
|
|
|
|
~|("poym-to-history: poym should always have an output" !!)
|
|
|
|
=/ new-hest=hest
|
|
|
|
%: mk-hest
|
|
|
|
ti xpub.u.txbu.poym
|
|
|
|
our.bowl payee.u.txbu.poym
|
|
|
|
u.vout note.poym
|
|
|
|
==
|
|
|
|
:- [(give-update:hc %new-tx new-hest)]~
|
|
|
|
%= state
|
|
|
|
poym [~ ~]
|
|
|
|
history (~(put by history) txid.ti new-hest)
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ 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)
|
|
|
|
=/ new-hest
|
|
|
|
(mk-hest ti xpub.u.pay payer.u.pay `our.bowl u.vout note.u.pay)
|
|
|
|
=. state (del-all-piym txid.ti payer.u.pay)
|
|
|
|
:- [(give-update:hc %new-tx new-hest)]~
|
2021-06-25 19:05:58 +03:00
|
|
|
%_ state
|
2021-06-24 20:39:33 +03:00
|
|
|
history (~(put by history) txid.ti new-hest)
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ 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))
|
|
|
|
==
|
|
|
|
--
|
|
|
|
::
|
|
|
|
++ mk-hest
|
|
|
|
|= $: ti=info:tx
|
|
|
|
=xpub:bc
|
|
|
|
payer=ship
|
|
|
|
payee=(unit ship)
|
|
|
|
vout=@ud
|
|
|
|
note=(unit @t)
|
|
|
|
==
|
|
|
|
^- hest
|
|
|
|
:* xpub
|
|
|
|
txid.ti
|
|
|
|
confs.ti
|
|
|
|
recvd.ti
|
|
|
|
(turn inputs.ti |=(i=val:tx [i `payer]))
|
|
|
|
%+ turn outputs.ti
|
|
|
|
|= o=val:tx
|
2021-07-02 09:14:09 +03:00
|
|
|
?: =(pos.o vout)
|
2021-06-24 20:39:33 +03:00
|
|
|
:: check whether this is the output that went to payee
|
|
|
|
[o payee]
|
|
|
|
[o `payer]
|
|
|
|
note
|
|
|
|
==
|
|
|
|
--
|
2021-06-25 02:12:46 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
%fail-broadcast-tx
|
|
|
|
?> =(src.bowl our.bowl)
|
|
|
|
~& >>> "%fail-broadcast-tx"
|
|
|
|
:_ state(poym [~ ~])
|
|
|
|
[(give-update:hc %error %broadcast-fail)]~
|
2021-06-25 02:12:46 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
%succeed-broadcast-tx
|
|
|
|
?> =(src.bowl our.bowl)
|
|
|
|
~& > "%succeed-broadcast-tx"
|
|
|
|
:_ state
|
|
|
|
:- (give-update:hc %broadcast-success ~)
|
|
|
|
?~ prov ~
|
|
|
|
:- (poke-provider:hc [%tx-info txid.intr])
|
|
|
|
?~ txbu.poym ~
|
|
|
|
?~ payee.u.txbu.poym ~
|
|
|
|
:_ ~
|
|
|
|
%- poke-peer:hc
|
|
|
|
:* u.payee.u.txbu.poym
|
|
|
|
%expect-payment
|
|
|
|
txid.intr
|
|
|
|
value:(snag 0 txos.u.txbu.poym)
|
|
|
|
==
|
|
|
|
==
|
|
|
|
--
|
|
|
|
::
|
2021-02-12 17:37:21 +03:00
|
|
|
++ on-agent
|
2021-06-24 20:39:33 +03:00
|
|
|
~/ %on-agent
|
2021-02-12 17:37:21 +03:00
|
|
|
|= [=wire =sign:agent:gall]
|
|
|
|
^- (quip card _this)
|
2021-06-24 20:39:33 +03:00
|
|
|
|^
|
|
|
|
?+ -.sign (on-agent:def wire sign)
|
2021-06-18 01:53:12 +03:00
|
|
|
%watch-ack
|
|
|
|
?~ p.sign `this
|
|
|
|
%- (slog leaf+"connection rejected by provider ({<src.bowl>})" u.p.sign)
|
|
|
|
`this
|
2021-06-24 20:39:33 +03:00
|
|
|
::
|
2021-02-12 17:37:21 +03:00
|
|
|
%kick
|
|
|
|
?~ prov `this
|
2021-06-25 02:12:46 +03:00
|
|
|
?. ?& ?=(%set-provider -.wire)
|
2021-02-12 17:37:21 +03:00
|
|
|
=(host.u.prov src.bowl)
|
|
|
|
==
|
2021-06-25 02:12:46 +03:00
|
|
|
`this
|
|
|
|
:_ this(prov [~ src.bowl %.n])
|
2021-07-02 20:59:58 +03:00
|
|
|
%- zing
|
2021-06-25 02:12:46 +03:00
|
|
|
:~ (watch-provider:hc src.bowl)
|
2021-07-02 20:59:58 +03:00
|
|
|
(give-update:hc %change-provider `[src.bowl %.n])^~
|
2021-06-25 02:12:46 +03:00
|
|
|
==
|
2021-06-24 20:39:33 +03:00
|
|
|
::
|
2021-02-12 17:37:21 +03:00
|
|
|
%fact
|
|
|
|
=^ cards state
|
|
|
|
?+ p.cage.sign `state
|
|
|
|
%btc-provider-status
|
2021-06-24 20:39:33 +03:00
|
|
|
(handle-provider-status !<(status:bp q.cage.sign))
|
|
|
|
::
|
2021-02-12 17:37:21 +03:00
|
|
|
%btc-provider-update
|
2021-06-24 20:39:33 +03:00
|
|
|
(handle-provider-update !<(update:bp q.cage.sign))
|
|
|
|
::
|
2021-04-02 01:33:27 +03:00
|
|
|
%json
|
2021-04-20 05:48:52 +03:00
|
|
|
?+ wire `state
|
|
|
|
[%check-payee @ ~]
|
|
|
|
=/ who (slav %p i.t.wire)
|
|
|
|
:_ state
|
|
|
|
:~ [%give %fact ~[/all] cage.sign]
|
|
|
|
[%pass wire %agent [who %btc-wallet] %leave ~]
|
|
|
|
==
|
|
|
|
::
|
|
|
|
[%permitted @ ~]
|
|
|
|
=/ who (slav %p i.t.wire)
|
|
|
|
:_ state
|
|
|
|
:~ [%give %fact ~[/all] cage.sign]
|
|
|
|
[%pass wire %agent [who %btc-provider] %leave ~]
|
|
|
|
==
|
2021-04-02 01:33:27 +03:00
|
|
|
==
|
2021-02-12 17:37:21 +03:00
|
|
|
==
|
2021-06-24 20:39:33 +03:00
|
|
|
[cards this]
|
2021-02-12 17:37:21 +03:00
|
|
|
==
|
2021-04-20 05:48:52 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
:: +handle-provider-status: handle connectivity updates from provider
|
|
|
|
:: - retry pend.piym on any %connected event, since we're checking mempool
|
|
|
|
:: - 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
|
|
|
|
^- (quip card _state)
|
|
|
|
=^ cards state
|
2021-04-22 04:31:42 +03:00
|
|
|
?~ prov `state
|
2021-06-24 20:39:33 +03:00
|
|
|
?. =(host.u.prov src.bowl) `state
|
|
|
|
?- -.s
|
|
|
|
%new-block
|
|
|
|
%: on-connected
|
|
|
|
u.prov network.s
|
|
|
|
block.s fee.s
|
|
|
|
`blockhash.s `blockfilter.s
|
|
|
|
==
|
2021-06-25 19:05:58 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
%connected
|
|
|
|
(on-connected u.prov network.s block.s fee.s ~ ~)
|
2021-06-25 19:05:58 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
%disconnected
|
|
|
|
`state(prov `u.prov(connected %.n))
|
2021-05-18 14:03:30 +03:00
|
|
|
==
|
2021-04-02 01:33:27 +03:00
|
|
|
:_ state
|
2021-06-25 02:12:46 +03:00
|
|
|
:+ (give-update:hc %btc-state btc-state)
|
|
|
|
(give-update:hc %change-provider prov)
|
|
|
|
cards
|
2021-04-20 05:48:52 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ on-connected
|
|
|
|
|= $: p=provider
|
|
|
|
net=network
|
|
|
|
block=@ud
|
|
|
|
fee=(unit sats)
|
|
|
|
blockhash=(unit hexb)
|
|
|
|
blockfilter=(unit hexb)
|
|
|
|
==
|
|
|
|
^- (quip card _state)
|
|
|
|
|^
|
|
|
|
:: request block-info for missing blocks
|
|
|
|
:: if blockhash or blockfilter are ~ request block-info for current block
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
=| blocks=(list @ud)
|
|
|
|
=/ gap (sub block block.btc-state)
|
|
|
|
=? blocks (gth gap 1)
|
|
|
|
(gulf +(block.btc-state) (dec block))
|
2021-06-29 00:06:04 +03:00
|
|
|
=? blocks ?&((gth gap 0) ?|(?=(~ blockhash) ?=(~ blockfilter)))
|
2021-06-24 20:39:33 +03:00
|
|
|
(snoc blocks block)
|
|
|
|
=? blocks (gth gap 50) ~
|
2021-06-25 02:12:46 +03:00
|
|
|
:_ %_ state
|
|
|
|
prov `p(connected %.y)
|
|
|
|
btc-state [block fee now.bowl]
|
|
|
|
==
|
|
|
|
%- zing
|
|
|
|
:~ retry-ahistorical-txs
|
2021-06-24 20:39:33 +03:00
|
|
|
(retry-pend-piym net)
|
|
|
|
(retry-block-info blocks)
|
2021-06-25 02:12:46 +03:00
|
|
|
::
|
|
|
|
?. ?|(!connected.p (gth gap 0))
|
|
|
|
~
|
|
|
|
%- zing
|
|
|
|
:~ (retry-poym net)
|
|
|
|
(retry-txs net)
|
|
|
|
(retry-scans net)
|
|
|
|
==
|
|
|
|
::
|
|
|
|
?. ?&(?=(^ blockhash) ?=(^ blockfilter) (gth gap 0))
|
|
|
|
~
|
|
|
|
(retry-filtered-addrs:hc net u.blockhash u.blockfilter)
|
|
|
|
::
|
|
|
|
?. (gth gap 50)
|
|
|
|
~
|
|
|
|
(retry-addrs net)
|
2021-05-17 05:31:41 +03:00
|
|
|
==
|
2021-02-13 15:14:50 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ retry-ahistorical-txs
|
|
|
|
^- (list card)
|
|
|
|
%+ turn ~(tap in ahistorical-txs)
|
|
|
|
|= =txid
|
|
|
|
(poke-provider:hc [%tx-info txid])
|
2021-02-18 15:13:06 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
:: +retry-pend-piym: check whether txids in pend-piym are in mempool
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ 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:hc [%tx-info txid])
|
2021-05-14 15:30:56 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ retry-block-info
|
|
|
|
|= blocks=(list @ud)
|
|
|
|
%+ turn blocks
|
|
|
|
|= block=@ud
|
|
|
|
(poke-provider:hc %block-info `block)
|
2021-02-13 15:14:50 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ retry-poym
|
|
|
|
|= =network
|
|
|
|
^- (list card)
|
|
|
|
?~ txbu.poym ~
|
|
|
|
=/ w (~(get by walts) xpub.u.txbu.poym)
|
|
|
|
?~ w ~
|
|
|
|
?. =(network network.u.w) ~
|
|
|
|
%+ weld
|
|
|
|
?~ signed-tx.u.txbu.poym ~
|
|
|
|
~[(poke-provider:hc [%broadcast-tx u.signed-tx.u.txbu.poym])]
|
|
|
|
%+ turn txis.u.txbu.poym
|
|
|
|
|= =txi
|
|
|
|
(poke-provider:hc [%raw-tx ~(get-txid txb:bl u.txbu.poym)])
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
:: +retry-txs: get info on txs without enough confirmations
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ 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:hc [%tx-info txid])
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ retry-scans
|
|
|
|
|= =network
|
|
|
|
^- (list card)
|
|
|
|
%- zing
|
|
|
|
%+ murn ~(tap by scans)
|
|
|
|
|= [[=xpub:bc =chyg] =batch]
|
|
|
|
=/ w (~(get by walts) xpub)
|
|
|
|
?~ w ~
|
|
|
|
?. =(network network.u.w) ~
|
|
|
|
`-:(req-scan:hc batch xpub chyg)
|
2021-03-01 12:13:07 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
:: +retry-addrs: get info on addresses with unconfirmed UTXOs
|
2021-03-01 12:13:07 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ retry-addrs
|
|
|
|
|= =network
|
|
|
|
^- (list card)
|
|
|
|
%- zing
|
|
|
|
%+ murn ~(val by walts)
|
|
|
|
|= w=walt
|
|
|
|
?. =(network network.w) ~
|
|
|
|
^- (unit (list card))
|
|
|
|
:- ~
|
|
|
|
%+ turn ~(tap by wach.w)
|
|
|
|
|= [a=address *]
|
|
|
|
(poke-provider:hc [%address-info a])
|
2021-03-01 12:13:07 +03:00
|
|
|
--
|
2021-06-24 20:39:33 +03:00
|
|
|
::
|
|
|
|
++ handle-provider-update
|
|
|
|
|= upd=update:bp
|
|
|
|
^- (quip card _state)
|
2021-02-18 15:59:32 +03:00
|
|
|
|^
|
2021-10-21 22:09:51 +03:00
|
|
|
?: =(~ prov) `state
|
|
|
|
?. =(host:(need prov) src.bowl) `state
|
2021-06-24 20:39:33 +03:00
|
|
|
?. ?=(%.y -.upd) `state
|
|
|
|
?- -.p.upd
|
|
|
|
%address-info
|
|
|
|
:: located in the helper in Scan Logic to keep all of that unified
|
|
|
|
::
|
|
|
|
(handle-address-info address.p.upd utxos.p.upd used.p.upd)
|
2021-06-25 02:12:46 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
%tx-info
|
2021-06-25 02:12:46 +03:00
|
|
|
:: TODO: why do we get a nest-fail when using =^ ?
|
2021-10-21 22:09:51 +03:00
|
|
|
=^ cards=(list card) state
|
2021-06-24 20:39:33 +03:00
|
|
|
(handle-tx-info:hc info.p.upd)
|
2021-10-21 22:09:51 +03:00
|
|
|
:_ state
|
2021-06-25 02:12:46 +03:00
|
|
|
:_ cards
|
|
|
|
(poke-internal:hc [%close-pym info.p.upd])
|
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
%raw-tx
|
|
|
|
:_ state
|
|
|
|
~[(poke-internal:hc [%add-poym-raw-txi +.p.upd])]
|
2021-06-25 02:12:46 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
%broadcast-tx
|
|
|
|
:_ state
|
2021-06-25 02:12:46 +03:00
|
|
|
?~ txbu.poym ~
|
|
|
|
?. =(~(get-txid txb:bl u.txbu.poym) txid.p.upd)
|
|
|
|
~
|
2021-06-24 20:39:33 +03:00
|
|
|
?: ?|(broadcast.p.upd included.p.upd)
|
|
|
|
~[(poke-internal:hc [%succeed-broadcast-tx txid.p.upd])]
|
|
|
|
:~ (poke-internal:hc [%fail-broadcast-tx txid.p.upd])
|
|
|
|
(give-update:hc %cancel-tx txid.p.upd)
|
2021-02-18 15:59:32 +03:00
|
|
|
==
|
2021-06-25 02:12:46 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
%block-info
|
|
|
|
:_ state
|
2021-06-25 02:12:46 +03:00
|
|
|
%^ retry-filtered-addrs:hc
|
|
|
|
network.p.upd
|
|
|
|
blockhash.p.upd
|
|
|
|
blockfilter.p.upd
|
2021-06-24 20:39:33 +03:00
|
|
|
==
|
2021-02-18 15:59:32 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
:: Scan Logic
|
|
|
|
::
|
|
|
|
:: 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
|
|
|
|
::
|
|
|
|
:: +handle-address-info: updates scans and wallet with address info
|
|
|
|
::
|
|
|
|
++ handle-address-info
|
|
|
|
|= [=address utxos=(set utxo) used=?]
|
|
|
|
^- (quip card _state)
|
|
|
|
=/ ac (address-coords:bl address ~(val by walts))
|
|
|
|
?~ ac
|
|
|
|
`state
|
|
|
|
=/ [w=walt =chyg =idx] u.ac
|
|
|
|
=. walts
|
|
|
|
%+ ~(put by walts) xpub.w
|
|
|
|
%+ ~(update-address wad:bl w chyg)
|
|
|
|
address
|
|
|
|
[used chyg idx utxos]
|
|
|
|
:: if transactions haven't made it into history, request transaction info
|
2021-02-18 15:59:32 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
=^ 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:hc [%tx-info txid.u]) cad]
|
|
|
|
(~(put by ah) txid.u)
|
|
|
|
:: if the wallet+chyg is being scanned, update the scan batch
|
2021-02-18 15:59:32 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
=/ b (~(get by scans) [xpub.w chyg])
|
|
|
|
?~ b
|
|
|
|
[cards state]
|
|
|
|
=. scans
|
|
|
|
(del-scanned u.b(has-used ?|(used has-used.u.b)) xpub.w chyg idx)
|
|
|
|
?: empty:(scan-status xpub.w chyg)
|
|
|
|
=^ scan-cards=(list card) state
|
|
|
|
(check-scan xpub.w)
|
|
|
|
[(weld scan-cards cards) state]
|
2021-02-18 15:59:32 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
[cards state]
|
2021-02-18 15:59:32 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
:: +del-scanned: delete scanned idxs
|
2021-02-18 15:13:06 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ del-scanned
|
|
|
|
|= [b=batch =xpub:bc =chyg to-delete=idx]
|
|
|
|
^- ^scans
|
|
|
|
%+ ~(put by scans) [xpub chyg]
|
|
|
|
b(todo (~(del in todo.b) to-delete))
|
2021-02-18 15:13:06 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ scan-status
|
|
|
|
|= [=xpub:bc =chyg]
|
|
|
|
^- [empty=? done=?]
|
|
|
|
=/ b=batch (~(got by scans) [xpub chyg])
|
|
|
|
=/ empty=? =(0 ~(wyt in todo.b))
|
|
|
|
:- empty
|
|
|
|
?&(empty ?!(has-used.b))
|
|
|
|
:: +check-scan: initiate a scan if one hasn't started
|
|
|
|
:: check status of scan if one is running
|
|
|
|
::
|
|
|
|
++ check-scan
|
|
|
|
|= =xpub:bc
|
|
|
|
^- (quip card _state)
|
|
|
|
=/ s0 (scan-status xpub %0)
|
|
|
|
=/ s1 (scan-status xpub %1)
|
|
|
|
?: ?&(empty.s0 done.s0 empty.s1 done.s1)
|
|
|
|
(end-scan xpub)
|
|
|
|
=^ cards0=(list card) state
|
|
|
|
(bump-batch xpub %0)
|
|
|
|
=^ cards1=(list card) state
|
|
|
|
(bump-batch xpub %1)
|
2021-07-02 09:14:09 +03:00
|
|
|
:_ state
|
|
|
|
[(scan-progress:hc xpub) (weld cards0 cards1)]
|
2021-06-24 20:39:33 +03:00
|
|
|
::
|
|
|
|
:: delete the xpub from scans and set wallet to scanned
|
|
|
|
::
|
|
|
|
++ end-scan
|
|
|
|
|= [=xpub:bc]
|
|
|
|
^- (quip card _state)
|
|
|
|
=/ w=walt (~(got by walts) xpub)
|
|
|
|
=. scans (~(del by scans) [xpub %0])
|
2021-06-25 19:05:58 +03:00
|
|
|
=: scans (~(del by scans) [xpub %1])
|
|
|
|
walts (~(put by walts) xpub w(scanned %.y))
|
|
|
|
==
|
2021-06-24 20:39:33 +03:00
|
|
|
%- (slog ~[leaf+"Scanned xpub {<xpub>}"])
|
2021-07-02 09:47:46 +03:00
|
|
|
=^ cards state
|
|
|
|
(set-curr-xpub:hc xpub)
|
|
|
|
[[(give-update:hc [%scan-progress ~ ~]) cards] state]
|
2021-06-24 20:39:33 +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
|
|
|
|
|= [=xpub:bc =chyg]
|
|
|
|
^- (quip card _state)
|
|
|
|
=/ b=batch (~(got by scans) xpub chyg)
|
|
|
|
=/ s (scan-status xpub chyg)
|
|
|
|
?. ?&(empty.s ?!(done.s))
|
|
|
|
`state
|
|
|
|
=/ w=walt (~(got by walts) xpub)
|
|
|
|
=/ newb=batch
|
2021-06-25 19:05:58 +03:00
|
|
|
:+ (silt (gulf +(endpoint.b) (add endpoint.b max-gap.w)))
|
|
|
|
(add endpoint.b max-gap.w)
|
|
|
|
%.n
|
2021-06-24 20:39:33 +03:00
|
|
|
(req-scan:hc newb xpub chyg)
|
|
|
|
--
|
|
|
|
--
|
2021-06-12 02:10:56 +03:00
|
|
|
::
|
2021-06-24 20:45:29 +03:00
|
|
|
++ on-peek
|
|
|
|
~/ %on-peek
|
|
|
|
|= pax=path
|
|
|
|
^- (unit (unit cage))
|
|
|
|
?+ pax (on-peek:def pax)
|
|
|
|
[%x %configured ~]
|
|
|
|
=/ provider=json
|
|
|
|
?~ prov ~
|
|
|
|
[%s (scot %p host.u.prov)]
|
|
|
|
=/ result=json
|
|
|
|
%- pairs:enjs:format
|
|
|
|
:~ [%provider provider]
|
|
|
|
[%'hasWallet' b+?=(^ walts)]
|
|
|
|
==
|
|
|
|
``json+!>(result)
|
|
|
|
::
|
|
|
|
[%x %scanned ~]
|
|
|
|
``noun+!>(scanned-wallets:hc)
|
|
|
|
::
|
|
|
|
[%x %balance @ ~]
|
|
|
|
``noun+!>((balance:hc (xpub:bc +>-.pax)))
|
|
|
|
==
|
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ on-watch
|
|
|
|
~/ %on-watch
|
|
|
|
|= =path
|
|
|
|
^- (quip card _this)
|
|
|
|
?+ path (on-watch:def path)
|
|
|
|
[%check-payee @ ~]
|
|
|
|
=/ who (slav %p i.t.path)
|
|
|
|
?> =(who our.bowl)
|
|
|
|
=/ response=json
|
|
|
|
%+ frond:enjs:format 'checkPayee'
|
|
|
|
%- pairs:enjs:format
|
|
|
|
:~ ['hasWallet' b+?=(^ curr-xpub)]
|
|
|
|
['payee' (ship:enjs:format our.bowl)]
|
2021-02-15 11:23:56 +03:00
|
|
|
==
|
2021-06-24 20:39:33 +03:00
|
|
|
:_ this
|
|
|
|
[%give %fact ~ %json !>(response)]~
|
2021-06-12 02:10:56 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
[%all ~]
|
|
|
|
?> (team:title our.bowl src.bowl)
|
|
|
|
:_ this
|
|
|
|
[give-initial:hc]~
|
2021-06-12 02:10:56 +03:00
|
|
|
==
|
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ on-leave on-leave:def
|
2021-10-21 21:03:05 +03:00
|
|
|
++ on-arvo
|
|
|
|
|= [=wire sign=sign-arvo]
|
|
|
|
^- (quip card _this)
|
|
|
|
?. ?=([%migrate-settings ~] wire) (on-arvo:def wire sign)
|
|
|
|
?> ?=([%behn *] sign)
|
|
|
|
(on-poke %noun !>(%migrate-settings))
|
2021-06-24 20:39:33 +03:00
|
|
|
++ on-fail on-fail:def
|
|
|
|
--
|
|
|
|
~% %btc-wallet-helper ..card ~
|
|
|
|
|_ =bowl:gall
|
2021-06-12 02:10:56 +03:00
|
|
|
::
|
|
|
|
++ retry-filtered-addrs
|
2021-06-24 20:39:33 +03:00
|
|
|
~/ %retry-filtered-addrs
|
2021-06-12 02:10:56 +03:00
|
|
|
|= [=network blockhash=hexb blockfilter=hexb]
|
|
|
|
^- (list card)
|
|
|
|
%- zing
|
|
|
|
%+ murn ~(val by walts)
|
|
|
|
|= w=walt
|
|
|
|
^- (unit (list card))
|
|
|
|
?. =(network network.w) ~
|
|
|
|
:- ~
|
2021-06-24 20:39:33 +03:00
|
|
|
%+ turn
|
2021-06-12 02:10:56 +03:00
|
|
|
%~ tap in
|
2021-06-24 20:39:33 +03:00
|
|
|
%^ all-match:bip-b158:bc
|
2021-06-12 02:10:56 +03:00
|
|
|
blockfilter
|
2021-06-24 20:39:33 +03:00
|
|
|
blockhash
|
|
|
|
%+ turn ~(tap by wach.w)
|
|
|
|
|= [a=address *]
|
|
|
|
[a (to-script-pubkey:adr:bc a)]
|
2021-06-12 02:10:56 +03:00
|
|
|
|= [a=address spk=hexb]
|
2021-06-24 20:39:33 +03:00
|
|
|
^- card
|
|
|
|
(poke-provider [%address-info a])
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
++ handle-tx-info
|
2021-06-24 20:39:33 +03:00
|
|
|
~/ %handle-tx-info
|
2021-02-12 17:37:21 +03:00
|
|
|
|= ti=info:tx
|
2021-04-16 17:11:03 +03:00
|
|
|
^- (quip card _state)
|
2021-02-12 17:37:21 +03:00
|
|
|
|^
|
|
|
|
=/ h (~(get by history) txid.ti)
|
2021-04-09 02:11:31 +03:00
|
|
|
=. ahistorical-txs (~(del in ahistorical-txs) txid.ti)
|
2021-05-17 06:41:08 +03:00
|
|
|
=/ our-inputs=(set address)
|
2021-02-18 15:13:06 +03:00
|
|
|
%- silt
|
2021-02-14 13:17:58 +03:00
|
|
|
%+ skim
|
2021-05-17 06:41:08 +03:00
|
|
|
%+ turn inputs.ti
|
2021-02-14 13:17:58 +03:00
|
|
|
|=(=val:tx address.val)
|
|
|
|
is-our-address
|
2021-05-17 06:41:08 +03:00
|
|
|
=/ our-outputs=(set address)
|
|
|
|
%- silt
|
|
|
|
%+ skim
|
|
|
|
%+ turn outputs.ti
|
|
|
|
|=(=val:tx address.val)
|
|
|
|
is-our-address
|
2021-06-24 20:39:33 +03:00
|
|
|
:: all our addresses in inputs/outputs of tx
|
|
|
|
::
|
|
|
|
=/ our-addrs=(set address)
|
2021-05-17 06:41:08 +03:00
|
|
|
(~(uni in our-inputs) our-outputs)
|
|
|
|
::
|
2021-04-25 21:52:04 +03:00
|
|
|
=/ addr-info-cards=(list card)
|
|
|
|
%+ turn ~(tap in our-addrs)
|
|
|
|
|= a=address
|
|
|
|
^- card
|
|
|
|
(poke-provider [%address-info a])
|
2021-04-16 17:11:03 +03:00
|
|
|
?: =(0 ~(wyt in our-addrs)) `state
|
2021-02-14 13:17:58 +03:00
|
|
|
=/ =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-06-24 20:39:33 +03:00
|
|
|
:: addresses in wallets, but tx not in history
|
|
|
|
::
|
|
|
|
?~ h
|
2021-05-17 06:41:08 +03:00
|
|
|
=/ new-hest=hest (mk-hest xpub our-inputs our-outputs)
|
2021-04-16 17:11:03 +03:00
|
|
|
=. history (~(put by history) txid.ti new-hest)
|
|
|
|
:_ state
|
2021-06-25 02:12:46 +03:00
|
|
|
:+ (give-update %balance current-balance)
|
2021-05-07 15:31:53 +03:00
|
|
|
(give-update %new-tx new-hest)
|
2021-06-25 02:12:46 +03:00
|
|
|
addr-info-cards
|
2021-06-24 20:39:33 +03:00
|
|
|
:: tx in history, but not in mempool/blocks
|
|
|
|
::
|
|
|
|
?. included.ti
|
2021-04-16 17:11:03 +03:00
|
|
|
:_ state(history (~(del by history) txid.ti))
|
2021-06-25 02:12:46 +03:00
|
|
|
:+ (give-update %balance current-balance)
|
2021-05-07 15:31:53 +03:00
|
|
|
(give-update %cancel-tx txid.ti)
|
2021-06-25 02:12:46 +03:00
|
|
|
addr-info-cards
|
2021-04-16 17:11:03 +03:00
|
|
|
=/ new-hest u.h(confs confs.ti, recvd recvd.ti)
|
|
|
|
=. history (~(put by history) txid.ti new-hest)
|
|
|
|
:_ state
|
2021-06-25 02:12:46 +03:00
|
|
|
:+ (give-update %balance current-balance)
|
2021-05-07 15:31:53 +03:00
|
|
|
(give-update %new-tx new-hest)
|
2021-06-25 02:12:46 +03:00
|
|
|
addr-info-cards
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
++ mk-hest
|
|
|
|
:: has tx-info
|
2021-06-24 20:39:33 +03:00
|
|
|
|= [=xpub:bc our-inputs=(set address) our-outputs=(set address)]
|
|
|
|
^- hest
|
|
|
|
:* xpub
|
|
|
|
txid.ti
|
|
|
|
confs.ti
|
|
|
|
recvd.ti
|
|
|
|
(turn inputs.ti |=(v=val:tx (is-our-ship our-inputs v)))
|
|
|
|
(turn outputs.ti |=(v=val:tx (is-our-ship our-outputs 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-06-24 20:39:33 +03:00
|
|
|
::
|
2021-02-14 13:17:58 +03:00
|
|
|
++ set-curr-xpub
|
|
|
|
|= =xpub
|
|
|
|
^- (quip card _state)
|
|
|
|
?~ (find ~[xpub] scanned-wallets) `state
|
2021-04-22 04:31:42 +03:00
|
|
|
=. curr-xpub `xpub
|
|
|
|
:_ state
|
|
|
|
[give-initial]~
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
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-06-24 20:39:33 +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])))
|
2021-06-25 02:12:46 +03:00
|
|
|
%_ state
|
2021-02-13 15:14:50 +03:00
|
|
|
scans
|
|
|
|
(~(put by scans) [xpub chyg] b)
|
2021-06-25 02:12:46 +03:00
|
|
|
::
|
2021-02-13 15:14:50 +03:00
|
|
|
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
|
|
|
::
|
|
|
|
++ poke-provider
|
2021-06-24 20:39:33 +03:00
|
|
|
|= act=action:bp
|
2021-02-12 17:37:21 +03:00
|
|
|
^- 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-06-24 20:39:33 +03:00
|
|
|
::
|
2021-02-18 15:13:06 +03:00
|
|
|
++ poke-internal
|
2021-06-24 20:39:33 +03:00
|
|
|
|= intr=internal
|
2021-02-18 15:13:06 +03:00
|
|
|
^- 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
|
|
|
::
|
2021-06-30 22:48:14 +03:00
|
|
|
++ poke-our
|
|
|
|
|= [app=term =cage]
|
|
|
|
^- card
|
|
|
|
[%pass / %agent [our.bowl app] %poke cage]
|
|
|
|
::
|
2021-04-16 17:11:03 +03:00
|
|
|
++ give-update
|
|
|
|
|= upd=update
|
|
|
|
^- card
|
|
|
|
[%give %fact ~[/all] %btc-wallet-update !>(upd)]
|
|
|
|
::
|
2021-07-02 09:14:09 +03:00
|
|
|
++ scan-progress
|
|
|
|
|= [=xpub:bc]
|
|
|
|
|^ ^- card
|
|
|
|
%- give-update
|
|
|
|
:+ %scan-progress
|
|
|
|
(to-idx (~(gut by scans.state) [xpub %0] *batch))
|
|
|
|
(to-idx (~(gut by scans.state) [xpub %1] *batch))
|
|
|
|
++ to-idx
|
|
|
|
|= b=batch
|
|
|
|
^- (unit idx:bc)
|
|
|
|
=/ s=(list idx:bc)
|
|
|
|
(sort ~(tap in todo.b) lth)
|
|
|
|
?~ s ~ `i.s
|
|
|
|
--
|
|
|
|
::
|
2021-06-17 13:33:22 +03:00
|
|
|
++ watch-provider
|
|
|
|
|= who=@p
|
2021-07-02 20:59:58 +03:00
|
|
|
^- (list card)
|
|
|
|
=/ =dock [who %btc-provider]
|
|
|
|
=/ 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)]
|
|
|
|
~
|
2021-06-17 13:33:22 +03:00
|
|
|
::
|
2021-04-22 04:31:42 +03:00
|
|
|
++ give-initial
|
|
|
|
^- card
|
|
|
|
=^ a=(unit address) state
|
|
|
|
?~ curr-xpub `state
|
|
|
|
=/ uw=(unit walt) (~(get by walts) u.curr-xpub)
|
|
|
|
?: ?|(?=(~ uw) ?!(scanned.u.uw))
|
|
|
|
~|("no wallet with xpub or wallet not scanned yet" !!)
|
|
|
|
=/ [addr=address =idx w=walt]
|
|
|
|
~(gen-address wad:bl u.uw %0)
|
|
|
|
[`addr state(walts (~(put by walts) u.curr-xpub w))]
|
2021-06-24 20:39:33 +03:00
|
|
|
%- give-update
|
|
|
|
^- update
|
|
|
|
:* %initial
|
|
|
|
prov
|
|
|
|
curr-xpub
|
|
|
|
current-balance
|
|
|
|
current-history
|
|
|
|
btc-state
|
|
|
|
a
|
|
|
|
==
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ current-balance
|
|
|
|
^- (unit [sats sats])
|
|
|
|
?~ curr-xpub ~
|
|
|
|
(balance u.curr-xpub)
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ current-history
|
|
|
|
^- ^history
|
|
|
|
?~ curr-xpub ~
|
|
|
|
%- ~(gas by *^history)
|
|
|
|
%+ skim ~(tap by history)
|
|
|
|
|= [txid =hest]
|
|
|
|
=(u.curr-xpub xpub.hest)
|
2021-02-12 17:37:21 +03:00
|
|
|
::
|
|
|
|
++ balance
|
2021-06-24 20:39:33 +03:00
|
|
|
~/ %balance
|
2021-02-21 13:13:50 +03:00
|
|
|
|= =xpub:bc
|
2021-04-23 23:18:20 +03:00
|
|
|
^- (unit [sats sats])
|
2021-02-12 17:37:21 +03:00
|
|
|
=/ w (~(get by walts) xpub)
|
|
|
|
?~ w ~
|
2021-04-23 23:18:20 +03:00
|
|
|
=/ values=(list [confirmed=sats unconfirmed=sats])
|
2021-02-12 17:37:21 +03:00
|
|
|
%+ turn ~(val by wach.u.w)
|
2021-04-23 23:18:20 +03:00
|
|
|
|= =addi ^- [sats sats]
|
2021-02-12 17:37:21 +03:00
|
|
|
%+ roll
|
|
|
|
%+ turn ~(tap by utxos.addi)
|
2021-04-23 23:18:20 +03:00
|
|
|
|= =utxo
|
|
|
|
^- [sats sats]
|
|
|
|
?: (~(spendable sut:bl [u.w eny.bowl block.btc-state ~ 0 ~]) utxo)
|
|
|
|
[value.utxo 0]
|
|
|
|
[0 value.utxo]
|
|
|
|
|= [[a=sats b=sats] out=[p=sats q=sats]]
|
|
|
|
[(add a p.out) (add b q.out)]
|
|
|
|
:- ~
|
|
|
|
%+ roll values
|
|
|
|
|= [[a=sats b=sats] out=[p=sats q=sats]]
|
|
|
|
[(add a p.out) (add b q.out)]
|
2021-04-02 01:33:27 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ is-dust
|
|
|
|
|= [=sats =address]
|
|
|
|
^- ?
|
|
|
|
%+ lth sats
|
|
|
|
(mul 3 (input-weight:bc (get-bipt:adr:bc address)))
|
2021-04-02 01:33:27 +03:00
|
|
|
::
|
2021-06-24 20:39:33 +03:00
|
|
|
++ is-broadcasting
|
|
|
|
^- ?
|
|
|
|
?~ txbu.poym %.n
|
|
|
|
?=(^ signed-tx.u.txbu.poym)
|
|
|
|
::
|
|
|
|
++ scanned-wallets
|
|
|
|
^- (list xpub:bc)
|
|
|
|
%+ murn ~(tap by walts)
|
|
|
|
|= [=xpub:bc w=walt]
|
|
|
|
^- (unit xpub:bc)
|
|
|
|
?:(scanned.w `xpub ~)
|
2021-06-30 04:03:34 +03:00
|
|
|
::
|
|
|
|
++ gall-scry
|
|
|
|
|* [=mold app=@tas =path]
|
|
|
|
.^(mold %gx (weld /(scot %p our.bowl)/[app]/(scot %da now.bowl) path))
|
2021-02-12 17:37:21 +03:00
|
|
|
--
|