Merge branch 'release/bitcoin-wallet' of github.com:urbit/urbit into release/bitcoin-wallet

This commit is contained in:
finned-palmer 2021-07-02 13:13:41 -05:00
commit 71c2cbaea6
4 changed files with 77 additions and 20 deletions

View File

@ -3,7 +3,7 @@
:: Scrys
:: x/scanned: (list xpub) of all scanned wallets
:: x/balance/xpub: balance (in sats) of wallet
/- *btc-wallet, bp=btc-provider, file-server, launch-store
/- *btc-wallet, bp=btc-provider, file-server, launch-store, settings
/+ dbug, default-agent, bl=btc, bc=bitcoin, bcu=bitcoin-utils, bip32
~% %btc-wallet-top ..part ~
|%
@ -69,21 +69,28 @@
++ on-init
^- (quip card _this)
~& > '%btc-wallet initialized'
=/ file
[%file-server-action !>([%serve-dir /'~btc' /app/btc-wallet %.n %.y])]
=/ tile
:- %launch-action
!> :+ %add
%btc-wallet
[[%custom `'/~btc' `'/~btc/img/tile.svg'] %.y]
=/ warning [%settings-event !>([%put-entry %btc-wallet %warning %b %.y])]
=/ currency
[%settings-event !>([%put-entry %btc-wallet %currency %s 'USD'])]
:- :~ [%pass /btc-wallet-server %agent [our.bowl %file-server] %poke file]
[%pass /btc-wallet-tile %agent [our.bowl %launch] %poke tile]
[%pass /warn %agent [our.bowl %settings-store] %poke warning]
[%pass /warn %agent [our.bowl %settings-store] %poke currency]
==
::
=/ warning=event:settings [%put-entry %btc-wallet %warning %b %.y]
=/ currency=event:settings [%put-entry %btc-wallet %currency %s 'USD']
=/ cards=(list card)
:~ (poke-our:hc %settings-store %settings-event !>(warning))
(poke-our:hc %settings-store %settings-event !>(currency))
==
::
=/ has-file=? (gall-scry:hc ? %file-server /url/'~btc'/noun)
=/ has-tile=?
(~(has in (gall-scry:hc (set @tas) %launch /keys/noun)) %btc-wallet)
=? cards !has-file
=/ file=action:file-server [%serve-dir /'~btc' /app/btc-wallet %.n %.y]
:_ cards
(poke-our:hc %file-server %file-server-action !>(file))
=? cards !has-tile
=/ tile=action:launch-store
[%add %btc-wallet [%custom `'/~btc' `'/~btc/img/tile.svg'] %.y]
:_ cards
(poke-our:hc %launch %launch-action !>(tile))
::
:- cards
%_ this
state
:* %1
@ -203,7 +210,8 @@
[(silt (gulf 0 endpoint)) endpoint %.n]
=^ cards0 state (req-scan:hc b xpub %0)
=^ cards1 state (req-scan:hc b xpub %1)
[(weld cards0 cards1) state]
:_ state
[(scan-progress:hc xpub) (weld cards0 cards1)]
--
::
%delete-wallet
@ -595,7 +603,7 @@
(turn inputs.ti |=(i=val:tx [i `payer]))
%+ turn outputs.ti
|= o=val:tx
?: =(pos.o vout)
?: =(pos.o vout)
:: check whether this is the output that went to payee
[o payee]
[o `payer]
@ -957,7 +965,8 @@
(bump-batch xpub %0)
=^ cards1=(list card) state
(bump-batch xpub %1)
[(weld cards0 cards1) state]
:_ state
[(scan-progress:hc xpub) (weld cards0 cards1)]
::
:: delete the xpub from scans and set wallet to scanned
::
@ -970,7 +979,9 @@
walts (~(put by walts) xpub w(scanned %.y))
==
%- (slog ~[leaf+"Scanned xpub {<xpub>}"])
(set-curr-xpub:hc xpub)
=^ cards state
(set-curr-xpub:hc xpub)
[[(give-update:hc [%scan-progress ~ ~]) cards] state]
::
:: +bump-batch
:: if the batch is done but the wallet isn't done scanning,
@ -1201,11 +1212,31 @@
%btc-wallet-internal !>(intr)
==
::
++ poke-our
|= [app=term =cage]
^- card
[%pass / %agent [our.bowl app] %poke cage]
::
++ give-update
|= upd=update
^- card
[%give %fact ~[/all] %btc-wallet-update !>(upd)]
::
++ 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
--
::
++ watch-provider
|= who=@p
^- card
@ -1287,4 +1318,8 @@
|= [=xpub:bc w=walt]
^- (unit xpub:bc)
?:(scanned.w `xpub ~)
::
++ gall-scry
|* [=mold app=@tas =path]
.^(mold %gx (weld /(scot %p our.bowl)/[app]/(scot %da now.bowl) path))
--

View File

@ -352,6 +352,10 @@
[%x %clay %base %hash ~]
=/ versions (base-hash:version [our now]:bowl)
``hash+!>(?~(versions 0v0 (end [0 25] i.versions)))
::
[%x %url *]
=/ url t.t.path
``noun+!>((~(has by serving) url))
==
++ on-agent on-agent:def
++ on-fail on-fail:def

View File

@ -110,6 +110,7 @@
%cancel-tx (hexb txid.upd)
%new-address (address address.upd)
%balance (balance balance.upd)
%scan-progress (scan-progress main.upd change.upd)
%error s+error.upd
%broadcast-success ~
==
@ -161,6 +162,19 @@
unconfirmed+(numb q.u.b)
==
::
++ scan-progress
|= [main=(unit idx:bitcoin) change=(unit idx:bitcoin)]
|^ ^- json
%- pairs
:~ main+(from-unit main)
change+(from-unit change)
==
++ from-unit
|= i=(unit idx:bitcoin)
?~ i ~
(numb u.i)
--
::
++ btc-state
|= bs=btc-state:btc-wallet
^- json

View File

@ -162,6 +162,10 @@
[%new-address =address]
[%balance balance=(unit [confirmed=sats unconfirmed=sats])]
[%error =error]
:: current index being scanned in each wallet part
:: ~ if scan of that part is done
::
[%scan-progress main=(unit idx) change=(unit idx)]
==
::
--