mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-12 15:01:38 +03:00
docs, btc-provider refactored
This commit is contained in:
parent
9bb35bdc3b
commit
f20a2bbc12
@ -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']]
|
||||
|
@ -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
|
||||
@ -124,7 +124,7 @@
|
||||
++ mk-wire
|
||||
|= act=action ^- wire
|
||||
/[-.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
|
||||
:: to RPC again if more information is required.
|
||||
::
|
||||
@ -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)
|
||||
==
|
||||
|
@ -36,7 +36,7 @@
|
||||
|= h=@t
|
||||
(hash256 [32 (to-hex h)])
|
||||
::
|
||||
++ http-request
|
||||
++ get-request
|
||||
|= url=@t
|
||||
^- request:http
|
||||
[%'GET' url ~ ~]
|
||||
@ -44,69 +44,59 @@
|
||||
++ 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
|
||||
|= res=response:rpc:jstd
|
||||
|^ ^- response:rpc
|
||||
~| -.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]
|
||||
==
|
||||
--
|
||||
++ parse-response
|
||||
|= res=response:rpc:jstd
|
||||
|^ ^- response:rpc
|
||||
~| -.res
|
||||
:: ignores RPC responses of %error, %fails and %batch
|
||||
::
|
||||
++ action-to-http
|
||||
|= [endpoint=@t ract=action:rpc]
|
||||
|^ ^- request:http
|
||||
%- http-request
|
||||
?- -.ract
|
||||
%get-address-utxos
|
||||
(mk-url '/addresses/utxos/' `address.ract)
|
||||
::
|
||||
%get-address-history
|
||||
(mk-url '/addresses/history/' `address.ract)
|
||||
%get-block-count
|
||||
(mk-url '/blockcount' ~)
|
||||
?> ?=(%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
|
||||
%- ot:dejs:format
|
||||
:~ [%utxos (as:dejs:format utxo)]
|
||||
[%used bo:dejs:format]
|
||||
[%blockcount ni:dejs:format]
|
||||
==
|
||||
++ 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)
|
||||
--
|
||||
++ 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]
|
||||
==
|
||||
--
|
||||
::
|
||||
++ 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
|
||||
--
|
||||
--
|
||||
|
||||
|
@ -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]
|
||||
==
|
||||
--
|
||||
|
Loading…
Reference in New Issue
Block a user