diff --git a/app/btc-provider.hoon b/app/btc-provider.hoon index 16c5d19611..2253436cb0 100644 --- a/app/btc-provider.hoon +++ b/app/btc-provider.hoon @@ -172,9 +172,6 @@ :: %broadcast-tx [%broadcast-tx rawtx.act] - :: - %ping - [%get-block-info ~] == [~[(req-card act ract)] state] :: diff --git a/app/btc-wallet.hoon b/app/btc-wallet.hoon index 2d4d4c7767..43b671f656 100644 --- a/app/btc-wallet.hoon +++ b/app/btc-wallet.hoon @@ -173,7 +173,7 @@ :: :: overwrites any payment being built in poym :: - %req-pay-address + %init-payment ~| "Can't pay ourselves; no comets; can't do while tx is being signed" ?< =(src.bowl payee.comm) ?< ?=(%pawn (clan:title payee.comm)) @@ -217,7 +217,7 @@ =. state state(num-fam.piym (~(put by num-fam.piym) f +(n))) =^ a=address state (generate-address u.curr-xpub %0) - :- ~[(poke-peer src.bowl [%recv-pay-address a value.act])] + :- ~[(poke-peer 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])) :: ++ generate-address @@ -237,10 +237,10 @@ ?^ pend.u.p ~|("%gen-address: {} already has pending payment to us" !!) =+ newp=u.p(value value.act) :_ state(ps.piym (~(put by ps.piym) payer newp)) - ~[(poke-peer payer [%recv-pay-address address.newp value.act])] + ~[(poke-peer payer [%give-pay-address address.newp value.act])] -- :: - %recv-pay-address + %give-pay-address ?: =(src.bowl our.bowl) ~|("Can't pay ourselves" !!) ?: is-broadcasting ~|("Broadcasting a transaction" !!) ?~ curr-xpub ~|("btc-wallet-hook: no curr-xpub set" !!) @@ -293,6 +293,15 @@ ?& =(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) + == -- == :: @@ -301,6 +310,7 @@ ^- (quip card _state) ?- -.intr %add-poym-raw-txi + |^ ?> =(src.bowl our.bowl) ?~ poym `state =. txis.u.poym @@ -313,6 +323,18 @@ ~& >> "{} vbytes, {<(div fee vb)>} sats/byte, {} sats fee" %- (slog [%leaf "PSBT: {}"]~) ~ + :: 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)) + -- :: delete an incoming/outgoing payment when we see it included in a tx :: %close-pym @@ -491,6 +513,7 @@ ?: ?|(?!(connected.p) (lth block.btc-state block)) ;: weld (retry-pend-piym network) + (retry-poym network) (retry-addrs network) (retry-txs network) (retry-scans network) @@ -769,34 +792,6 @@ [(weld cards0 cards1) state] :: :: - -:: +update-pend.piym -:: - set pend.payment to txid (lock) -:: - add txid to pend.piym -:: -++ 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) - == -:: -:: +update-poym-txis: -:: update outgoing payment with a rawtx, if the txid is in poym's txis -:: -++ update-poym-txis - |= [txis=(list txi) txid=hexb rt=hexb] - ^- (list txi) - =| i=@ - |- ?: (gte i (lent txis)) txis - =/ ith=txi (snag i txis) - =? txis =(txid txid.utxo.ith) - (snap txis i `txi`ith(ur `rt)) - $(i +(i)) -:: -:: :: ++ poke-provider |= [act=action:bp] diff --git a/lib/btc.hoon b/lib/btc.hoon index 9f84c1d29b..db99e2f8f0 100644 --- a/lib/btc.hoon +++ b/lib/btc.hoon @@ -151,8 +151,8 @@ =/ ins=(list in:psbt:bc) %+ murn txis.t |= =txi - ?~ ur.txi ~ - `[utxo.txi u.ur.txi hdkey.txi] + ?~ rawtx.txi ~ + `[utxo.txi u.rawtx.txi hdkey.txi] ?: (lth (lent ins) (lent txis.t)) ~ =/ outs=(list out:psbt:bc) diff --git a/sur/btc-provider.hoon b/sur/btc-provider.hoon index a5c7ed46fc..3b723773e1 100644 --- a/sur/btc-provider.hoon +++ b/sur/btc-provider.hoon @@ -31,9 +31,7 @@ [%raw-tx txid=hexb] [%broadcast-tx rawtx=hexb] [%ping ~] - check-network == -+$ check-network [%check-network =network] :: +$ result $% [%address-info =address utxos=(set utxo) used=? block=@ud] diff --git a/sur/btc-wallet.hoon b/sur/btc-wallet.hoon index 07e7511bd5..0b222591da 100644 --- a/sur/btc-wallet.hoon +++ b/sur/btc-wallet.hoon @@ -16,14 +16,14 @@ [%set-current-wallet =xpub] [%add-wallet =xpub =fprint scan-to=(unit scon) max-gap=(unit @ud) confs=(unit @ud)] [%delete-wallet =xpub] - [%req-pay-address payee=ship value=sats feyb=sats] + [%init-payment payee=ship value=sats feyb=sats] [%broadcast-tx txhex=cord] == :: action: how peers poke us :: +$ action $% [%gen-pay-address value=sats] - [%recv-pay-address =address value=sats] + [%give-pay-address =address value=sats] [%expect-payment =txid value=sats] == :: internal: actions that simply make the state machine more explicit @@ -88,7 +88,7 @@ :: +$ insel [=utxo =chyg =idx] +$ feyb sats -+$ txi [=utxo ur=(unit hexb) =hdkey] ++$ txi [=utxo rawtx=(unit hexb) =hdkey] +$ txo [=address value=sats hk=(unit hdkey)] +$ txbu $: =xpub