docs, btc-provider refactored

This commit is contained in:
timlucmiptev 2020-11-13 12:14:35 +02:00 committed by ixv
parent 9bb35bdc3b
commit f20a2bbc12
4 changed files with 64 additions and 75 deletions

View File

@ -3,8 +3,7 @@ The below requires norsyr's fix to `decompress-point` in order to work.
## Set Credentials and Ping Servers ## Set Credentials and Ping Servers
``` ```
=rpc-pass '78bd7a1107d6a23acc489abfc4029f959f1518c1713d998a161f83c307da32af' :btc-provider|command [%set-credentials api-url='http://localhost:50002']
:btc-provider|command [%set-credentials [rpc-url='http://localhost:8332' rpc-user='__cookie__' rpc-pass] [rpc-url='http://localhost:50002']]
:btc-provider|action ['addr0' %address-info [%bech32 'bc1q59u5epktervh6fxqay2dlph0wxu9hjnx6v8n66']] :btc-provider|action ['addr0' %address-info [%bech32 'bc1q59u5epktervh6fxqay2dlph0wxu9hjnx6v8n66']]
:btc-provider|action ['addr1' %address-info [%bech32 'bc1qlwd7mw33uea5m8r2lsnsrkc7gp2qynrxsfxpfm']] :btc-provider|action ['addr1' %address-info [%bech32 'bc1qlwd7mw33uea5m8r2lsnsrkc7gp2qynrxsfxpfm']]

View File

@ -7,7 +7,7 @@
:: results/errors of RPC calls :: results/errors of RPC calls
:: ::
/- btc /- btc
/+ *btc-provider, dbug, default-agent, elib=electrum-rpc /+ *btc-provider, dbug, default-agent
|% |%
+$ versioned-state +$ versioned-state
$% state-0 $% state-0
@ -31,7 +31,7 @@
++ on-init ++ on-init
^- (quip card _this) ^- (quip card _this)
~& > '%btc-provider initialized successfully' ~& > '%btc-provider initialized successfully'
`this(host-info [*credentials connected=%.n clients=*(set ship)], whitelist *(set ship)) `this(host-info ['' connected=%.n clients=*(set ship)], whitelist *(set ship))
++ on-save ++ on-save
^- vase ^- vase
!>(state) !>(state)
@ -107,10 +107,10 @@
=/ ract=action:rpc =/ ract=action:rpc
?- -.body.act ?- -.body.act
%address-info %address-info
[%get-address-utxos address.body.act] [%get-address-info address.body.act]
:: ::
%ping %ping
[%brpc %get-block-count ~] [%get-block-count ~]
== ==
[~[(req-card act ract)] state] [~[(req-card act ract)] state]
++ req-card ++ req-card
@ -124,7 +124,7 @@
++ mk-wire ++ mk-wire
|= act=action ^- wire |= act=action ^- wire
/[-.body.act]/[req-id.act]/[(scot %da now.bowl)] /[-.body.act]/[req-id.act]/[(scot %da now.bowl)]
:: Handles HTTP responses from RPC servers. Parses for errors, then handles response. :: Handles HTTP responses from RPC servers. Parses for errors, then handles response.
:: For actions that require collating multiple RPC calls, uses req-card to call out :: For actions that require collating multiple RPC calls, uses req-card to call out
:: to RPC again if more information is required. :: to RPC again if more information is required.
:: ::
@ -149,12 +149,12 @@
?+ wire ~|("Unexpected HTTP response" !!) ?+ wire ~|("Unexpected HTTP response" !!)
[%address-info @ *] [%address-info @ *]
=/ req-id=@t +>-.wire =/ req-id=@t +>-.wire
=/ resp=response:rpc (parse-response:rpc rpc-resp) =/ resp=response:rpc (parse-response rpc-resp)
?> ?=([%get-address-info *] resp) ?> ?=([%get-address-info *] resp)
:_ state :_ state
~[(send-update [%& req-id %address-info utxos.resp %.y])] ~[(send-update [%& req-id %address-info +.resp])]
:: ::
[%ping %brpc *] [%ping @ *]
:- ~[(send-status %connected)] :- ~[(send-status %connected)]
state(connected.host-info %.y) state(connected.host-info %.y)
== ==

View File

