From 1d0d26becc50b8e1c4a085d2b706642a345407ff Mon Sep 17 00:00:00 2001 From: timlucmiptev Date: Fri, 12 Feb 2021 21:43:25 +0400 Subject: [PATCH] WIP: still fixing type errors --- app/btc-wallet.hoon | 55 ++++++++++++++++----------------------------- lib/btc-wallet.hoon | 2 +- sur/btc-wallet.hoon | 4 ++-- 3 files changed, 22 insertions(+), 39 deletions(-) diff --git a/app/btc-wallet.hoon b/app/btc-wallet.hoon index fd1cde138..f4fc4330f 100644 --- a/app/btc-wallet.hoon +++ b/app/btc-wallet.hoon @@ -201,7 +201,7 @@ =+ fee=~(fee txb u.poym) ~& >> "{} vbytes, {<(div fee vb)>} sats/byte, {} sats fee" %- (slog [%leaf "PSBT: {}"]~) - ~[(send-update [%sign-tx u.poym])] + ~ :: %close-pym ?> =(src.bowl our.bowl) @@ -218,18 +218,15 @@ :: %fail-broadcast-tx ?> =(src.bowl our.bowl) - ~& > "%fail-broadcast-tx" - :_ state(poym ~) - ~[(send-update [%broadcast-tx-spent-utxos txid.act])] + ~& >>> "%fail-broadcast-tx" + `state(poym ~) :: %succeed-broadcast-tx ?> =(src.bowl our.bowl) ~& > "%succeed-broadcast-tx" - :_ %_ state - reqs (~(put by reqs) txid.act [%tx-info 0 txid.act]) - == + :_ state ?~ prov ~ - :- (poke-provider host.u.prov [%tx-info txid.act]) + :- (poke-provider [%tx-info txid.act]) ?~ poym ~ ?~ payee.u.poym ~ :_ ~ @@ -250,13 +247,11 @@ =^ cards state (reuse-address src.bowl value.act) ?^ cards [cards state] - :: if no reuseable address, call store to generate - :: =+ f=(fam src.bowl) =+ n=(~(gut by num-fam.piym) f 0) ?~ curr-xpub ~|("btc-wallet-hook: no curr-xpub set" !!) - ?: (gte n fam-limit) - ~|("More than {} addresses for moons + planet" !!) + ?: (gte n fam-limit.params) + ~|("More than {} addresses for moons + planet" !!) =. state state(num-fam.piym (~(put by num-fam.piym) f +(n))) =^ addr state (generate-address u.curr-xpub %0 `[src.bowl value.act]) @@ -289,7 +284,7 @@ ?> (piym-matches u.pay) :_ (update-pend-piym txid.act u.pay(pend `txid.act)) ?~ prov ~ - ~[(poke-provider host.u.prov [%tx-info txid.act])] + ~[(poke-provider [%tx-info txid.act])] :: ++ piym-matches |= p=payment @@ -332,7 +327,7 @@ ^- (quip card _state) :_ %_ state prov `[host.p %.y] - btc-state [block fee now.bowl] + btc-state [block fee now.bowl] == ?: ?|(?!(connected.p) (lth block.btc-state block)) ;:(weld retry-pend-piym retry-addrs retry-txs) @@ -422,8 +417,7 @@ ++ handle-address-info |= [=address utxos=(set utxo) used=?] ^- (quip card _state) - |^ - =/ am address-meta + =/ am (address-meta address ~(val by walts)) ?~ am `state =/ [w=walt =chyg =idx] u.am =. walts @@ -434,25 +428,14 @@ :: if the wallet+chyg is being scanned, update the scan batch :: if not, just get more-info for the address if still being scanned :: - =/ b (~(get by scans) [xpub chyg]) + =/ b (~(get by scans) [xpub.w chyg]) ?~ b `state =. scans (del-scanned u.b(has-used ?|(used has-used.u.b)) xpub.w chyg idx) ?: empty:(scan-status xpub.w chyg) - (run-scan xpub.w) + (check-scan xpub.w) `state :: -++ address-meta -^- (unit [walt chyg idx]) -=/ ws=(list walt) ~(val by walts) -|- -?~ ws ~ -=/ res=(unit [chyg idx]) -(address-loc i.ws address) -?^ res [i.ws chyg.u.res idx.u.res] -$(ws t.ws) --- -:: ++ req-scan |= [b=batch =xpub =chyg] ^- (list card) @@ -545,13 +528,13 @@ $(ws t.ws) ^- [(unit txbu) _state] =/ uw (~(get by walts) xpub) ?~ uw - ~|("btc-wallet-store: non-existent xpub" !!) + ~|("btc-wallet: non-existent xpub" !!) ?. scanned.u.uw - ~|("btc-wallet-store: wallet not scanned yet" !!) + ~|("btc-wallet: wallet not scanned yet" !!) =/ [tb=(unit txbu) chng=(unit sats)] %~ with-change sut [u.uw eny.bowl block.btc-state payee feyb txos] - ?~ tb ~&(>>> "btc-wallet-store: insufficient balance" `state) + ?~ tb ~&(>>> "btc-wallet: insufficient balance" `state) :: if no change, return txbu; else add change to txbu :: ?~ chng [tb state] @@ -565,9 +548,9 @@ $(ws t.ws) ^- [address _state] =/ uw=(unit walt) (~(get by walts) xpub) ?~ uw - ~|("btc-wallet-store: non-existent xpub" !!) + ~|("btc-wallet: non-existent xpub" !!) ?. scanned.u.uw - ~|("btc-wallet-store: wallet not scanned yet" !!) + ~|("btc-wallet: wallet not scanned yet" !!) =/ [addr=address:btc =idx w=walt] ~(gen-address wad u.uw chyg) [addr state(walts (~(put by walts) xpub w))] @@ -602,7 +585,7 @@ $(ws t.ws) :: - checks whether the txid matches that signed tx :: - if not, skip :: - clears poym -:: - returns card that adds hest to wallet-store history +:: - returns card that adds hest to history :: ++ poym-to-history |= ti=info:tx @@ -634,7 +617,7 @@ $(ws t.ws) :: - checks whether ti has a matching value output to piym :: - if no match found, just deletes pend-piym with this tx :: stops peer from spamming txids -:: - returns card that adds hest to wallet-store history +:: - returns card that adds hest to history :: ++ piym-to-history |= ti=info:tx diff --git a/lib/btc-wallet.hoon b/lib/btc-wallet.hoon index 4b3d78474..af508ca0e 100644 --- a/lib/btc-wallet.hoon +++ b/lib/btc-wallet.hoon @@ -1,6 +1,6 @@ :: :: -/- *btc-wallet-store +/- *btc-wallet /+ bip32, btc, bp=btc-provider =, secp:crypto =+ ecc=secp256k1 diff --git a/sur/btc-wallet.hoon b/sur/btc-wallet.hoon index 37964ae2a..952a62b43 100644 --- a/sur/btc-wallet.hoon +++ b/sur/btc-wallet.hoon @@ -13,7 +13,7 @@ +$ command $% [%set-provider provider=ship =network] [%set-current-wallet =xpub] - [%add-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] [%broadcast-tx txhex=cord] @@ -21,7 +21,7 @@ +$ action :: local-only actions :: - $: [%close-pym ti=info:tx] + $% [%close-pym ti=info:tx] [%add-poym-raw-txi =txid rawtx=hexb] [%fail-broadcast-tx =txid] [%succeed-broadcast-tx =txid]