diff --git a/MOON_INSTALL.md b/MOON_INSTALL.md index 6cd73d6301..79244eceb3 100644 --- a/MOON_INSTALL.md +++ b/MOON_INSTALL.md @@ -63,13 +63,13 @@ Install files: :btc-wallet-hook|action [%set-provider moon1] =xpub2 'zpub6r8dKyWJ31XF6n69KKeEwLjVC5ruqAbiJ4QCqLsrV36Mvx9WEjUaiPNPGFLHNCCqgCdy6iZC8ZgHsm6a1AUTVBMVbKGemNcWFcwBGSjJKbD' =fprint [%4 0xbeef.dead] -:btc-wallet-store|action [%add-wallet xpub2 fprint ~ [~ 8] [~ 6]] +:btc-wallet-store|action [%add-wallet xpub2 fprint ~ [~ 8] [~ 1]] ``` ### Request Address Moon2: ``` -:btc-wallet-hook|action [%req-pay-address payee=moon1 value=2.000 [~ 30]] +:btc-wallet-hook|action [%req-pay-address payee=~sarsev-dapwel-timluc-miptev value=10.000 [~ 37]] :btc-wallet-hook +dbug [%state 'poym'] ``` diff --git a/app/btc-provider.hoon b/app/btc-provider.hoon index 5b446709ea..7683a9dff4 100644 --- a/app/btc-provider.hoon +++ b/app/btc-provider.hoon @@ -31,7 +31,7 @@ ++ on-init ^- (quip card _this) ~& > '%btc-provider initialized successfully' - `this(host-info ['' connected=%.n clients=*(set ship)], whitelist *(set ship)) + `this(host-info ['' connected=%.n block=0 clients=*(set ship)], whitelist *(set ship)) ++ on-save ^- vase !>(state) @@ -77,7 +77,7 @@ =^ cards state ?+ +<.sign-arvo (on-arvo:def wire sign-arvo) %http-response - (handle-rpc-response:hc wire client-response.sign-arvo) + (handle-rpc-response:hc wire client-response.sign-arvo) == [cards this] :: @@ -91,7 +91,7 @@ ?- -.comm %set-credentials :- do-ping - state(host-info [api-url.comm connected=%.n clients=*(set ship)]) + state(host-info [api-url.comm connected=%.n block=0 clients=*(set ship)]) :: %whitelist-clients `state(whitelist (~(uni in whitelist) clients.comm)) @@ -119,7 +119,7 @@ [%broadcast-tx rawtx.act] :: %ping - [%get-block-and-fee ~] + [%get-block-info ~] == [~[(req-card act ract)] state] :: @@ -197,9 +197,11 @@ ~[(send-update [%.y %broadcast-tx +.r])] :: %ping - ?> ?=([%get-block-and-fee *] r) - :- ~[(send-status [%connected block.r fee.r])] - state(connected.host-info %.y) + ?> ?=([%get-block-info *] r) + :_ state(connected.host-info %.y, block.host-info block.r) + ?: =(block.host-info block.r) + ~[(send-status [%connected block.r fee.r])] + ~[(send-status [%new-block block.r fee.r blockhash.r blockfilter.r])] == :: ++ send-status diff --git a/app/btc-wallet-hook.hoon b/app/btc-wallet-hook.hoon index 8e135998e0..c47771f320 100644 --- a/app/btc-wallet-hook.hoon +++ b/app/btc-wallet-hook.hoon @@ -31,7 +31,7 @@ :: +$ state-0 $: %0 - prov=(unit [host=ship connected=?]) + prov=(unit provider) =reqs =btc-state def-wallet=(unit xpub) @@ -310,27 +310,44 @@ ++ handle-provider-status |= s=status:bp ^- (quip card _state) + |^ ?~ prov `state ?. =(host.u.prov src.bowl) `state ?- -.s + %new-block + ~& >> "%new-block" + (connected u.prov block.s fee.s `blockhash.s `blockfilter.s) + :: %connected - :_ %= state - prov `[host.u.prov %.y] - btc-state [block.s fee.s now.bowl] - == - ?: ?!(connected.u.prov) - %- zing - :~ (retry-reqs block.s) - retry-poym - retry-pend-piym - == - ?. (lth block.btc-state block.s) - retry-pend-piym - (weld retry-pend-piym (retry-reqs block.s)) + ~& >> "%connected" + (connected u.prov block.s fee.s ~ ~) :: %disconnected `state(prov `[host.u.prov %.n]) == + :: + ++ connected + |= $: p=provider + block=@ud + fee=sats + blockhash=(unit bytc) + blockfilter=(unit bytc) + == + ^- (quip card _state) + :_ %_ state + prov `[host.p %.y] + btc-state [block fee now.bowl] + == + ?: ?!(connected.p) + %- zing + :~ (retry-reqs block) + retry-poym + retry-pend-piym + == + ?. (lth block.btc-state block) + retry-pend-piym + (weld retry-pend-piym (retry-reqs block)) + -- :: ++ handle-provider-update |= upd=update:bp diff --git a/lib/btc-provider.hoon b/lib/btc-provider.hoon index f0b78140c1..cba35e2331 100644 --- a/lib/btc-provider.hoon +++ b/lib/btc-provider.hoon @@ -108,8 +108,8 @@ %get-block-count [id.res (ni:dejs:format res.res)] :: - %get-block-and-fee - [id.res (block-and-fee res.res)] + %get-block-info + [id.res (block-info res.res)] == ++ address-info %- ot:dejs:format @@ -126,7 +126,7 @@ [%value ni:dejs:format] [%recvd (cu:dejs:format from-epoch ni:dejs:format)] == - ++ tx-vals + ++ tx-vals %- ot:dejs:format :~ [%included bo:dejs:format] [%txid (cu:dejs:format to-hash256 so:dejs:format)] @@ -153,10 +153,12 @@ [%broadcast bo:dejs:format] [%included bo:dejs:format] == - ++ block-and-fee + ++ block-info %- ot:dejs:format :~ [%block ni:dejs:format] [%fee ni:dejs:format] + [%blockhash (cu:dejs:format to-bytc so:dejs:format)] + [%blockfilter (cu:dejs:format to-bytc so:dejs:format)] == -- -- @@ -189,9 +191,9 @@ %- get-request (mk-url '/getblockcount' '') :: - %get-block-and-fee + %get-block-info %- get-request - (mk-url '/getblockandfee' '') + (mk-url '/getblockinfo' '') == ++ mk-url |= [base=@t params=@t] diff --git a/lib/btc-wallet-store.hoon b/lib/btc-wallet-store.hoon index b7f8946792..5694dc5bdb 100644 --- a/lib/btc-wallet-store.hoon +++ b/lib/btc-wallet-store.hoon @@ -75,8 +75,8 @@ == ++ txo-data |= =txo - :* (script-pubkey:btc address.txo) - value.txo + :- (script-pubkey:btc address.txo) + value.txo -- :: ++ fee @@ -134,8 +134,8 @@ |= =idx:btc ^- address:btc ?: ?=(%84 bipt.w) - (need (encode-pubkey:bech32:btc %main dat:(pubkey idx))) - ~|("legacy addresses not supported yet " !!) + (need (encode-pubkey:bech32:btc %main (pubkey idx))) + ~|("base58 addresses not supported yet " !!) :: +nixt-address: used to get change addresses :: - gets the current next available address :: - doesn't bump nixt-address if it's unused diff --git a/sur/btc-provider.hoon b/sur/btc-provider.hoon index 1c22e16146..a7b772c129 100644 --- a/sur/btc-provider.hoon +++ b/sur/btc-provider.hoon @@ -1,6 +1,11 @@ /- *btc |% -+$ host-info [api-url=@t connected=? clients=(set ship)] ++$ host-info + $: api-url=@t + connected=? + block=@ud + clients=(set ship) + == +$ command $% [%set-credentials api-url=@t] [%whitelist-clients clients=(set ship)] @@ -26,7 +31,8 @@ == +$ update (each result error) +$ status - $% [%connected block=@ud fee=@ud] + $% [%connected block=@ud fee=sats] + [%new-block block=@ud fee=sats blockhash=bytc blockfilter=bytc] [%disconnected ~] == :: @@ -38,7 +44,7 @@ [%get-raw-tx =txid] [%broadcast-tx =rawtx] [%get-block-count ~] - [%get-block-and-fee ~] + [%get-block-info ~] == :: +$ result @@ -48,7 +54,7 @@ [%create-raw-tx =rawtx] [%broadcast-tx =txid broadcast=? included=?] [%get-block-count block=@ud] - [%get-block-and-fee block=@ud fee=sats] + [%get-block-info block=@ud fee=sats blockhash=bytc blockfilter=bytc] == -- diff --git a/sur/btc-wallet-hook.hoon b/sur/btc-wallet-hook.hoon index 2f40c7a528..2c8889ea2f 100644 --- a/sur/btc-wallet-hook.hoon +++ b/sur/btc-wallet-hook.hoon @@ -11,6 +11,7 @@ :: pend-piym: incoming payment txs that peer says they have broadcast :: poym: outgoing payments. One at a time: new replaces old :: ++$ provider [host=ship connected=?] +$ block @ud +$ btc-state [=block fee=sats t=@da] +$ reqs (map $?(address txid) request:bws)