@ -36,7 +36,7 @@
|= h=@t |= h=@t
(hash256 [32 (to-hex h)]) (hash256 [32 (to-hex h)])
:: ::
++ http-request ++ get-request
|= url=@t |= url=@t
^- request:http ^- request:http
[%'GET' url ~ ~] [%'GET' url ~ ~]
@ -44,69 +44,59 @@
++ gen-request ++ gen-request
|= [=host-info ract=action:rpc] |= [=host-info ract=action:rpc]
^- request:http ^- request:http
%+ action-to-http:rpc %+ rpc-action-to-http
api-url.creds.host-info api-url.host-info ract
:: ::
++ to-response ++ to-response
|= result:rpc |= result:rpc
^- result ^- result
*result *result
++ rpc ++ parse-response
|% |= res=response:rpc:jstd
++ parse-response |^ ^- response:rpc
|= res=response:rpc:jstd ~| -.res
|^ ^- response:rpc :: ignores RPC responses of %error, %fails and %batch
~| -.res
:: only deals with successful requests
:: ignores (%error, %fails and %batch)
::
?> ?=(%result -.res)
?+ id.res ~|([%unsupported-response id.res] !!)
%get-address-info
[id.res (address-info res.res)]
::
%get-block-count
[id.res (ni:dejs:format res.res)]
==
++ address-info
:: TODO: top element is blockcount+utxos
:: use: (as:dejs:format utxo)
++ utxo
%- ot:dejs:format
:~ ['tx_pos' ni:dejs:format]
['tx_hash' (cu:dejs:format to-hash256 so:dejs:format)]
[%height ni:dejs:format]
[%value ni:dejs:format]
[%blockcount ni:dejs:format]
==
++ history
%- ot:dejs:format
:~ ['tx_hash' (cu:dejs:format to-hash256 so:dejs:format)]
[%height ni:dejs:format]
[%blockcount ni:dejs:format]
==
--
:: ::
++ action-to-http ?> ?=(%result -.res)
|= [endpoint=@t ract=action:rpc] ?+ id.res ~|([%unsupported-response id.res] !!)
|^ ^- request:http %get-address-info
%- http-request [id.res (address-info res.res)]
?- -.ract ::
%get-address-utxos %get-block-count
(mk-url '/addresses/utxos/' `address.ract) [id.res (ni:dejs:format res.res)]
:: ==
%get-address-history ++ address-info
(mk-url '/addresses/history/' `address.ract) %- ot:dejs:format
%get-block-count :~ [%utxos (as:dejs:format utxo)]
(mk-url '/blockcount' ~) [%used bo:dejs:format]
[%blockcount ni:dejs:format]
== ==
++ mk-url ++ utxo
|= [base=@t uaddr=(unit address)] %- ot:dejs:format
=/ addr=@t :~ ['tx_pos' ni:dejs:format]
?~ uaddr '' (address-to-cord u.uaddr) ['tx_hash' (cu:dejs:format to-hash256 so:dejs:format)]
%^ cat 3 [%height ni:dejs:format]
(cat 3 endpoint base) [%value ni:dejs:format]
(address-to-cord addr) ==
-- --
::
++ rpc-action-to-http
|= [endpoint=@t ract=action:rpc]
|^ ^- request:http
%- get-request
?- -.ract
%get-address-info
(mk-url '/addresses/info/' `address.ract)
::
%get-block-count
(mk-url '/getblockcount' ~)
==
++ mk-url
|= [base=@t uaddr=(unit address)]
=/ addr=@t
?~ uaddr '' (address-to-cord u.uaddr)
%^ cat 3
(cat 3 endpoint base) addr
-- --
-- --

View File

@ -2,6 +2,10 @@
|% |%
+$ host-info [api-url=@t connected=? clients=(set ship)] +$ host-info [api-url=@t connected=? clients=(set ship)]
+$ req-id @t +$ req-id @t
+$ command
$% [%set-credentials api-url=@t]
[%whitelist-clients clients=(set ship)]
==
+$ action [=req-id body=action-body] +$ action [=req-id body=action-body]
+$ action-body +$ action-body
$% [%address-info =address] $% [%address-info =address]
@ -9,7 +13,7 @@
== ==
+$ result [=req-id body=result-body] +$ result [=req-id body=result-body]
+$ result-body +$ result-body
$% [%address-info utxos=(set utxo) used=?] $% [%address-info utxos=(set utxo) used=? blockcount=@ud]
== ==
+$ error +$ error
$% [%not-connected status=@ud] $% [%not-connected status=@ud]
@ -21,19 +25,15 @@
+$ update (each result error) +$ update (each result error)
+$ status ?(%connected %disconnected) +$ status ?(%connected %disconnected)
:: ::
+$ command
$% [%set-credentials api-url=@t]
[%whitelist-clients clients=(set ship)]
==
++ rpc ++ rpc
|% |%
+$ action +$ action
$: [%get-address-info =address] $% [%get-address-info =address]
[%get-block-count ~] [%get-block-count ~]
== ==
:: ::
+$ response +$ response
$: [%get-address-info utxos=(set utxo) used=? blockcount=@ud] $% [%get-address-info utxos=(set utxo) used=? blockcount=@ud]
[%get-block-count blockcount=@ud] [%get-block-count blockcount=@ud]
== ==
-- --