diff --git a/app/btc-provider.hoon b/app/btc-provider.hoon index 0c639852af..27473880d9 100644 --- a/app/btc-provider.hoon +++ b/app/btc-provider.hoon @@ -1,9 +1,8 @@ -:: btc-provider.hoon +:: btc-provider.hoon :: Proxy that serves a BTC full node and ElectRS address indexer :: -/- *btc-provider, bnh=btc-node-hook -/+ dbug, default-agent, base64, blib=btc-node-json, elib=electrum-rpc-http +/+ *btc-provider, dbug, default-agent, base64, blib=btc-node-json, elib=electrum-rpc |% +$ versioned-state $% state-0 @@ -225,7 +224,7 @@ ++ electrum-http-response |= [status=@ud rpc-resp=response:rpc:jstd] ^- (quip card _state) - ~& > rpc-resp + ~& >> (parse-response:electrum-rpc:elib rpc-resp) `state :: -- diff --git a/bippy-scratch.md b/bippy-scratch.md index 1ad6cefbcb..30549e1084 100644 --- a/bippy-scratch.md +++ b/bippy-scratch.md @@ -3,7 +3,7 @@ The below requires norsyr's fix to `decompress-point` in order to work. ## 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|rpc-action [%brpc %get-block-count ~] diff --git a/lib/btc-provider.hoon b/lib/btc-provider.hoon new file mode 100644 index 0000000000..41e19ad818 --- /dev/null +++ b/lib/btc-provider.hoon @@ -0,0 +1,10 @@ +/- sur=btc-provider, *btc +^? +=< [sur .] +=, sur +|% +++ to-response + |= response:rpc + ^- response:sur + [%get-address-info *address-info] +-- diff --git a/lib/electrum-rpc-http.hoon b/lib/electrum-rpc-http.hoon deleted file mode 100644 index 2faad087c9..0000000000 --- a/lib/electrum-rpc-http.hoon +++ /dev/null @@ -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) - == - -- --- diff --git a/lib/electrum-rpc.hoon b/lib/electrum-rpc.hoon new file mode 100644 index 0000000000..9aaa81f4f9 --- /dev/null +++ b/lib/electrum-rpc.hoon @@ -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) + == + -- +-- diff --git a/sur/btc-node-hook.hoon b/sur/btc-node-hook.hoon index 82d0eb7f22..e5d55b0589 100644 --- a/sur/btc-node-hook.hoon +++ b/sur/btc-node-hook.hoon @@ -574,10 +574,7 @@ +$ btc-node-hook-command command:btc-rpc :: Expand the response type to include connectivity :: -+$ btc-node-hook-response - $% [%status connected=? status-code=@ud] - response:btc-rpc - == ++$ btc-node-hook-response response:btc-rpc :: ++ btc-rpc |% diff --git a/sur/btc-provider.hoon b/sur/btc-provider.hoon index fb9bdd4d8d..bf4029879e 100644 --- a/sur/btc-provider.hoon +++ b/sur/btc-provider.hoon @@ -25,6 +25,10 @@ $% [%erpc request:electrum:rpc] [%brpc request:bitcoin-core:rpc] == ++$ rpc-response + $% [%erpc response:electrum:rpc] + [%brpc response:bitcoin-core:rpc] + == ++ rpc |% ++ electrum @@ -33,10 +37,14 @@ $% [%get-address-balance =address] [%get-address-utxos =address] == + +$ response + $% [%get-address-utxos utxos=(set utxo)] + == -- ++ bitcoin-core |% +$ request btc-node-hook-action:bnh + +$ response btc-node-hook-response:bnh -- -- --