2020-12-09 12:35:02 +03:00
|
|
|
/- sur=btc-provider, json-rpc
|
|
|
|
/+ *btc
|
2020-10-20 13:44:31 +03:00
|
|
|
^?
|
|
|
|
=< [sur .]
|
|
|
|
=, sur
|
|
|
|
|%
|
2020-11-12 18:20:54 +03:00
|
|
|
++ address-to-cord
|
|
|
|
|= =address ^- cord
|
2021-01-22 11:59:38 +03:00
|
|
|
?: ?=([%base58 *] address)
|
2020-11-12 18:20:54 +03:00
|
|
|
(scot %uc +.address)
|
|
|
|
+.address
|
|
|
|
::
|
|
|
|
++ address-from-cord
|
|
|
|
|= addrc=@t ^- address
|
|
|
|
?. ?| =("bc1" (scag 3 (trip addrc)))
|
|
|
|
=("tb1" (scag 3 (trip addrc)))
|
|
|
|
==
|
2021-01-22 11:59:38 +03:00
|
|
|
~|("base58 addresses not yet supported" !!)
|
2020-11-12 18:20:54 +03:00
|
|
|
[%bech32 addrc]
|
2020-12-08 12:56:32 +03:00
|
|
|
::
|
2021-01-26 21:36:21 +03:00
|
|
|
++ hexb-to-cord
|
|
|
|
|= =hexb ^- cord
|
|
|
|
(en:base16:mimes:html hexb)
|
2020-12-13 13:04:47 +03:00
|
|
|
::
|
2020-12-08 12:56:32 +03:00
|
|
|
++ txid-to-cord
|
2021-01-26 21:36:21 +03:00
|
|
|
|= txid=hexb
|
|
|
|
^- cord
|
2020-12-08 12:56:32 +03:00
|
|
|
(en:base16:mimes:html txid)
|
2020-12-01 15:23:11 +03:00
|
|
|
:: +from-epoch: time since Jan 1, 1970 in seconds.
|
|
|
|
::
|
|
|
|
++ from-epoch
|
|
|
|
|= secs=@ud
|
|
|
|
^- (unit @da)
|
|
|
|
?: =(0 secs) ~
|
|
|
|
[~ (add ~1970.1.1 `@dr`(mul secs ~s1))]
|
2020-11-12 18:20:54 +03:00
|
|
|
::
|
2020-11-13 13:14:35 +03:00
|
|
|
++ get-request
|
2020-11-12 18:20:54 +03:00
|
|
|
|= url=@t
|
|
|
|
^- request:http
|
|
|
|
[%'GET' url ~ ~]
|
2020-10-20 17:13:52 +03:00
|
|
|
::
|
2020-12-08 12:56:32 +03:00
|
|
|
++ post-request
|
|
|
|
|= [url=@t body=json]
|
|
|
|
^- request:http
|
|
|
|
:* %'POST'
|
|
|
|
url
|
|
|
|
~[['Content-Type' 'application/json']]
|
|
|
|
=, html
|
|
|
|
%- some
|
|
|
|
%- as-octt:mimes
|
|
|
|
(en-json body)
|
|
|
|
==
|
|
|
|
::
|
2020-10-20 17:13:52 +03:00
|
|
|
++ gen-request
|
2020-12-13 13:04:47 +03:00
|
|
|
|= [=host-info ract=action:rpc-types]
|
2020-10-20 17:13:52 +03:00
|
|
|
^- request:http
|
2020-11-13 13:14:35 +03:00
|
|
|
%+ rpc-action-to-http
|
|
|
|
api-url.host-info ract
|
2020-10-20 17:13:52 +03:00
|
|
|
::
|
2020-12-13 13:04:47 +03:00
|
|
|
++ rpc
|
2021-02-11 14:00:21 +03:00
|
|
|
=, dejs:format
|
2020-12-13 13:04:47 +03:00
|
|
|
|%
|
|
|
|
++ parse-result
|
|
|
|
|= res=response:json-rpc
|
|
|
|
|^ ^- result:rpc-types
|
|
|
|
~| -.res
|
|
|
|
?> ?=(%result -.res)
|
2020-12-13 20:00:52 +03:00
|
|
|
?+ id.res ~|([%unsupported-result id.res] !!)
|
2020-12-13 13:04:47 +03:00
|
|
|
%get-address-info
|
|
|
|
[id.res (address-info res.res)]
|
|
|
|
::
|
|
|
|
%get-tx-vals
|
|
|
|
[id.res (tx-vals res.res)]
|
|
|
|
::
|
|
|
|
%get-raw-tx
|
|
|
|
[id.res (raw-tx res.res)]
|
2020-12-21 12:50:33 +03:00
|
|
|
::
|
2020-12-13 20:00:52 +03:00
|
|
|
%broadcast-tx
|
2020-12-13 23:33:08 +03:00
|
|
|
[%broadcast-tx (broadcast-tx res.res)]
|
2020-12-13 13:04:47 +03:00
|
|
|
::
|
|
|
|
%get-block-count
|
2021-02-11 14:00:21 +03:00
|
|
|
[id.res (ni res.res)]
|
2020-12-13 13:04:47 +03:00
|
|
|
::
|
2021-01-26 14:27:32 +03:00
|
|
|
%get-block-info
|
|
|
|
[id.res (block-info res.res)]
|
2020-11-16 19:30:50 +03:00
|
|
|
==
|
2020-12-13 13:04:47 +03:00
|
|
|
++ address-info
|
|
|
|
%- ot:dejs:format
|
2020-12-23 15:58:23 +03:00
|
|
|
:~ [%address (cu:dejs:format address-from-cord so:dejs:format)]
|
|
|
|
[%utxos (as:dejs:format utxo)]
|
2020-12-13 13:04:47 +03:00
|
|
|
[%used bo:dejs:format]
|
|
|
|
[%block ni:dejs:format]
|
|
|
|
==
|
|
|
|
++ utxo
|
|
|
|
%- ot:dejs:format
|
|
|
|
:~ ['tx_pos' ni:dejs:format]
|
2021-01-26 21:36:21 +03:00
|
|
|
['tx_hash' (cu:dejs:format to-hexb so:dejs:format)]
|
2020-12-13 13:04:47 +03:00
|
|
|
[%height ni:dejs:format]
|
|
|
|
[%value ni:dejs:format]
|
|
|
|
[%recvd (cu:dejs:format from-epoch ni:dejs:format)]
|
|
|
|
==
|
2021-01-26 14:27:32 +03:00
|
|
|
++ tx-vals
|
2020-12-13 13:04:47 +03:00
|
|
|
%- ot:dejs:format
|
2020-12-21 12:50:33 +03:00
|
|
|
:~ [%included bo:dejs:format]
|
2021-01-26 21:36:21 +03:00
|
|
|
[%txid (cu:dejs:format to-hexb so:dejs:format)]
|
2020-12-13 13:04:47 +03:00
|
|
|
[%confs ni:dejs:format]
|
|
|
|
[%recvd (cu:dejs:format from-epoch ni:dejs:format)]
|
|
|
|
[%inputs (ar:dejs:format tx-val)]
|
|
|
|
[%outputs (ar:dejs:format tx-val)]
|
|
|
|
==
|
|
|
|
++ tx-val
|
|
|
|
%- ot:dejs:format
|
2021-01-26 21:36:21 +03:00
|
|
|
:~ [%txid (cu:dejs:format to-hexb so:dejs:format)]
|
2020-12-13 13:04:47 +03:00
|
|
|
[%pos ni:dejs:format]
|
|
|
|
[%address (cu:dejs:format address-from-cord so:dejs:format)]
|
|
|
|
[%value ni:dejs:format]
|
|
|
|
==
|
|
|
|
++ raw-tx
|
|
|
|
%- ot:dejs:format
|
2021-01-26 21:36:21 +03:00
|
|
|
:~ [%txid (cu:dejs:format to-hexb so:dejs:format)]
|
|
|
|
[%rawtx (cu:dejs:format to-hexb so:dejs:format)]
|
2020-12-13 13:04:47 +03:00
|
|
|
==
|
2020-12-13 23:33:08 +03:00
|
|
|
++ broadcast-tx
|
|
|
|
%- ot:dejs:format
|
2021-01-26 21:36:21 +03:00
|
|
|
:~ [%txid (cu:dejs:format to-hexb so:dejs:format)]
|
2020-12-13 23:33:08 +03:00
|
|
|
[%broadcast bo:dejs:format]
|
|
|
|
[%included bo:dejs:format]
|
|
|
|
==
|
2021-01-26 14:27:32 +03:00
|
|
|
++ block-info
|
2020-12-13 13:04:47 +03:00
|
|
|
%- ot:dejs:format
|
|
|
|
:~ [%block ni:dejs:format]
|
2021-02-11 14:00:21 +03:00
|
|
|
[%fee (mu:dejs:format ni:dejs:format)]
|
2021-01-26 21:36:21 +03:00
|
|
|
[%blockhash (cu:dejs:format to-hexb so:dejs:format)]
|
|
|
|
[%blockfilter (cu:dejs:format to-hexb so:dejs:format)]
|
2020-12-13 13:04:47 +03:00
|
|
|
==
|
|
|
|
--
|
2020-11-13 13:14:35 +03:00
|
|
|
--
|
|
|
|
::
|
|
|
|
++ rpc-action-to-http
|
2020-12-13 13:04:47 +03:00
|
|
|
|= [endpoint=@t ract=action:rpc-types]
|
2020-11-13 13:14:35 +03:00
|
|
|
|^ ^- request:http
|
|
|
|
?- -.ract
|
|
|
|
%get-address-info
|
2020-12-08 12:56:32 +03:00
|
|
|
%- get-request
|
2020-11-20 14:58:27 +03:00
|
|
|
%+ mk-url '/addresses/info/'
|
|
|
|
(address-to-cord address.ract)
|
2020-12-06 20:53:02 +03:00
|
|
|
::
|
|
|
|
%get-tx-vals
|
2020-12-08 12:56:32 +03:00
|
|
|
%- get-request
|
2020-12-06 20:53:02 +03:00
|
|
|
%+ mk-url '/gettxvals/'
|
2020-12-08 12:56:32 +03:00
|
|
|
(txid-to-cord txid.ract)
|
2020-11-20 14:58:27 +03:00
|
|
|
::
|
|
|
|
%get-raw-tx
|
2020-12-08 12:56:32 +03:00
|
|
|
%- get-request
|
2020-11-20 14:58:27 +03:00
|
|
|
%+ mk-url '/getrawtx/'
|
2020-12-08 12:56:32 +03:00
|
|
|
(txid-to-cord txid.ract)
|
2020-12-13 13:04:47 +03:00
|
|
|
::
|
|
|
|
%broadcast-tx
|
|
|
|
%- get-request
|
|
|
|
%+ mk-url '/broadcasttx/'
|
2021-01-26 21:36:21 +03:00
|
|
|
(hexb-to-cord rawtx.ract)
|
2020-11-13 13:14:35 +03:00
|
|
|
::
|
|
|
|
%get-block-count
|
2020-12-08 12:56:32 +03:00
|
|
|
%- get-request
|
2020-11-20 14:58:27 +03:00
|
|
|
(mk-url '/getblockcount' '')
|
2020-11-16 19:30:50 +03:00
|
|
|
::
|
2021-01-26 14:27:32 +03:00
|
|
|
%get-block-info
|
2020-12-08 12:56:32 +03:00
|
|
|
%- get-request
|
2021-01-26 14:27:32 +03:00
|
|
|
(mk-url '/getblockinfo' '')
|
2020-11-13 13:14:35 +03:00
|
|
|
==
|
|
|
|
++ mk-url
|
2020-11-20 14:58:27 +03:00
|
|
|
|= [base=@t params=@t]
|
2020-11-13 13:14:35 +03:00
|
|
|
%^ cat 3
|
2020-11-20 14:58:27 +03:00
|
|
|
(cat 3 endpoint base) params
|
2020-11-12 18:20:54 +03:00
|
|
|
--
|
2020-11-13 13:17:02 +03:00
|
|
|
:: RPC/HTTP Utilities
|
|
|
|
::
|
|
|
|
++ httr-to-rpc-response
|
|
|
|
|= hit=httr:eyre
|
2020-12-09 12:35:02 +03:00
|
|
|
^- response:json-rpc
|
2020-11-13 13:17:02 +03:00
|
|
|
~| hit
|
|
|
|
=/ jon=json (need (de-json:html q:(need r.hit)))
|
|
|
|
?. =(%2 (div p.hit 100))
|
|
|
|
(parse-rpc-error jon)
|
|
|
|
=, dejs-soft:format
|
2020-12-09 12:35:02 +03:00
|
|
|
^- response:json-rpc
|
2020-11-13 13:17:02 +03:00
|
|
|
=; dere
|
|
|
|
=+ res=((ar dere) jon)
|
|
|
|
?~ res (need (dere jon))
|
|
|
|
[%batch u.res]
|
|
|
|
|= jon=json
|
2020-12-09 12:35:02 +03:00
|
|
|
^- (unit response:json-rpc)
|
2020-11-13 13:17:02 +03:00
|
|
|
=/ res=[id=(unit @t) res=(unit json) err=(unit json)]
|
|
|
|
%. jon
|
|
|
|
=, dejs:format
|
|
|
|
=- (ou -)
|
|
|
|
:~ ['id' (uf ~ (mu so))]
|
|
|
|
['result' (uf ~ (mu same))]
|
|
|
|
['error' (uf ~ (mu same))]
|
|
|
|
==
|
|
|
|
?: ?=([^ * ~] res)
|
|
|
|
`[%result [u.id.res ?~(res.res ~ u.res.res)]]
|
|
|
|
~| jon
|
|
|
|
`(parse-rpc-error jon)
|
|
|
|
::
|
|
|
|
++ get-rpc-response
|
|
|
|
|= response=client-response:iris
|
2020-12-09 12:35:02 +03:00
|
|
|
^- response:json-rpc
|
2020-11-13 13:17:02 +03:00
|
|
|
?> ?=(%finished -.response)
|
|
|
|
%- httr-to-rpc-response
|
|
|
|
%+ to-httr:iris
|
|
|
|
response-header.response
|
|
|
|
full-file.response
|
|
|
|
::
|
|
|
|
++ parse-rpc-error
|
|
|
|
|= =json
|
2020-12-09 12:35:02 +03:00
|
|
|
^- response:json-rpc
|
2020-11-13 13:17:02 +03:00
|
|
|
:- %error
|
|
|
|
?~ json ['' '' '']
|
|
|
|
%. json
|
|
|
|
=, dejs:format
|
|
|
|
=- (ou -)
|
|
|
|
:~ =- ['id' (uf '' (cu - (mu so)))]
|
|
|
|
|*(a=(unit) ?~(a '' u.a))
|
|
|
|
:- 'error'
|
|
|
|
=- (uf ['' ''] -)
|
|
|
|
=- (cu |*(a=(unit) ?~(a ['' ''] u.a)) (mu (ou -)))
|
|
|
|
:~ ['code' (uf '' no)]
|
|
|
|
['message' (uf '' so)]
|
|
|
|
== ==
|
2020-10-20 13:44:31 +03:00
|
|
|
--
|