WIP: handle %generate-txbu

This commit is contained in:
timlucmiptev 2020-11-19 17:54:01 +02:00 committed by ixv
parent e4f3c6bf9a
commit 36dcca24a7
5 changed files with 23 additions and 19 deletions

View File

@ -21,6 +21,7 @@
++ def-moon-limit 10
:: provider: maybe ship if provider is set
:: moon-limit: how many addresses a ship and its moons can request in piym
:: piym/poym-watch: listen to btc-wallet-store for address updates; update payment info
::
+$ state-0
$: %0
@ -146,7 +147,7 @@
?> =(payer.act our.bowl)
:_ state
:~ %- poke-wallet-store
[%generate-txbu u.def-wallet fee.btc-state ~[[address.act value.act]]]
[%generate-txbu u.def-wallet `src.bowl fee.btc-state ~[[address.act value.act]]]
==
::
%force-retry
@ -206,7 +207,7 @@
^- (quip card _state)
?- -.upd
%generate-address
:: if no meta (payer/value), just prints address
:: if no meta (payer/value), just prints address
::
?~ meta.upd ~&(> address.upd `state)
=/ [payer=ship value=sats] u.meta.upd
@ -216,7 +217,9 @@
%generate-txbu
:: TODO: add the txbu to poym
:: send all its input tx-ids out for feedback
`state
:_ ?~ payee.upd state
state(poym (~(put by poym) u.payee.upd txbu.upd))
~
::
%scan-done
?~ def-wallet

View File

@ -124,12 +124,12 @@
%generate-txbu
=/ uw=(unit walt) (~(get by walts) xpub.act)
?~ uw ~&(>>> "btc-wallet-store: non-existent xpub" `state)
=/ r=(unit [=vbytes:btc =txbu])
=/ r=(unit txbu)
%~ select-utxos sut
[u.uw eny.bowl +>.act]
[u.uw eny.bowl feyb.act txos.act]
?~ r ~&(>>> "btc-wallet-store: insufficient balance" `state)
:_ state
~[(send-update [%generate-txbu xpub.act u.r])]
~[(send-update [%generate-txbu xpub.act payee.act u.r])]
==
:: wallet scan algorithm:
:: Initiate a batch for each chyg, with max-gap idxs in it

View File

@ -127,24 +127,25 @@
(sub val cost)
:: Uses naive random selection. Should switch to branch-and-bound later.
::
++ inputs-to-txbu
|= is=(list input) ^- txbu
:_ txos
%+ turn is
|=(i=input [utxo.i ~ [bipt.w chyg.i idx.i]])
::
++ select-utxos
|^ ^- (unit [=vbytes =txbu])
|^ ^- (unit =txbu)
=/ uis=(unit (list input))
%- single-random-draw
%- zing
(turn ~(val by wach.w) to-inputs)
?~ uis ~
`[(total-vbytes u.uis) (inputs-to-txbu u.uis)]
?~(uis ~ `(inputs-to-txbu u.uis))
::
++ to-inputs
|= =addi ^- (list input)
%+ turn ~(tap in utxos.addi)
|=(=utxo:btc [utxo chyg.addi idx.addi])
++ inputs-to-txbu
|= is=(list input) ^- txbu
:* (total-vbytes is)
%+ turn is
|=(i=input [utxo.i ~ [bipt.w chyg.i idx.i]])
txos
==
--
:: single-random-draw
:: randomly choose utxos until target is hit

View File

@ -9,7 +9,7 @@
:: 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
:: let us link an address back to its incoming/outgoing payment
::
+$ btc-state [blockcount=@ud fee=sats t=@da]
+$ pend-addr (map req-id:bp request:bws)

View File

@ -50,7 +50,7 @@
+$ key [=bipt =chyg =idx]
+$ txi [=utxo raw-tx=(unit buffer) =key]
+$ txo [=address value=sats]
+$ txbu [txis=(list txi) txos=(list txo)]
+$ txbu [=vbytes txis=(list txi) txos=(list txo)]
:: TODO: document
::
+$ batch [todo=(set idx) endpoint=idx has-used=?]
@ -66,12 +66,12 @@
$% [%add-wallet =xpub scan-to=(unit scon) max-gap=(unit @ud) confs=(unit @ud)]
[%address-info =xpub =chyg =idx utxos=(set utxo) used=? blockcount=@ud]
[%generate-address =xpub =chyg meta=(unit [payer=ship value=sats])]
[%generate-txbu =xpub feyb=sats txos=(list txo)]
[%generate-txbu =xpub payee=(unit ship) feyb=sats txos=(list txo)]
==
::
+$ update
$% [%generate-address =address meta=(unit [payer=ship value=sats])]
[%generate-txbu =xpub =vbytes =txbu]
[%generate-txbu =xpub payee=(unit ship) =txbu]
[%scan-done =xpub]
==
::