%broadcast-tx types work

This commit is contained in:
timlucmiptev 2020-12-13 22:33:08 +02:00 committed by ixv
parent 9eeaa31f4f
commit 8fa6fdb545
5 changed files with 45 additions and 63 deletions

View File

@ -158,20 +158,9 @@
:_ state(connected.host-info %.n) :_ state(connected.host-info %.n)
~[(send-status [%disconnected ~]) (send-update [%| u.conn-err])] ~[(send-status [%disconnected ~]) (send-update [%| u.conn-err])]
:: ::
:: TODO: make sure below works %+ handle-rpc-result wire
=/ resp=response:rpc-types %- parse-result:rpc
%- parse-response:rpc (get-rpc-response response)
(get-rpc-response response)
?- -.resp
%error
(handle-rpc-error wire +.resp)
::
%result
(handle-rpc-result wire +.resp)
::
%unhandled-response
[~[(send-update [%| [%rpc-error ~]])] state]
==
:: ::
++ connection-error ++ connection-error
|= status=@ud |= status=@ud
@ -189,15 +178,6 @@
[`[%not-connected status] state(connected.host-info %.n)] [`[%not-connected status] state(connected.host-info %.n)]
== ==
:: ::
++ handle-rpc-error
|= [=wire e=error:rpc-types]
^- (quip card _state)
?+ e [~[(send-update [%.n [%rpc-error ~]])] state]
%tx-inputs-missing-or-spent
:_ state
~[(send-update [%.y (get-req-id wire) %broadcast-tx %.n %tx-inputs-missing-or-spent])]
==
::
++ handle-rpc-result ++ handle-rpc-result
|= [=wire r=result:rpc-types] |= [=wire r=result:rpc-types]
^- (quip card _state) ^- (quip card _state)
@ -215,17 +195,17 @@
[%raw-tx @ *] [%raw-tx @ *]
?> ?=([%get-raw-tx *] r) ?> ?=([%get-raw-tx *] r)
:_ state :_ state
~[(send-update [%.y (get-req-id wire) %raw-tx +.r])] ~[(send-update [%.y (get-req-id wire) %raw-tx +.r])]
:: ::
[%create-raw-tx @ *] [%create-raw-tx @ *]
?> ?=([%get-raw-tx *] r) ?> ?=([%get-raw-tx *] r)
:_ state :_ state
~[(send-update [%.y (get-req-id wire) %raw-tx +.r])] ~[(send-update [%.y (get-req-id wire) %raw-tx +.r])]
:: ::
[%broadcast-raw-tx @ *] [%broadcast-tx @ *]
?> ?=([%broadcast-tx *] r) ?> ?=([%broadcast-tx *] r)
:_ state :_ state
~[(send-update [%.y (get-req-id wire) %broadcast-tx %.y +.r])] ~[(send-update [%.y (get-req-id wire) %broadcast-tx +.r])]
:: ::
[%ping @ *] [%ping @ *]
?> ?=([%get-block-and-fee *] r) ?> ?=([%get-block-and-fee *] r)

View File

@ -116,26 +116,6 @@
:: ::
++ rpc ++ rpc
|% |%
++ parse-response
|= res=response:json-rpc
^- response:rpc-types
?+ -.res [%unhandled-response ~]
%error
[%error (parse-error res)]
%result
[%result (parse-result res)]
==
::
++ parse-error
|= res=response:json-rpc
^- error:rpc-types
?> ?=(%error -.res)
?: =('-25' code.res)
%tx-inputs-missing-or-spent
?: =('28' code.res)
%blocks-not-ready
%connection-error
::
++ parse-result ++ parse-result
|= res=response:json-rpc |= res=response:json-rpc
|^ ^- result:rpc-types |^ ^- result:rpc-types
@ -155,7 +135,7 @@
[%get-raw-tx (raw-tx res.res)] [%get-raw-tx (raw-tx res.res)]
:: ::
%broadcast-tx %broadcast-tx
[%broadcast-tx ((cu:dejs:format to-hash256 so:dejs:format) res.res)] [%broadcast-tx (broadcast-tx res.res)]
:: ::
%get-block-count %get-block-count
[id.res (ni:dejs:format res.res)] [id.res (ni:dejs:format res.res)]
@ -197,6 +177,12 @@
:~ [%txid (cu:dejs:format to-hash256 so:dejs:format)] :~ [%txid (cu:dejs:format to-hash256 so:dejs:format)]
[%rawtx (cu:dejs:format to-bytc so:dejs:format)] [%rawtx (cu:dejs:format to-bytc so:dejs:format)]
== ==
++ broadcast-tx
%- ot:dejs:format
:~ [%txid (cu:dejs:format to-hash256 so:dejs:format)]
[%broadcast bo:dejs:format]
[%included bo:dejs:format]
==
++ block-and-fee ++ block-and-fee
%- ot:dejs:format %- ot:dejs:format
:~ [%block ni:dejs:format] :~ [%block ni:dejs:format]

