mirror of
https://github.com/urbit/shrub.git
synced 2024-12-22 10:21:31 +03:00
btc-provider lib
This commit is contained in:
parent
9dfe6210d2
commit
dc09351e0e
@ -2,8 +2,7 @@
|
|||||||
:: btc-provider.hoon
|
:: btc-provider.hoon
|
||||||
:: Proxy that serves a BTC full node and ElectRS address indexer
|
:: Proxy that serves a BTC full node and ElectRS address indexer
|
||||||
::
|
::
|
||||||
/- *btc-provider, bnh=btc-node-hook
|
/+ *btc-provider, dbug, default-agent, base64, blib=btc-node-json, elib=electrum-rpc
|
||||||
/+ dbug, default-agent, base64, blib=btc-node-json, elib=electrum-rpc-http
|
|
||||||
|%
|
|%
|
||||||
+$ versioned-state
|
+$ versioned-state
|
||||||
$% state-0
|
$% state-0
|
||||||
@ -225,7 +224,7 @@
|
|||||||
++ electrum-http-response
|
++ electrum-http-response
|
||||||
|= [status=@ud rpc-resp=response:rpc:jstd]
|
|= [status=@ud rpc-resp=response:rpc:jstd]
|
||||||
^- (quip card _state)
|
^- (quip card _state)
|
||||||
~& > rpc-resp
|
~& >> (parse-response:electrum-rpc:elib rpc-resp)
|
||||||
`state
|
`state
|
||||||
::
|
::
|
||||||
--
|
--
|
||||||
|
@ -3,7 +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 '22b159ae3ebfdc3404b446fc61df4760de0fece271586dfb5039e1260cb15775'
|
=rpc-pass '302a586ef1d1d4d93f22b1c69cadfdfc8323b984c0f469356529b1a8fdd2558e'
|
||||||
: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 [rpc-url='http://localhost:8332' rpc-user='__cookie__' rpc-pass] [rpc-url='http://localhost:50002']]
|
||||||
|
|
||||||
:btc-provider|rpc-action [%brpc %get-block-count ~]
|
:btc-provider|rpc-action [%brpc %get-block-count ~]
|
||||||
|
10
lib/btc-provider.hoon
Normal file
10
lib/btc-provider.hoon
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/- sur=btc-provider, *btc
|
||||||
|
^?
|
||||||
|
=< [sur .]
|
||||||
|
=, sur
|
||||||
|
|%
|
||||||
|
++ to-response
|
||||||
|
|= response:rpc
|
||||||
|
^- response:sur
|
||||||
|
[%get-address-info *address-info]
|
||||||
|
--
|
@ -1,35 +0,0 @@
|
|||||||
|
|
||||||
/- *btc-provider, *btc
|
|
||||||
|%
|
|
||||||
++ address-to-cord
|
|
||||||
|= =address ^- cord
|
|
||||||
?: ?=([%legacy *] address)
|
|
||||||
(scot %uc +.address)
|
|
||||||
+.address
|
|
||||||
++ http-request
|
|
||||||
|= url=@t
|
|
||||||
^- request:http
|
|
||||||
[%'GET' url ~ ~]
|
|
||||||
::
|
|
||||||
++ electrum-rpc
|
|
||||||
|%
|
|
||||||
++ parse-response
|
|
||||||
|= rpc-resp=@t
|
|
||||||
%.y
|
|
||||||
++ request-to-http
|
|
||||||
|= [endpoint=@t req=request:electrum:rpc]
|
|
||||||
^- request:http
|
|
||||||
%- http-request
|
|
||||||
?- -.req
|
|
||||||
%get-address-balance
|
|
||||||
%^ cat 3
|
|
||||||
(cat 3 endpoint '/addresses/balance/')
|
|
||||||
(address-to-cord address.req)
|
|
||||||
::
|
|
||||||
%get-address-utxos
|
|
||||||
%^ cat 3
|
|
||||||
(cat 3 endpoint '/addresses/listunspent/')
|
|
||||||
(address-to-cord address.req)
|
|
||||||
==
|
|
||||||
--
|
|
||||||
--
|
|
68
lib/electrum-rpc.hoon
Normal file
68
lib/electrum-rpc.hoon
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/- *btc-provider, *btc
|
||||||
|
|%
|
||||||
|
++ address-to-cord
|
||||||
|
|= =address ^- cord
|
||||||
|
?: ?=([%legacy *] address)
|
||||||
|
(scot %uc +.address)
|
||||||
|
+.address
|
||||||
|
++ to-hex
|
||||||
|
|= h=@t
|
||||||
|
^- @ux
|
||||||
|
?: =('' h) 0x0
|
||||||
|
:: Add leading 00
|
||||||
|
::
|
||||||
|
=+ (lsh 3 2 h)
|
||||||
|
:: Group by 4-size block
|
||||||
|
::
|
||||||
|
=+ (rsh 3 2 -)
|
||||||
|
:: Parse hex to atom
|
||||||
|
::
|
||||||
|
`@ux`(rash - hex)
|
||||||
|
++ to-hash256
|
||||||
|
|= h=@t
|
||||||
|
(hash256 [32 (to-hex h)])
|
||||||
|
++ http-request
|
||||||
|
|= url=@t
|
||||||
|
^- request:http
|
||||||
|
[%'GET' url ~ ~]
|
||||||
|
::
|
||||||
|
++ electrum-rpc
|
||||||
|
|%
|
||||||
|
++ parse-response
|
||||||
|
|= res=response:rpc:jstd
|
||||||
|
|^ ^- response:electrum:rpc
|
||||||
|
~| -.res
|
||||||
|
:: only deals with successful requests
|
||||||
|
:: ignores (%error, %fails and %batch)
|
||||||
|
::
|
||||||
|
?> ?=(%result -.res)
|
||||||
|
?+ id.res ~|([%unsupported-response id.res] !!)
|
||||||
|
%get-address-utxos
|
||||||
|
[id.res ((as:dejs:format utxo) res.res)]
|
||||||
|
==
|
||||||
|
++ 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]
|
||||||
|
==
|
||||||
|
--
|
||||||
|
::
|
||||||
|
++ request-to-http
|
||||||
|
|= [endpoint=@t req=request:electrum:rpc]
|
||||||
|
^- request:http
|
||||||
|
%- http-request
|
||||||
|
?- -.req
|
||||||
|
%get-address-balance
|
||||||
|
%^ cat 3
|
||||||
|
(cat 3 endpoint '/addresses/balance/')
|
||||||
|
(address-to-cord address.req)
|
||||||
|
::
|
||||||
|
%get-address-utxos
|
||||||
|
%^ cat 3
|
||||||
|
(cat 3 endpoint '/addresses/utxos/')
|
||||||
|
(address-to-cord address.req)
|
||||||
|
==
|
||||||
|
--
|
||||||
|
--
|
@ -574,10 +574,7 @@
|
|||||||
+$ btc-node-hook-command command:btc-rpc
|
+$ btc-node-hook-command command:btc-rpc
|
||||||
:: Expand the response type to include connectivity
|
:: Expand the response type to include connectivity
|
||||||
::
|
::
|
||||||
+$ btc-node-hook-response
|
+$ btc-node-hook-response response:btc-rpc
|
||||||
$% [%status connected=? status-code=@ud]
|
|
||||||
response:btc-rpc
|
|
||||||
==
|
|
||||||
::
|
::
|
||||||
++ btc-rpc
|
++ btc-rpc
|
||||||
|%
|
|%
|
||||||
|
@ -25,6 +25,10 @@
|
|||||||
$% [%erpc request:electrum:rpc]
|
$% [%erpc request:electrum:rpc]
|
||||||
[%brpc request:bitcoin-core:rpc]
|
[%brpc request:bitcoin-core:rpc]
|
||||||
==
|
==
|
||||||
|
+$ rpc-response
|
||||||
|
$% [%erpc response:electrum:rpc]
|
||||||
|
[%brpc response:bitcoin-core:rpc]
|
||||||
|
==
|
||||||
++ rpc
|
++ rpc
|
||||||
|%
|
|%
|
||||||
++ electrum
|
++ electrum
|
||||||
@ -33,10 +37,14 @@
|
|||||||
$% [%get-address-balance =address]
|
$% [%get-address-balance =address]
|
||||||
[%get-address-utxos =address]
|
[%get-address-utxos =address]
|
||||||
==
|
==
|
||||||
|
+$ response
|
||||||
|
$% [%get-address-utxos utxos=(set utxo)]
|
||||||
|
==
|
||||||
--
|
--
|
||||||
++ bitcoin-core
|
++ bitcoin-core
|
||||||
|%
|
|%
|
||||||
+$ request btc-node-hook-action:bnh
|
+$ request btc-node-hook-action:bnh
|
||||||
|
+$ response btc-node-hook-response:bnh
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
--
|
--
|
||||||
|
Loading…
Reference in New Issue
Block a user