From 663aacbc234ba0e5d8d1c2830e69f5fe835fa538 Mon Sep 17 00:00:00 2001 From: timlucmiptev Date: Thu, 19 Nov 2020 11:11:02 +0200 Subject: [PATCH] syntax cleanup --- WALLET.scratch.md | 4 ++-- lib/btc-wallet-store.hoon | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/WALLET.scratch.md b/WALLET.scratch.md index da5fb6ce9..3fd20d7ff 100644 --- a/WALLET.scratch.md +++ b/WALLET.scratch.md @@ -86,10 +86,10 @@ Uses `btc-wallet-hook`, with max-gap=3 =eny1 0v3uc.iuebi.5qilc.l8d87.c1k6n.7iksq.nkobs.8s5he.raq40.9ff0b.5tj3u.kjtg7.aq59e.hatv7.oioam.mlsr4.pqqcd.cnbjn.pnpi2.1m5rt.k4scg =eny2 0v1gt.mc4ca.lfs0m.q1dal.lqobu.mmlbd.2umnp.lj9dr.4pf4s.pvclr.dps96.4a6i8.rt6n9.krp0r.11kqu.ckqe4.1tmat.gr754.463aj.a4b41.jj7qg - =inputs ~[[u(value val0) %0 0] [u(value val1) %0 2] [u(value val2) %0 1] [u(value val3) %1 2]] + (~(single-random-draw sut:bwsl [*walt:bwsl eny1 400.100 100 2]) inputs) -(~(single-random-draw sut:bwsl [*walt:bwsl eny2 400.100 100 2]) inputs)(~(single-random-draw sut:bwsl [*walt:bwsl eny2 400.100 100 2]) inputs) +(~(single-random-draw sut:bwsl [*walt:bwsl eny2 400.100 100 2]) inputs) ``` Above tests w 2 outputs, total fees with 2 inputs of 27.500. Gives: diff --git a/lib/btc-wallet-store.hoon b/lib/btc-wallet-store.hoon index dd2cf9e79..26f687256 100644 --- a/lib/btc-wallet-store.hoon +++ b/lib/btc-wallet-store.hoon @@ -114,17 +114,17 @@ %+ add base-weight (mul input-weight (lent selected)) :: value of an input after fee - :: 0 if net is <= 0 + :: 0 if net is <= 0 :: ++ net-value |= val=sats ^- sats =/ cost (mul input-weight feyb) ?: (lte val cost) 0 (sub val cost) - :: Uses naive random selection. Should switch to branch-and-bound later + :: Uses naive random selection. Should switch to branch-and-bound later. :: ++ select-utxos - |^ ^- (unit (list input)) + |^ ^- (unit [=vbytes (list input)]) %- single-random-draw %- zing (turn ~(val by wach.w) to-inputs) @@ -139,19 +139,20 @@ :: ++ single-random-draw |= is=(list input) - ^- (unit (list input)) + ^- (unit [=vbytes (list input)]) =/ rng ~(. og eny) =/ target (add targ (mul feyb base-weight)) :: add base fees to target =| [select=(list input) total=sats:btc] - |- ?~ is ~ + |- ?: =(~ is) ~ =^ n rng (rads:rng (lent is)) - =/ i=input (snag n `(list input)`is) + =/ i=input (snag n is) =/ net-val (net-value value.utxo.i) =? select (gth net-val 0) [i select] :: select if net-value > 0 =/ new-total (add total net-val) - ?: (gte new-total target) `select + ?: (gte new-total target) + `[(total-vbytes select) select] %= $ - is (oust [n 1] `(list input)`is) + is (oust [n 1] is) total new-total == ::