fix CRITICAL bug with rawtx byt length

This commit is contained in:
timlucmiptev 2020-12-10 17:54:39 +02:00 committed by ixv
parent 55a9728c80
commit 83167a93d1
5 changed files with 61 additions and 35 deletions

View File

@ -12,8 +12,8 @@
:: Sends updates to:
:: /sign-me
::
/- *btc, *btc-wallet-hook, bws=btc-wallet-store
/+ dbug, default-agent, bp=btc-provider
/- *btc-wallet-hook, bws=btc-wallet-store
/+ dbug, default-agent, bp=btc-provider, bwsl=btc-wallet-store, *btc
|%
++ defaults
|%
@ -300,7 +300,11 @@
?~ poym `state
=. txis.u.poym (update-poym-txis txis.u.poym txid.rt rawtx.rt)
:_ state
?:(poym-ready ~[(send-sign-tx u.poym)] ~)
=+ pb=~(to-psbt txb:bwsl u.poym)
?~ pb ~
~& > "PSBT ready:"
~& >> u.pb
~[(send-sign-tx u.poym)]
==
:: get address-info for the request if block in request is old
::
@ -344,7 +348,6 @@
:: - request provider to create-raw-tx from txbu
::
%generate-txbu
:: TODO make tx info fetch correctly
:_ state(poym `txbu.upd)
?~ provider ~&(>>> "provider not set" ~)
%+ weld ~[(create-raw-tx host.u.provider txbu.upd)]
@ -440,17 +443,6 @@
=? txis =(txid txid.utxo.ith)
(snap txis i `txi:bws`ith(ur `rt))
$(i +(i))
:: +poym-ready: whether poym txbu is ready to sign
:: - is the txinfo filled in?
:: - do all txis in poym have rawtxs?
::
++ poym-ready
^- ?
?~ poym %.n
?& ?=(^ txinfo.u.poym)
%+ levy txis.u.poym
|=(t=txi:bws ?=(^ ur.t))
==
:: +retry-reqs: get-address-info for any reqs with old last-block
::
++ retry-reqs
@ -533,8 +525,6 @@
++ send-sign-tx
|= =txbu:bws
^- card
~& >> "transaction ready to sign"
~& > txinfo.txbu
[%give %fact ~[/sign-me] %btc-wallet-hook-request !>([%sign-tx txbu])]
::
++ poke-wallet-store

View File

@ -56,7 +56,8 @@
++ to-bytc
|= h=@t
^- bytc
[(lent (trip h)) (to-hex h)]
:- (div (lent (trip h)) 2)
(to-hex h)
::
++ get-request
|= url=@t

View File

@ -52,14 +52,29 @@
|= =txo
^- txbu
t(txos [txo txos.t])
:: +to-psbt: returns a based 64 PSBT if
:: - txinfo is present
:: - all inputs have an associated rawtx
::
++ to-psbt
|= w=walt
^- cord
''
:: TODO
:: for each txi, get the pubkey from the hdkey
:: get a list of map:psbt:btc
^- (unit (list bytc))
:: ^- (unit base64:psbt:btc)
?~ txinfo.t ~
=/ ins=(list in:psbt:btc)
%+ murn txis.t
|= =txi
?~ ur.txi ~
`[utxo.txi u.ur.txi hdkey.txi]
?: (lth (lent ins) (lent txis.t))
~
=/ outs=(list out:psbt:btc)
%+ turn txos.t
|=(=txo [address.txo hk.txo])
:- ~
%: encode:pbt:btc
rawtx.u.txinfo.t txid.u.txinfo.t
ins outs
==
--
:: wad: door for processing walts (wallets)
:: parameterized on a walt and it's chyg account

View File

@ -110,22 +110,41 @@
==
(flip:byt [(met 3 idx.h) idx.h])
==
::
++ keyval-byts
|= kv=keyval:psbt
^- bytc
%- cat:byt
:~ 1^wid.key.kv
key.kv
1^wid.val.kv
val.kv
==
::
++ map-byts
|= m=map:psbt
^- (unit bytc)
?~ m ~
:- ~
%- cat:byt
(turn m keyval-byts)
--
:: +encode: make base64 cord of PSBT
::
++ encode
|= [=rawtx =txid inputs=(list in:psbt) outputs=(list out:psbt)]
^- cord
:: (globals rawtx)
:: TODO
:: make global map
:: raw tx hex
:: turn each input and output into a map (or ~)
:: put the 0x0 separator between all
:: parse to hex
:: encode as base64!
*cord
:: ^- cord
^- (list bytc)
=/ final=(list (unit bytc))
%+ join `(unit bytc)`[~ 1^0x0]
%+ turn
%- zing
:~ ~[(globals:en rawtx)]
(turn inputs input:en)
(turn outputs output:en)
==
map-byts:en
(murn final same)
::
++ parse
|= psbt-base64=cord

View File

@ -61,6 +61,7 @@
--
++ psbt
|%
+$ base64 cord
+$ in [=utxo =rawtx =hdkey]
+$ out [=address hk=(unit hdkey)]
+$ target $?(%input %output)