mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-14 08:34:25 +03:00
move Electrum to GET
This commit is contained in:
parent
fd0655b068
commit
87b7b230f6
@ -2,7 +2,7 @@
|
||||
:: Proxy for accessing BTC full node
|
||||
::
|
||||
/- *btc-bridge, bnh=btc-node-hook
|
||||
/+ dbug, default-agent, base64, lib=btc-node-json
|
||||
/+ dbug, default-agent, base64, blib=btc-node-json
|
||||
|%
|
||||
+$ versioned-state
|
||||
$% state-0
|
||||
@ -47,11 +47,7 @@
|
||||
%btc-bridge-command
|
||||
(handle-command:hc !<(command vase))
|
||||
%btc-bridge-rpc-action
|
||||
=/ act=rpc-action !<(rpc-action vase)
|
||||
?+ -.act (on-poke:def mark vase)
|
||||
%brpc
|
||||
(handle-action +.act)
|
||||
==
|
||||
(handle-rpc-action !<(rpc-action vase))
|
||||
==
|
||||
[cards this]
|
||||
::
|
||||
@ -90,22 +86,25 @@
|
||||
`state(clients.status (~(uni in clients.status) users.comm))
|
||||
==
|
||||
==
|
||||
++ gen-request
|
||||
|= act=btc-node-hook-action:bnh
|
||||
++ btc-rpc-auth-header
|
||||
=* user rpc-user.bc.credentials
|
||||
=* pass rpc-password.bc.credentials
|
||||
:- 'Authorization'
|
||||
;: (cury cat 3)
|
||||
'Basic '
|
||||
%- ~(en base64 | &)
|
||||
(as-octs:mimes:html :((cury cat 3) user ':' pass))
|
||||
==
|
||||
++ gen-btc-request
|
||||
|= req=request:bitcoin-core:rpc
|
||||
^- request:http
|
||||
=* user rpc-user.credentials
|
||||
=* pass rpc-password.credentials
|
||||
=* endpoint rpc-url.credentials
|
||||
=* endpoint rpc-url.bc.credentials
|
||||
=/ body=request:rpc:jstd
|
||||
(request-to-rpc:btc-rpc:lib act)
|
||||
(request-to-rpc:btc-rpc:blib req)
|
||||
=/ =header-list:http
|
||||
:~ ['Content-Type' 'application/json']
|
||||
:- 'Authorization'
|
||||
;: (cury cat 3)
|
||||
'Basic '
|
||||
%- ~(en base64 | &)
|
||||
(as-octs:mimes:html :((cury cat 3) user ':' pass))
|
||||
== ==
|
||||
btc-rpc-auth-header
|
||||
==
|
||||
:* %'POST'
|
||||
endpoint
|
||||
header-list
|
||||
@ -115,12 +114,26 @@
|
||||
(en-json (request-to-json:rpc:jstd body))
|
||||
==
|
||||
::
|
||||
++ handle-action
|
||||
|= act=btc-node-hook-action:bnh
|
||||
++ gen-electrum-request
|
||||
|= req=request:electrum:rpc
|
||||
~& >>> req
|
||||
*request:http
|
||||
++ gen-request
|
||||
|= ract=rpc-action
|
||||
^- request:http
|
||||
?- -.ract
|
||||
%erpc
|
||||
(gen-electrum-request +.ract)
|
||||
%brpc
|
||||
(gen-btc-request +.ract)
|
||||
==
|
||||
::
|
||||
++ handle-rpc-action
|
||||
|= ract=rpc-action
|
||||
^- (quip card _state)
|
||||
=/ out *outbound-config:iris
|
||||
=/ req=request:http
|
||||
(gen-request act)
|
||||
(gen-request ract)
|
||||
:_ state
|
||||
[%pass /[(scot %da now.bowl)] %arvo %i %request req out]~
|
||||
::
|
||||
@ -184,7 +197,7 @@
|
||||
?. ?=([%result *] rpc-resp)
|
||||
~& [%error +.rpc-resp]
|
||||
[~ state]
|
||||
~& > (parse-response:btc-rpc:lib rpc-resp)
|
||||
~& > (parse-response:btc-rpc:blib rpc-resp)
|
||||
[~ state]
|
||||
::
|
||||
--
|
||||
|
@ -1,6 +1,14 @@
|
||||
## NOTE
|
||||
The below requires norsyr's fix to `decompress-point` in order to work.
|
||||
|
||||
## Set Credentials and Ping Servers
|
||||
```
|
||||
:btc-bridge|command [%become-host [rpc-url='http://localhost:8332' rpc-user='__cookie__' rpc-password='b813c98bde1d4489e2889269559d1f42920fb367c59ed43eb7668ceeabde2272'] [rpc-url='http://localhost:50001']]
|
||||
|
||||
:btc-bridge|rpc-action [%brpc %get-block-count ~]
|
||||
:btc-bridge|rpc-action [%erpc %get-balance-scripthash 'c5d92092c3d6793e159d93a195c4b12b4110d2b4721862b1e208ae206858c25c']
|
||||
```
|
||||
|
||||
## Working with BTC RPC Library
|
||||
```
|
||||
|start :btc-bridge
|
||||
|
21
lib/electrum-rpc-json.hoon
Normal file
21
lib/electrum-rpc-json.hoon
Normal file
@ -0,0 +1,21 @@
|
||||
/- *btc-bridge
|
||||
/+ lib=btc-node-json
|
||||
:: dummy core until needed
|
||||
|%
|
||||
++ blank 42
|
||||
:: TODO: generate GET URLS here, or even the whole http request!!
|
||||
:: ++ electrum-rpc
|
||||
:: |%
|
||||
:: ++ request-to-rpc
|
||||
:: =, enjs:format
|
||||
:: |= req=request:electrum:rpc
|
||||
:: ^- request:rpc:jstd
|
||||
:: ?- -.req
|
||||
:: %get-address-balance
|
||||
:: :* id='0'
|
||||
:: method='blockchain.scripthash.get_balance'
|
||||
:: params=[%list ~[[%s address.req]]]
|
||||
:: ==
|
||||
:: ==
|
||||
:: --
|
||||
--
|
@ -1,7 +1,8 @@
|
||||
/- *btc, bnh=btc-node-hook
|
||||
|
||||
|%
|
||||
+$ credentials [rpc-url=@t rpc-user=@t rpc-password=@t]
|
||||
+$ btc-credentials [rpc-url=@t rpc-user=@t rpc-password=@t]
|
||||
+$ electrum-credentials [rpc-url=@t]
|
||||
+$ credentials [bc=btc-credentials ec=electrum-credentials]
|
||||
+$ status
|
||||
$% [%host connected=? clients=(set ship)]
|
||||
[%client connected=? host=(unit ship)]
|
||||
@ -19,20 +20,21 @@
|
||||
[%allow-clients users=(set ship)]
|
||||
==
|
||||
+$ rpc-action
|
||||
$% [%erpc action:electrum:rpc]
|
||||
[%brpc action:bitcoin-core:rpc]
|
||||
$% [%erpc request:electrum:rpc]
|
||||
[%brpc request:bitcoin-core:rpc]
|
||||
==
|
||||
++ rpc
|
||||
|%
|
||||
++ electrum
|
||||
|%
|
||||
+$ action
|
||||
$% [%timluc ~]
|
||||
+$ request
|
||||
$% [%get-address-balance =address]
|
||||
==
|
||||
--
|
||||
++ bitcoin-core
|
||||
|%
|
||||
+$ action btc-node-hook-action:bnh
|
||||
+$ request btc-node-hook-action:bnh
|
||||
--
|
||||
--
|
||||
--
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user