urbit/lib/btc-provider.hoon

57 lines
1.3 KiB
Plaintext
Raw Normal View History

2020-10-20 13:44:31 +03:00
/- sur=btc-provider, *btc
2020-10-20 17:13:52 +03:00
/+ blib=btc-node-json, elib=electrum-rpc, base64
2020-10-20 13:44:31 +03:00
^?
=< [sur .]
=, sur
|%
2020-10-20 17:13:52 +03:00
++ btc-rpc-auth-header
2020-10-22 10:36:25 +03:00
|= =host-info
=* user rpc-user.bc.creds.host-info
=* pass rpc-password.bc.creds.host-info
2020-10-20 17:13:52 +03:00
:- 'Authorization'
;: (cury cat 3)
'Basic '
%- ~(en base64 | &)
(as-octs:mimes:html :((cury cat 3) user ':' pass))
==
++ btc-gen-request
2020-10-22 10:36:25 +03:00
|= [=host-info req=request:bitcoin-core:rpc]
2020-10-20 17:13:52 +03:00
^- request:http
2020-10-22 10:36:25 +03:00
=* endpoint rpc-url.bc.creds.host-info
2020-10-20 17:13:52 +03:00
=/ body=request:rpc:jstd
(request-to-rpc:btc-rpc:blib req)
=/ =header-list:http
:~ ['Content-Type' 'application/json']
2020-10-22 10:36:25 +03:00
(btc-rpc-auth-header host-info)
2020-10-20 17:13:52 +03:00
==
:* %'POST'
endpoint
header-list
=, html
%- some
%- as-octt:mimes
(en-json (request-to-json:rpc:jstd body))
==
::
++ electrum-gen-request
2020-10-22 10:36:25 +03:00
|= [=host-info req=request:electrum:rpc]
2020-10-20 17:13:52 +03:00
%+ request-to-http:electrum-rpc:elib
2020-10-22 10:36:25 +03:00
rpc-url.ec.creds.host-info req
2020-10-20 17:13:52 +03:00
::
++ gen-request
2020-10-22 10:36:25 +03:00
|= [=host-info ract=action:rpc]
2020-10-20 17:13:52 +03:00
^- request:http
?- -.ract
%erpc
2020-10-22 10:36:25 +03:00
(electrum-gen-request host-info +.ract)
2020-10-20 17:13:52 +03:00
%brpc
2020-10-22 10:36:25 +03:00
(btc-gen-request host-info +.ract)
2020-10-20 17:13:52 +03:00
==
::
2020-10-20 13:44:31 +03:00
++ to-response
2020-10-23 20:35:04 +03:00
|= result:rpc
^- result
*result
::[%get-address-info *address-info]
2020-10-20 13:44:31 +03:00
--