mirror of
https://github.com/urbit/shrub.git
synced 2024-12-24 11:24:21 +03:00
wh types refactor
This commit is contained in:
parent
ecd1dcb7a4
commit
57a3d2cef9
@ -24,7 +24,9 @@
|
||||
$: %0
|
||||
provider=(unit [host=ship connected=?])
|
||||
=btc-state
|
||||
pend=back
|
||||
def-wallet=(unit xpub)
|
||||
padr=pend-addr
|
||||
ptxb=pend-txbu
|
||||
==
|
||||
::
|
||||
+$ card card:agent:gall
|
||||
@ -110,11 +112,24 @@
|
||||
sub-card
|
||||
==
|
||||
::
|
||||
%pay
|
||||
%set-default-wallet
|
||||
=/ xs=(list xpub) scry-scanned
|
||||
?. (gth (lent xs) 0) `state
|
||||
`state(def-wallet `(snag 0 xs))
|
||||
::
|
||||
%req-pay-address
|
||||
:: TODO: gen-address in wallet-store
|
||||
:: handle response in on-agent-> wallet-store update
|
||||
:: TODO: check whether default-wallet has a value
|
||||
?~ def-wallet ~& >>> "no default wallet" `state
|
||||
:- ~[(poke-wallet-store [%generate-address u.def-wallet %0])]
|
||||
state
|
||||
::
|
||||
%pay-address
|
||||
`state
|
||||
::
|
||||
%force-retry
|
||||
[(retry pend) state]
|
||||
[(retry padr) state]
|
||||
==
|
||||
:: if status is %connected, retry all pending address lookups
|
||||
::
|
||||
@ -126,7 +141,7 @@
|
||||
?- -.s
|
||||
%connected
|
||||
:: only retry if previously disconnected
|
||||
:- ?:(connected.u.provider ~ (retry pend))
|
||||
:- ?:(connected.u.provider ~ (retry padr))
|
||||
%= state
|
||||
provider `[host.u.provider %.y]
|
||||
btc-state [blockcount.s fee.s now.bowl]
|
||||
@ -137,26 +152,19 @@
|
||||
::
|
||||
++ handle-provider-update
|
||||
|= =update:bp
|
||||
|^ ^- (quip card _state)
|
||||
^- (quip card _state)
|
||||
?. ?=(%& -.update) `state
|
||||
?- -.body.p.update
|
||||
%address-info
|
||||
=/ ureq (~(get by pend) req-id.p.update)
|
||||
=/ ureq (~(get by padr) req-id.p.update)
|
||||
?~ ureq `state
|
||||
:_ state(pend (~(del by pend) req-id.p.update))
|
||||
:~ %- poke-store
|
||||
:_ state(padr (~(del by padr) req-id.p.update))
|
||||
:~ %- poke-wallet-store
|
||||
:* %address-info xpub.u.ureq chyg.u.ureq idx.u.ureq
|
||||
utxos.body.p.update used.body.p.update blockcount.body.p.update
|
||||
==
|
||||
==
|
||||
==
|
||||
++ poke-store
|
||||
|= act=action:bws ^- card
|
||||
:* %pass /[(scot %da now.bowl)] %agent
|
||||
[our.bowl %btc-wallet-store] %poke
|
||||
%btc-wallet-store-action !>(act)
|
||||
==
|
||||
--
|
||||
::
|
||||
++ handle-request
|
||||
|= req=request:bws
|
||||
@ -164,7 +172,7 @@
|
||||
?- -.req
|
||||
%scan-address
|
||||
=/ ri=req-id:bp (mk-req-id (hash-xpub:bwsl +>.req))
|
||||
:_ state(pend (~(put by pend) ri req))
|
||||
:_ state(padr (~(put by padr) ri req))
|
||||
?~ provider ~
|
||||
?: provider-connected
|
||||
~[(get-address-info ri host.u.provider a.req)]
|
||||
@ -173,10 +181,10 @@
|
||||
==
|
||||
::
|
||||
++ retry
|
||||
|= =back
|
||||
|= p=pend-addr
|
||||
^- (list card)
|
||||
?~ provider ~|("provider not set" !!)
|
||||
%+ turn ~(tap by back)
|
||||
%+ turn ~(tap by p)
|
||||
|= [ri=req-id:bp req=request:bws]
|
||||
(get-address-info ri host.u.provider a.req)
|
||||
::
|
||||
@ -192,4 +200,21 @@
|
||||
^- ?
|
||||
?~ provider %.n
|
||||
connected.u.provider
|
||||
::
|
||||
++ poke-wallet-store
|
||||
|= act=action:bws ^- card
|
||||
:* %pass /[(scot %da now.bowl)] %agent
|
||||
[our.bowl %btc-wallet-store] %poke
|
||||
%btc-wallet-store-action !>(act)
|
||||
==
|
||||
::
|
||||
++ scry-scanned
|
||||
.^ (list xpub)
|
||||
%gx
|
||||
(scot %p our.bowl)
|
||||
%btc-wallet-store
|
||||
(scot %da now.bowl)
|
||||
%scanned
|
||||
%noun
|
||||
==
|
||||
--
|
||||
|
@ -102,7 +102,7 @@
|
||||
=. walts (~(put by walts) xpub.act w)
|
||||
(init-batches xpub.act (dec max-gap.w))
|
||||
::
|
||||
%address-info
|
||||
%address-info
|
||||
(update-address +.act)
|
||||
::
|
||||
%generate-address
|
||||
|
@ -1,26 +1,37 @@
|
||||
/- *btc, bws=btc-wallet-store, bp=btc-provider
|
||||
|%
|
||||
:: req-id: hash of [xpub chyg idx]
|
||||
:: back: lookup table of req-id -> requests from wallet-store
|
||||
:: piym: incoming payments
|
||||
:: pend: lookup of req-id -> requests from wallet-store
|
||||
:: pend-txbu: lookup req-id -> txbu (to fetch and assoc raw-tx info with txid)
|
||||
::
|
||||
:: payment: a payment expected from another ship
|
||||
:: - address: address generated for this payment
|
||||
:: txbu: tx builder -- all information needed to make a transaction for signing
|
||||
:: piym: incoming payments. Stores all ship moons inside
|
||||
:: poym: outgoing payments
|
||||
:: piym-watch/poym-watch:
|
||||
:: let us link an address back to its incoming/outgoing payment
|
||||
::
|
||||
+$ btc-state [blockcount=@ud fee=sats t=@da]
|
||||
+$ back (map req-id:bp request:bws)
|
||||
+$ payment [=address payer=ship amount=sats]
|
||||
+$ pend-addr (map req-id:bp request:bws)
|
||||
+$ pend-txbu (map req-id:bp ship)
|
||||
::
|
||||
+$ payment [=address payer=ship value=sats]
|
||||
+$ key [=bipt =chyg:bws =idx:bws]
|
||||
+$ txin [=utxo raw-tx=byts =key]
|
||||
+$ txout [=address value=sats]
|
||||
+$ txbu [txins=(list txin) txouts=(list txout)]
|
||||
::
|
||||
+$ piym (jar ship payment)
|
||||
+$ poym (jar ship txin)
|
||||
+$ poym (map ship txbu)
|
||||
+$ piym-watch (map address ship)
|
||||
+$ poym-watch (map address ship)
|
||||
::
|
||||
+$ action
|
||||
$% [%set-provider provider=ship]
|
||||
[%pay payee=ship amount=sats]
|
||||
[%set-default-wallet ~]
|
||||
[%req-pay-address payee=ship value=sats]
|
||||
[%pay-address payer=ship value=sats =address]
|
||||
[%force-retry ~]
|
||||
==
|
||||
--
|
||||
|
Loading…
Reference in New Issue
Block a user