2020-11-20 14:58:27 +03:00
|
|
|
/- sur=btc-provider
|
|
|
|
/+ base64, *btc
|
2020-10-20 13:44:31 +03:00
|
|
|
^?
|
|
|
|
=< [sur .]
|
|
|
|
=, sur
|
|
|
|
|%
|
2020-11-20 14:58:27 +03:00
|
|
|
++ gen-req-id
|
|
|
|
|= eny=@uvJ ^- req-id
|
|
|
|
%+ scot %ux
|
|
|
|
(ripemd-160:ripemd:crypto [(met 3 eny) eny])
|
|
|
|
::
|
2020-11-12 18:20:54 +03:00
|
|
|
++ address-to-cord
|
|
|
|
|= =address ^- cord
|
|
|
|
?: ?=([%legacy *] address)
|
|
|
|
(scot %uc +.address)
|
|
|
|
+.address
|
|
|
|
::
|
|
|
|
++ address-from-cord
|
|
|
|
|= addrc=@t ^- address
|
|
|
|
?. ?| =("bc1" (scag 3 (trip addrc)))
|
|
|
|
=("tb1" (scag 3 (trip addrc)))
|
|
|
|
==
|
|
|
|
~|("legacy addresses not yet supported" !!)
|
|
|
|
[%bech32 addrc]
|
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-12-02 15:01:49 +03:00
|
|
|
|
2020-11-12 18:20:54 +03:00
|
|
|
::
|
|
|
|
++ 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)
|
2020-10-20 17:13:52 +03:00
|
|
|
::
|
2020-11-12 18:20:54 +03:00
|
|
|
++ to-hash256
|
|
|
|
|= h=@t
|
|
|
|
(hash256 [32 (to-hex h)])
|
|
|
|
::
|
2020-11-20 14:58:27 +03:00
|
|
|
++ to-btc-byts
|
|
|
|
|= h=@t
|
|
|
|
^- btc-byts
|
|
|
|
[(lent (trip h)) (to-hex h)]
|
|
|
|
::
|
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
|
|
|
::
|
|
|
|
++ gen-request
|
2020-11-12 18:20:54 +03:00
|
|
|
|= [=host-info ract=action:rpc]
|
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-10-20 13:44:31 +03:00
|
|
|
++ to-response
|
2020-10-23 20:35:04 +03:00
|
|
|
|= result:rpc
|
|
|
|
^- result
|
|
|
|
*result
|
2020-11-13 13:14:35 +03:00
|
|
|
++ parse-response
|
|
|
|
|= res=response:rpc:jstd
|
|
|
|
|^ ^- response:rpc
|
|
|
|
~| -.res
|
|
|
|
:: ignores RPC responses of %error, %fails and %batch
|
|
|
|
::
|
|
|
|
?> ?=(%result -.res)
|
|
|
|
?+ id.res ~|([%unsupported-response id.res] !!)
|
|
|
|
%get-address-info
|
|
|
|
[id.res (address-info res.res)]
|
2020-11-20 14:58:27 +03:00
|
|
|
::
|
|
|
|
%get-raw-tx
|
|
|
|
[id.res (raw-tx res.res)]
|
2020-11-12 18:20:54 +03:00
|
|
|
::
|
2020-11-13 13:14:35 +03:00
|
|
|
%get-block-count
|
|
|
|
[id.res (ni:dejs:format res.res)]
|
2020-11-16 19:30:50 +03:00
|
|
|
::
|
|
|
|
%get-block-and-fee
|
|
|
|
[id.res (block-and-fee res.res)]
|
2020-11-13 13:14:35 +03:00
|
|
|
==
|
|
|
|
++ address-info
|
|
|
|
%- ot:dejs:format
|
|
|
|
:~ [%utxos (as:dejs:format utxo)]
|
|
|
|
[%used bo:dejs:format]
|
2020-12-01 15:23:11 +03:00
|
|
|
[%block ni:dejs:format]
|
2020-11-12 18:20:54 +03:00
|
|
|
==
|
2020-11-13 13:14:35 +03:00
|
|
|
++ 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]
|
2020-12-02 15:01:49 +03:00
|
|
|
[%recvd (cu:dejs:format from-epoch ni:dejs:format)]
|
2020-11-12 18:20:54 +03:00
|
|
|
==
|
2020-11-20 14:58:27 +03:00
|
|
|
++ raw-tx
|
2020-11-20 16:22:24 +03:00
|
|
|
%- ot:dejs:format
|
|
|
|
:~ [%txid (cu:dejs:format to-hash256 so:dejs:format)]
|
|
|
|
[%rawtx (cu:dejs:format to-btc-byts so:dejs:format)]
|
|
|
|
==
|
2020-11-16 19:30:50 +03:00
|
|
|
++ block-and-fee
|
|
|
|
%- ot:dejs:format
|
2020-12-01 15:23:11 +03:00
|
|
|
:~ [%block ni:dejs:format]
|
2020-11-16 19:30:50 +03:00
|
|
|
[%fee ni:dejs:format]
|
|
|
|
==
|
2020-11-13 13:14:35 +03:00
|
|
|
--
|
|
|
|
::
|
|
|
|
++ rpc-action-to-http
|
|
|
|
|= [endpoint=@t ract=action:rpc]
|
|
|
|
|^ ^- request:http
|
|
|
|
%- get-request
|
|
|
|
?- -.ract
|
|
|
|
%get-address-info
|
2020-11-20 14:58:27 +03:00
|
|
|
%+ mk-url '/addresses/info/'
|
|
|
|
(address-to-cord address.ract)
|
|
|
|
::
|
|
|
|
%get-raw-tx
|
|
|
|
%+ mk-url '/getrawtx/'
|
|
|
|
(en:base16:mimes:html txid.ract)
|
2020-11-13 13:14:35 +03:00
|
|
|
::
|
|
|
|
%get-block-count
|
2020-11-20 14:58:27 +03:00
|
|
|
(mk-url '/getblockcount' '')
|
2020-11-16 19:30:50 +03:00
|
|
|
::
|
|
|
|
%get-block-and-fee
|
2020-11-20 14:58:27 +03:00
|
|
|
(mk-url '/getblockandfee' '')
|
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
|
|
|
|
^- response:rpc:jstd
|
|
|
|
~| hit
|
|
|
|
=/ jon=json (need (de-json:html q:(need r.hit)))
|
|
|
|
?. =(%2 (div p.hit 100))
|
|
|
|
(parse-rpc-error jon)
|
|
|
|
=, dejs-soft:format
|
|
|
|
^- response:rpc:jstd
|
|
|
|
=; dere
|
|
|
|
=+ res=((ar dere) jon)
|
|
|
|
?~ res (need (dere jon))
|
|
|
|
[%batch u.res]
|
|
|
|
|= jon=json
|
|
|
|
^- (unit response:rpc:jstd)
|
|
|
|
=/ 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
|
|
|
|
^- response:rpc:jstd
|
|
|
|
?> ?=(%finished -.response)
|
|
|
|
%- httr-to-rpc-response
|
|
|
|
%+ to-httr:iris
|
|
|
|
response-header.response
|
|
|
|
full-file.response
|
|
|
|
::
|
|
|
|
++ parse-rpc-error
|
|
|
|
|= =json
|
|
|
|
^- response:rpc:jstd
|
|
|
|
:- %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
|
|
|
--
|