btc: record history for transactions that occur outside wallet flow
feybs=(map ship sats)
=piym
=poym
+ ahistorical-txs=(set txid)
==
::
+$ card card:agent:gall
*(map ship sats)
*^piym
*^poym
+ ~
==
==
++ on-save
=+ n=(~(gut by num-fam.piym) f 0)
?: (gte n fam-limit.params)
~|("More than {<fam-limit.params>} addresses for moons + planet" !!)
-
=. state state(num-fam.piym (~(put by num-fam.piym) f +(n)))
=^ a=address state
(generate-address u.curr-xpub %0)
(retry-addrs network)
(retry-txs network)
(retry-scans network)
+ retry-ahistorical-txs
==
+ ;: weld
+ retry-ahistorical-txs
(retry-pend-piym network)
+ ==
+ ::
+ ++ retry-ahistorical-txs
+ ^- (list card)
+ %+ turn ~(tap in ahistorical-txs)
+ |= =txid
+ (poke-provider [%tx-info txid])
::
++ retry-scans
|= =network
^- _state
|^
=/ h (~(get by history) txid.ti)
+ =. ahistorical-txs (~(del in ahistorical-txs) txid.ti)
=/ our-addrs=(set address) :: all our addresses in inputs/outputs of tx
%- silt
%+ skim
|= [=address utxos=(set utxo) used=?]
^- (quip card _state)
=/ ac (address-coords:bl address ~(val by walts))
- ?~ ac `state
+ ?~ 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
+ ::
+ =^ 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)
:: if the wallet+chyg is being scanned, update the scan batch
::
=/ b (~(get by scans) [xpub.w chyg])
- ?~ b `state
+ ?~ 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)
- `state
+ [(weld scan-cards cards) state]
+ ::
+ [cards state]
:: +req-scan
:: - adds addresses in batch to wallet's watch map as un-used addresses
:: - returns provider %address-info request cards
