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
```
=rpc-pass '78bd7a1107d6a23acc489abfc4029f959f1518c1713d998a161f83c307da32af'
:btc-provider|command [%set-credentials [rpc-url='http://localhost:8332' rpc-user='__cookie__' rpc-pass] [rpc-url='http://localhost:50002']]
:btc-provider|command [%set-credentials api-url='http://localhost:50002']
:btc-provider|action ['addr0' %address-info [%bech32 'bc1q59u5epktervh6fxqay2dlph0wxu9hjnx6v8n66']]
:btc-provider|action ['addr1' %address-info [%bech32 'bc1qlwd7mw33uea5m8r2lsnsrkc7gp2qynrxsfxpfm']]

View File

@ -7,7 +7,7 @@
:: results/errors of RPC calls
::
/- btc
/+ *btc-provider, dbug, default-agent, elib=electrum-rpc
/+ *btc-provider, dbug, default-agent
|%
+$ versioned-state
$% state-0
@ -31,7 +31,7 @@
++ on-init
^- (quip card _this)
~& > '%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
^- vase
!>(state)
@ -107,10 +107,10 @@
=/ ract=action:rpc
?- -.body.act
%address-info
[%get-address-utxos address.body.act]
[%get-address-info address.body.act]
::
%ping
[%brpc %get-block-count ~]
[%get-block-count ~]
==
[~[(req-card act ract)] state]
++ req-card
@ -149,12 +149,12 @@
?+ wire ~|("Unexpected HTTP response" !!)
[%address-info @ *]
=/ req-id=@t +>-.wire
=/ resp=response:rpc (parse-response:rpc rpc-resp)
=/ resp=response:rpc (parse-response rpc-resp)
?> ?=([%get-address-info *] resp)
:_ state
~[(send-update [%& req-id %address-info utxos.resp %.y])]
~[(send-update [%& req-id %address-info +.resp])]
::
[%ping %brpc *]
[%ping @ *]
:- ~[(send-status %connected)]
state(connected.host-info %.y)
==

View File

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

View File

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