View File

@ -53,7 +53,24 @@
?. =(wid.hex 20) ?. =(wid.hex 20)
~|("Only 20-byte addresses supported" !!) ~|("Only 20-byte addresses supported" !!)
(to-script-pubkey (from-byts:buf hex)) (to-script-pubkey (from-byts:buf hex))
:: arms to handle BIP174 PSBTs :: +txu: tx utility functions
++ txu
|%
++ en
|= data:tx
^- bytc
*bytc
++ de
|= b=bytc
^- data:tx
*data:tx
:: TODO parse out signatures
++ get-id
|= b=bytc
^- txid
(dsha256 b)
--
:: core to handle BIP174 PSBTs
:: ::
++ pbt ++ pbt
|% |%

View File

@ -22,7 +22,7 @@
$% [%address-info utxos=(set utxo) used=? block=@ud] $% [%address-info utxos=(set utxo) used=? block=@ud]
[%tx-info =info:tx] [%tx-info =info:tx]
[%raw-tx =txid =rawtx] [%raw-tx =txid =rawtx]
[%broadcast-tx (each txid %tx-inputs-missing-or-spent)] [%broadcast-tx =txid broadcast=? included=?]
== ==
+$ error +$ error
$% [%not-connected status=@ud] $% [%not-connected status=@ud]
@ -48,22 +48,12 @@
[%get-block-and-fee ~] [%get-block-and-fee ~]
== ==
:: ::
+$ response
$% [%error error]
[%result result]
[%unhandled-response ~]
==
+$ error
$? %tx-inputs-missing-or-spent
%blocks-not-ready
%connection-error
==
+$ result +$ result
$% [%get-address-info utxos=(set utxo) used=? block=@ud] $% [%get-address-info utxos=(set utxo) used=? block=@ud]
[%get-tx-vals =info:tx] [%get-tx-vals =info:tx]
[%get-raw-tx =txid =rawtx] [%get-raw-tx =txid =rawtx]
[%create-raw-tx =rawtx] [%create-raw-tx =rawtx]
[%broadcast-tx =txid] [%broadcast-tx =txid broadcast=? included=?]
[%get-block-count block=@ud] [%get-block-count block=@ud]
[%get-block-and-fee block=@ud fee=sats] [%get-block-and-fee block=@ud fee=sats]

View File

@ -29,6 +29,12 @@
== ==
++ tx ++ tx
|% |%
+$ data
$: is=(list input)
os=(list output)
locktime=@ud
witness=@ud
==
+$ val +$ val
$: =txid $: =txid
pos=@ud pos=@ud
@ -50,14 +56,17 @@
== ==
+$ input +$ input
$: =txid $: =txid
tx-index=@ pos=@ud
witness-ver=@ witness-ver=@ud
sequence=byts sequence=byts
script-pubkey=byts
redeem-script=(unit byts) redeem-script=(unit byts)
pubkey=(unit byts) pubkey=(unit byts)
value=sats value=sats
== ==
+$ output
$: =address
value=sats
==
-- --
++ psbt ++ psbt
|% |%