mirror of
https://github.com/ilyakooo0/urbit.git
synced 2025-01-03 04:40:50 +03:00
support for req-id
This commit is contained in:
parent
3ce9600a10
commit
c933100d80
@ -4,12 +4,12 @@ The below requires norsyr's fix to `decompress-point` in order to work.
|
||||
## Set Credentials and Ping Servers
|
||||
(don't need password if all run on localhost)
|
||||
```
|
||||
=rpc-pass 'c7dc0698a2e3a5d66096152b34c273b8fbcc821e9d49f2ac706e38307d3441c5'
|
||||
=rpc-pass 'c55932944eee4de272a22678b9592a25782283e76361fbe671369616e18b1f46'
|
||||
:btc-provider|command [%set-credentials [rpc-url='http://localhost:8332' rpc-user='__cookie__' rpc-pass] [rpc-url='http://localhost:50002']]
|
||||
|
||||
:btc-provider|action [%address-info [%bech32 'bc1q59u5epktervh6fxqay2dlph0wxu9hjnx6v8n66']]
|
||||
:btc-provider|action [%address-info [%bech32 'bc1qlwd7mw33uea5m8r2lsnsrkc7gp2qynrxsfxpfm']]
|
||||
:btc-provider|action [%address-info [%bech32 'bc1qglkc9zfcn04vcc88nn0ljtxcpu5uxfznc3829k']]
|
||||
:btc-provider|action ['addr0' %address-info [%bech32 'bc1q59u5epktervh6fxqay2dlph0wxu9hjnx6v8n66']]
|
||||
:btc-provider|action ['addr1' %address-info [%bech32 'bc1qlwd7mw33uea5m8r2lsnsrkc7gp2qynrxsfxpfm']]
|
||||
:btc-provider|action ['addr2' %address-info [%bech32 'bc1qglkc9zfcn04vcc88nn0ljtxcpu5uxfznc3829k']]
|
||||
:: first is an address w balance
|
||||
:: second has no balance but is used
|
||||
:: third is unused
|
||||
|
@ -73,7 +73,7 @@
|
||||
:_ this
|
||||
:~ :* %pass /ping/[(scot %da now.bowl)] %agent
|
||||
[our.bowl %btc-provider] %poke
|
||||
%btc-provider-action !>([%ping ~])
|
||||
%btc-provider-action !>([%blank-id %ping ~])
|
||||
==
|
||||
(start-ping-timer:hc ~s30)
|
||||
==
|
||||
@ -107,13 +107,13 @@
|
||||
++ handle-action
|
||||
|= act=action
|
||||
^- (quip card _state)
|
||||
?. ?|(connected.host-info =(-.act %ping))
|
||||
?. ?|(connected.host-info =(-.body.act %ping))
|
||||
~& >>> "Not connected to RPC"
|
||||
[~[(send-update [%| [%not-connected 500]])] state]
|
||||
[~[(send-update [%| %not-connected 500])] state]
|
||||
=/ ract=action:rpc
|
||||
?- -.act
|
||||
?- -.body.act
|
||||
%address-info
|
||||
[%erpc %get-address-utxos address.act]
|
||||
[%erpc %get-address-utxos address.body.act]
|
||||
::
|
||||
%ping
|
||||
[%brpc %get-block-count ~]
|
||||
@ -125,16 +125,21 @@
|
||||
=/ req=request:http
|
||||
(gen-request host-info ract)
|
||||
[%pass (mk-wire act ract) %arvo %i %request req out]
|
||||
:: wire structure: /action-tas/rpc-action-tas/(address, if rpc-action %erpc)/now
|
||||
:: wire structure: /action-tas/rpc-action-tas/req-id/(address, if rpc-action %erpc)/now
|
||||
::
|
||||
++ mk-wire
|
||||
|= [act=action ract=action:rpc]
|
||||
^- wire
|
||||
=/ addr=path
|
||||
?:(?=(%erpc -.ract) /(address-to-cord:elib address.ract) /)
|
||||
%- zing ~[/[-.act]/[-.ract] addr /[(scot %da now.bowl)]]
|
||||
:: TODO: write up how some responses can trigger a req-card to get more info (i.e. used
|
||||
:: that happens when multiple RPC calls have to be collated into one response
|
||||
%- zing
|
||||
:~ /[-.body.act]/[-.ract]/[req-id.act]
|
||||
addr
|
||||
/[(scot %da now.bowl)]
|
||||
==
|
||||
:: Handles HTTP responses from RPC servers. Parses for errors, then handles response.
|
||||
:: For actions that require collating multiple RPC calls, uses req-card to call out
|
||||
:: to RPC again if more information is required.
|
||||
::
|
||||
++ handle-rpc-response
|
||||
|= [=wire response=client-response:iris]
|
||||
@ -155,29 +160,33 @@
|
||||
:: no error, switch on wire to handle RPC data
|
||||
::
|
||||
?+ wire ~|("Unexpected HTTP response" !!)
|
||||
[%address-info %erpc @ *]
|
||||
=/ addr=address:btc (address-from-cord:elib +>-.wire)
|
||||
=/ eresp (parse-response:electrum-rpc:elib rpc-resp)
|
||||
:_ state
|
||||
^- (list card)
|
||||
:~ ?- -.eresp
|
||||
%get-address-utxos
|
||||
?: =(0 ~(wyt in utxos.eresp))
|
||||
(req-card [%address-info addr] [%erpc %get-address-history addr])
|
||||
(send-update [%& %address-info addr utxos.eresp %.y])
|
||||
::
|
||||
%get-address-history
|
||||
%- send-update
|
||||
:* %& %address-info addr *(set utxo:btc)
|
||||
?:(=(0 ~(wyt in txs.eresp)) %.n %.y)
|
||||
==
|
||||
==
|
||||
==
|
||||
[%address-info %erpc @ @ *]
|
||||
[(handle-address-info wire rpc-resp) state]
|
||||
::
|
||||
[%ping %brpc *]
|
||||
`state(connected.host-info %.y)
|
||||
==
|
||||
::
|
||||
++ handle-address-info
|
||||
|= [=wire rpc-resp=response:rpc:jstd]
|
||||
^- (list card)
|
||||
=/ req-id=@t +>-.wire
|
||||
=/ addr=address:btc (address-from-cord:elib +>+<.wire)
|
||||
=/ eresp (parse-response:electrum-rpc:elib rpc-resp)
|
||||
:~ ?- -.eresp
|
||||
%get-address-utxos
|
||||
?: =(0 ~(wyt in utxos.eresp))
|
||||
(req-card [req-id %address-info addr] [%erpc %get-address-history addr])
|
||||
(send-update [%& req-id %address-info addr utxos.eresp %.y])
|
||||
::
|
||||
%get-address-history
|
||||
%- send-update
|
||||
:* %& req-id %address-info addr *(set utxo:btc)
|
||||
?:(=(0 ~(wyt in txs.eresp)) %.n %.y)
|
||||
==
|
||||
==
|
||||
==
|
||||
::
|
||||
++ connection-error
|
||||
|= status=@ud
|
||||
^- [(unit error) _state]
|
||||
@ -195,7 +204,8 @@
|
||||
==
|
||||
::
|
||||
++ send-update
|
||||
|= =update ^- card
|
||||
|= =update
|
||||
^- card
|
||||
~& >> "send-update: {<update>}"
|
||||
[%give %fact [/clients]~ %btc-provider-update !>(update)]
|
||||
::
|
||||
|
@ -12,7 +12,7 @@
|
||||
:: Sends updates to:
|
||||
:: none
|
||||
::
|
||||
/- *btc, *btc-wallet-hook, bws=btc-wallet-store
|
||||
/- *btc, *btc-wallet-hook, bws=btc-wallet-store, bp=btc-provider
|
||||
/+ shoe, dbug, default-agent, bwsl=btc-wallet-store
|
||||
|%
|
||||
+$ versioned-state
|
||||
@ -147,4 +147,7 @@
|
||||
:* %pass /[(scot %da now.bowl)] %agent [host %btc-provider]
|
||||
%poke %btc-provider-action !>([%get-address-info a])
|
||||
==
|
||||
++ mk-req-id
|
||||
|= hash=@ux ^- req-id:bp
|
||||
(scot %ux hash)
|
||||
--
|
||||
|
@ -4,11 +4,13 @@
|
||||
+$ electrum-credentials [rpc-url=@t]
|
||||
+$ credentials [bc=btc-credentials ec=electrum-credentials]
|
||||
+$ host-info [creds=credentials connected=? clients=(set ship)]
|
||||
+$ action
|
||||
+$ action [req-id=@t body=action-body]
|
||||
+$ action-body
|
||||
$% [%address-info =address]
|
||||
[%ping ~]
|
||||
==
|
||||
+$ result
|
||||
+$ result [req-id=@t body=result-body]
|
||||
+$ result-body
|
||||
$% [%address-info a=address utxos=(set utxo) used=?]
|
||||
==
|
||||
+$ error
|
||||
@ -18,7 +20,7 @@
|
||||
[%http-error status=@ud]
|
||||
[%rpc-error ~]
|
||||
==
|
||||
+$ update (each result error) :: sub updates to /clients path (connection etc.)
|
||||
+$ update (each result error)
|
||||
::
|
||||
+$ command
|
||||
$% [%set-credentials creds=credentials]
|
||||
|
@ -1,12 +1,11 @@
|
||||
/- *btc, bws=btc-wallet-store
|
||||
/- *btc, bws=btc-wallet-store, bp=btc-provider
|
||||
|%
|
||||
:: req-id: hash of [xpub chyg idx]
|
||||
:: addo: wallet index to send result of request to
|
||||
:: back: lookup table of req-id -> addo
|
||||
::
|
||||
+$ req-id @ux
|
||||
+$ addo [=xpub =chyg:bws =idx:bws]
|
||||
+$ back (map req-id addo)
|
||||
+$ back (map req-id:bp addo)
|
||||
+$ action
|
||||
$% [%set-provider provider=ship]
|
||||
==
|
||||
|
Loading…
Reference in New Issue
Block a user