Make subscribing the default behavior with --detached (#345)

This commit is contained in:
doonte
2023-03-07 21:40:11 +00:00
committed by GitHub
parent e1ffabb03f
commit 98f4e91ba1
3 changed files with 27 additions and 24 deletions

View File

@@ -38,7 +38,7 @@ const (
flagRelayerFee = "relayer-fee"
flagRelayerEndpoint = "relayer-endpoint"
flagSearchTime = "search-time"
flagSubscribe = "subscribe"
flagDetached = "detached"
)
var (
@@ -168,8 +168,8 @@ var (
Required: true,
},
&cli.BoolFlag{
Name: flagSubscribe,
Usage: "Subscribe to push notifications about the swap's status",
Name: flagDetached,
Usage: "Exit immediately instead of subscribing to notifications about the swap's status",
},
&cli.StringFlag{
Name: "eth-asset",
@@ -209,8 +209,8 @@ var (
Required: true,
},
&cli.BoolFlag{
Name: flagSubscribe,
Usage: "Subscribe to push notifications about the swap's status",
Name: flagDetached,
Usage: "Exit immediately instead of subscribing to notifications about the swap's status",
},
swapdPortFlag,
},
@@ -570,7 +570,7 @@ func runMake(ctx *cli.Context) error {
fmt.Printf("\tTaker Max: %s %s\n", otherMax.Text('f'), ethAsset)
}
if ctx.Bool(flagSubscribe) {
if !ctx.Bool(flagDetached) {
wsc, err := newWSClient(ctx) //nolint:govet
if err != nil {
return err
@@ -625,7 +625,7 @@ func runTake(ctx *cli.Context) error {
return err
}
if ctx.Bool(flagSubscribe) {
if !ctx.Bool(flagDetached) {
wsc, err := newWSClient(ctx)
if err != nil {
return err

View File

@@ -126,7 +126,9 @@ And Bob's balances with this command:
### Make a Swap Offer
Next we need Bob to make an offer and advertise it, so that Alice can take it:
Next we need Bob to make an offer and advertise it, so that Alice can take it. You
will get notified when the swap is taken. This command will block waiting for update
messages, so you will need to dedicate a separate terminal for it:
```bash
./bin/swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.05 --swapd-port 5001
```
@@ -137,13 +139,14 @@ Published:
Peer ID: 12D3KooWK7989g6xmAaEsKFPuZTj2CVknRxQuk7dFL55CC1rpEWW
Taker Min: 0.005 ETH
Taker Max: 0.05 ETH
> Stage updated: KeysExchanged
> Stage updated: XMRLocked
> Stage updated: Success
```
Alternatively, you can make the offer via websockets and get notified when the swap is
taken. This option will block waiting for update messages, so you will need to dedicate a
separate terminal for it:
Alternatively, you can make the offer without subscribing to swap updates:
```bash
./bin/swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.05 --swapd-port 5001 --subscribe
./bin/swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.05 --swapd-port 5001 --detached
```
### Discover Swap Offers
@@ -180,14 +183,6 @@ from the previous step to update the command below:
--offer-id 0xcc57d3d1b9d8186118f1f1581a8dc4dca0e5aa6c39a5255bd0c2ebb824cfe2eb \
--provides-amount 0.05
```
Alternatively, you can take the offer via websockets and get notified when the swap status updates.
```bash
./bin/swapcli take \
--peer-id 12D3KooWAE3zH374qcxyFCA8B5g1uMqhgeiHoXT5KKD6A54SGGsp \
--offer-id 0xcc57d3d1b9d8186118f1f1581a8dc4dca0e5aa6c39a5255bd0c2ebb824cfe2eb \
--provides-amount 0.05 --subscribe
```
```
Initiated swap with offer ID 0xcc57d3d1b9d8186118f1f1581a8dc4dca0e5aa6c39a5255bd0c2ebb824cfe2eb
> Stage updated: ExpectingKeys
@@ -196,6 +191,14 @@ Initiated swap with offer ID 0xcc57d3d1b9d8186118f1f1581a8dc4dca0e5aa6c39a5255bd
> Stage updated: Success
```
Alternatively, you can take the offer without subscribing to swap updates:
```bash
./bin/swapcli take \
--peer-id 12D3KooWAE3zH374qcxyFCA8B5g1uMqhgeiHoXT5KKD6A54SGGsp \
--offer-id 0xcc57d3d1b9d8186118f1f1581a8dc4dca0e5aa6c39a5255bd0c2ebb824cfe2eb \
--provides-amount 0.05 --detached
```
If all goes well, you should see Alice and Bob successfully exchange messages and execute
the swap protocol.

View File

@@ -122,11 +122,11 @@ yarn start
# Initiated swap with ID=0
```
3. b. Alternatively, you can take the offer via websockets and get notified when the swap status updates:
3. b. Alternatively, you can take the offer without getting notified of swap status updates:
```bash
./bin/swapcli take --peer-id 12D3KooWHLUrLnJtUbaGzTSi6azZavKhNgUZTtSiUZ9Uy12v1eZ7 \
--offer-id 0xcf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9 \
--provides-amount 0.05 --subscribe --swapd-port 5001
--provides-amount 0.05 --detached --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.
@@ -152,9 +152,9 @@ If you don't have any luck with these, please message me on twitter/reddit (@eli
# Published offer with ID cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9
```
4. b. Alternatively, make an offer and subscribe to updates on it with `swapcli`:
4. b. Alternatively, make an offer with `swapcli` without subscribing to updates:
```bash
./bin/swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.5 --swapd-port 5001 --subscribe
./bin/swapcli make --min-amount 0.1 --max-amount 1 --exchange-rate 0.5 --swapd-port 5001 --detached
# Published offer with ID cf4bf01a0775a0d13fa41b14516e4b89034300707a1754e0d99b65f6cb6fffb9
```