mirror of
https://github.com/AthanorLabs/atomic-swap.git
synced 2026-01-10 06:38:04 -05:00
RPC and WS endpoints share the same port (#187)
Combine our HTTP RPC and Websocket services into a single HTTP server, eliminating the --ws-port flag to swapd and using --swapd-port flag for swapcli.
This commit is contained in:
@@ -34,7 +34,7 @@ Create a wallet for "Bob", who will own XMR later on:
|
||||
./monero-wallet-cli // you will be prompted to create a wallet. In the next steps, we will go with "Bob", without password. Remember the name and optionally the password for the upcoming steps
|
||||
```
|
||||
|
||||
You do not need to mine blocks, and you can exit the the wallet-cli once Bob's account has been created by typing "exit".
|
||||
You do not need to mine blocks, and you can exit the wallet-cli once Bob's account has been created by typing "exit".
|
||||
|
||||
Start monero-wallet-rpc for Bob on port 18083. Make sure `--wallet-dir` corresponds to the directory the wallet from the previous step is in:
|
||||
```bash
|
||||
@@ -98,13 +98,13 @@ In terminal 3, we will interact with the swap daemon using `swapcli`.
|
||||
|
||||
Firstly, we need Bob to make an offer and advertise it, so that Alice can take it:
|
||||
```bash
|
||||
./swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.05 --daemon-addr=http://localhost:5002
|
||||
./swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.05 --swapd-port 5002
|
||||
# Published offer with ID cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9
|
||||
```
|
||||
|
||||
Alternatively, you can make the offer via websockets and get notified when the swap is taken:
|
||||
```bash
|
||||
./swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.05 --daemon-addr=ws://localhost:8082 --subscribe
|
||||
./swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.05 --swapd-port 5002 --subscribe
|
||||
```
|
||||
|
||||
Now, we can have Alice begin discovering peers who have offers advertised.
|
||||
@@ -127,7 +127,7 @@ Now, we can tell Alice to initiate the protocol w/ the peer (Bob), the offer (co
|
||||
|
||||
Alternatively, you can take the offer via websockets and get notified when the swap status updates:
|
||||
```bash
|
||||
./swapcli take --multiaddr /ip4/127.0.0.1/tcp/9934/p2p/12D3KooWHLUrLnJtUbaGzTSi6azZavKhNgUZTtSiUZ9Uy12v1eZ7 --offer-id cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9 --provides-amount 0.05 --subscribe --daemon-addr=ws://localhost:8081
|
||||
./swapcli take --multiaddr /ip4/127.0.0.1/tcp/9934/p2p/12D3KooWHLUrLnJtUbaGzTSi6azZavKhNgUZTtSiUZ9Uy12v1eZ7 --offer-id cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9 --provides-amount 0.05 --subscribe --swapd-port 5001
|
||||
```
|
||||
|
||||
If all goes well, you should see Alice and Bob successfully exchange messages and execute the swap protocol. The result is that Alice now owns the private key to a Monero account (and is the only owner of that key) and Bob has the ETH transferred to him. On Alice's side, a Monero wallet will be generated in the `--wallet-dir` provided in the `monero-wallet-rpc` step for Alice.
|
||||
|
||||
@@ -258,7 +258,7 @@ Returns:
|
||||
|
||||
Example:
|
||||
```bash
|
||||
wscat -c ws://localhost:8081
|
||||
wscat -c ws://localhost:5001/ws
|
||||
# Connected (press CTRL+C to quit)
|
||||
# > {"jsonrpc":"2.0", "method":"swap_subscribeStatus", "params": {"id": "7492ceb4d0f5f45ecd5d06923b35cae406d1406cd685ce1ba184f2a40c683ac2"}, "id": 0}
|
||||
# < {"jsonrpc":"2.0","result":{"stage":"ETHLocked"},"error":null,"id":null}
|
||||
@@ -282,7 +282,7 @@ Returns:
|
||||
|
||||
Example (including notifications when swap is taken):
|
||||
```bash
|
||||
wscat -c ws://localhost:8082
|
||||
wscat -c ws://localhost:5002/ws
|
||||
# Connected (press CTRL+C to quit)
|
||||
# > {"jsonrpc":"2.0", "method":"net_makeOfferAndSubscribe", "params": {"minimumAmount": 0.1, "maximumAmount": 1, "exchangeRate": 0.05}, "id": 0}
|
||||
# < {"jsonrpc":"2.0","result":{"offerID":"cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9"},"error":null,"id":null}
|
||||
@@ -308,7 +308,7 @@ Returns:
|
||||
|
||||
Example:
|
||||
```bash
|
||||
wscat -c ws://localhost:8081
|
||||
wscat -c ws://localhost:5001/ws
|
||||
# Connected (press CTRL+C to quit)
|
||||
# > {"jsonrpc":"2.0", "method":"net_takeOfferAndSubscribe", "params": {"multiaddr": "/ip4/192.168.0.101/tcp/9934/p2p/12D3KooWHLUrLnJtUbaGzTSi6azZavKhNgUZTtSiUZ9Uy12v1eZ7", "offerID": "cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9", "providesAmount": 0.05}, "id": 0}
|
||||
# < {"jsonrpc":"2.0","result":{"id":0},"error":null,"id":null}
|
||||
@@ -316,4 +316,4 @@ wscat -c ws://localhost:8081
|
||||
# < {"jsonrpc":"2.0","result":{"stage":"ETHLocked"},"error":null,"id":null}
|
||||
# < {"jsonrpc":"2.0","result":{"stage":"ContractReady"},"error":null,"id":null}
|
||||
# < {"jsonrpc":"2.0","result":{"stage":"Success"},"error":null,"id":null}
|
||||
```
|
||||
```
|
||||
|
||||
@@ -93,7 +93,7 @@ yarn start
|
||||
|
||||
1. Search for existing XMR offers using `swapcli`:
|
||||
```bash
|
||||
./swapcli discover --provides XMR --search-time 3 --daemon-addr=http://localhost:5005
|
||||
./swapcli discover --provides XMR --search-time 3 --swapd-port 5001
|
||||
# [[/ip4/127.0.0.1/tcp/9934/p2p/12D3KooWC547RfLcveQi1vBxACjnT6Uv15V11ortDTuxRWuhubGv /ip4/127.0.0.1/tcp/9934/p2p/12D3KooWC547RfLcveQi1vBxACjnT6Uv15V11ortDTuxRWuhubGv]]
|
||||
```
|
||||
|
||||
@@ -113,7 +113,7 @@ yarn start
|
||||
|
||||
3. b. Alternatively, you can take the offer via websockets and get notified when the swap status updates:
|
||||
```bash
|
||||
./swapcli take --multiaddr /ip4/127.0.0.1/tcp/9934/p2p/12D3KooWHLUrLnJtUbaGzTSi6azZavKhNgUZTtSiUZ9Uy12v1eZ7 --offer-id cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9 --provides-amount 0.05 --subscribe --daemon-addr=ws://localhost:8081
|
||||
./swapcli take --multiaddr /ip4/127.0.0.1/tcp/9934/p2p/12D3KooWHLUrLnJtUbaGzTSi6azZavKhNgUZTtSiUZ9Uy12v1eZ7 --offer-id cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9 --provides-amount 0.05 --subscribe --swapd-port 5001
|
||||
```
|
||||
|
||||
If all goes well, you should see the node execute the swap protocol. If the swap ends successfully, a Monero wallet will be generated in the `--wallet-dir` provided in the `monero-wallet-rpc` step (so `./node-keys`) named `swap-deposit-wallet`. This wallet will contained the received XMR.
|
||||
@@ -140,13 +140,13 @@ If you don't have any luck with these, please message me on twitter/reddit (@eli
|
||||
|
||||
4. a. Make an offer with `swapcli`:
|
||||
```bash
|
||||
./swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.5 --daemon-addr http://localhost:5005
|
||||
./swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.5 --swapd-port 5001
|
||||
# Published offer with ID cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9
|
||||
```
|
||||
|
||||
4. b. Alternatively, make an offer and subscribe to updates on it with `swapcli`:
|
||||
```bash
|
||||
./swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.5 --daemon-addr ws://localhost:6005 --subscribe
|
||||
./swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.5 --swapd-port 5001 --subscribe
|
||||
# Published offer with ID cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user