diff --git a/app/btc-wallet-hook.hoon b/app/btc-wallet-hook.hoon index 84c984f57..c195eff0e 100644 --- a/app/btc-wallet-hook.hoon +++ b/app/btc-wallet-hook.hoon @@ -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 diff --git a/lib/btc-provider.hoon b/lib/btc-provider.hoon index 56eabd964..420dfb0bf 100644 --- a/lib/btc-provider.hoon +++ b/lib/btc-provider.hoon @@ -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 diff --git a/lib/btc-wallet-store.hoon b/lib/btc-wallet-store.hoon index a0150f1ab..ae3f82e12 100644 --- a/lib/btc-wallet-store.hoon +++ b/lib/btc-wallet-store.hoon @@ -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 diff --git a/lib/btc.hoon b/lib/btc.hoon index 736a47f3e..36a6f9a70 100644 --- a/lib/btc.hoon +++ b/lib/btc.hoon @@ -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 diff --git a/sur/btc.hoon b/sur/btc.hoon index a049592c5..714172423 100644 --- a/sur/btc.hoon +++ b/sur/btc.hoon @@ -61,6 +61,7 @@ -- ++ psbt |% + +$ base64 cord +$ in [=utxo =rawtx =hdkey] +$ out [=address hk=(unit hdkey)] +$ target $?(%input %output)