%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)
~[(send-status [%disconnected ~]) (send-update [%| u.conn-err])]
::
:: TODO: make sure below works
=/ resp=response:rpc-types
%- parse-response:rpc
(get-rpc-response response)
?- -.resp
%error
(handle-rpc-error wire +.resp)
::
%result
(handle-rpc-result wire +.resp)
::
%unhandled-response
[~[(send-update [%| [%rpc-error ~]])] state]
==
%+ handle-rpc-result wire
%- parse-result:rpc
(get-rpc-response response)
::
++ connection-error
|= status=@ud
@ -189,15 +178,6 @@
[`[%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
|= [=wire r=result:rpc-types]
^- (quip card _state)
@ -215,17 +195,17 @@
[%raw-tx @ *]
?> ?=([%get-raw-tx *] r)
:_ state
~[(send-update [%.y (get-req-id wire) %raw-tx +.r])]
~[(send-update [%.y (get-req-id wire) %raw-tx +.r])]
::
[%create-raw-tx @ *]
?> ?=([%get-raw-tx *] r)
:_ state
~[(send-update [%.y (get-req-id wire) %raw-tx +.r])]
::
[%broadcast-raw-tx @ *]
[%broadcast-tx @ *]
?> ?=([%broadcast-tx *] r)
:_ state
~[(send-update [%.y (get-req-id wire) %broadcast-tx %.y +.r])]
~[(send-update [%.y (get-req-id wire) %broadcast-tx +.r])]
::
[%ping @ *]
?> ?=([%get-block-and-fee *] r)

View File

@ -116,26 +116,6 @@
::
++ 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
|= res=response:json-rpc
|^ ^- result:rpc-types
@ -155,7 +135,7 @@
[%get-raw-tx (raw-tx res.res)]
::
%broadcast-tx
[%broadcast-tx ((cu:dejs:format to-hash256 so:dejs:format) res.res)]
[%broadcast-tx (broadcast-tx res.res)]
::
%get-block-count
[id.res (ni:dejs:format res.res)]
@ -197,6 +177,12 @@
:~ [%txid (cu:dejs:format to-hash256 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
%- ot:dejs:format
:~ [%block ni:dejs:format]

View File

@ -53,7 +53,24 @@
?. =(wid.hex 20)
~|("Only 20-byte addresses supported" !!)
(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
|%

View File

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

View File

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