Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API BSQ swap simulation script and doc updates #5 #5876

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5924312
Adjust bsq-swap-offer related gRPC services & msgs
ghubstan Nov 11, 2021
c6aceb0
Adjust bsq-swap-offer related gRPC daemon services
ghubstan Nov 11, 2021
5d63fd7
Partially adjust api proto wrappers for bsq-swap support
ghubstan Nov 11, 2021
713b309
Add String getRole(BsqSwapTrade trade) method
ghubstan Nov 11, 2021
521495c
Add conveniences isFiatOffer(offer), isAltcoinOffer(offer)
ghubstan Nov 11, 2021
3dfbf3f
Partially adjust core api for bsq-swap support
ghubstan Nov 11, 2021
16be357
Paritally adjust bsq-swap-offer related gRPC CLI side classes
ghubstan Nov 11, 2021
c5f50b5
Paritally adjust bsq-swap-offer related apitest cases
ghubstan Nov 11, 2021
564303a
Normalize API gRPC bsq-swap related protos & wrappers
ghubstan Nov 12, 2021
9f01279
Merge branch 'master' into 1-basic-api-bsqswap-support
ghubstan Nov 12, 2021
fc53ca4
Add CLI output IntegerColumn
ghubstan Nov 14, 2021
4ca878a
Adjust API 'gettrade' for Bsq swaps
ghubstan Nov 14, 2021
d8f1e44
Try to hide from pesky codacy
ghubstan Nov 14, 2021
b65cc9c
Merge branch 'master' into 1-basic-api-bsqswap-support
ghubstan Nov 23, 2021
17277c4
Remove Get/Take BSQSwap Offer/Trade rpc service defs
ghubstan Nov 24, 2021
f88c151
Refactor GrpcTradesService: use GetTrade & TakeOffer services for BSQ…
ghubstan Nov 24, 2021
3aae052
Refactor core.api trade service implemenentations for BSQ swaps
ghubstan Nov 24, 2021
0c5c343
Adjust CLI to support getting/taking BSQ swaps
ghubstan Nov 24, 2021
6403fc1
Adjust apitest cases to rpc BSQ wwap related changes
ghubstan Nov 24, 2021
c177b3b
Merge branch 'master' into 2-api-bsq-swap-scratch
ghubstan Nov 24, 2021
00a5e2b
Merge branch 'master' into 2-refactor-api-bsqswap-support
ghubstan Nov 25, 2021
3077be5
Remove API createoffer's paymentAcctId request param (BSQ swap)
ghubstan Nov 25, 2021
b1c872c
Adjust createoffer opt parser/test for bsq swaps
ghubstan Nov 25, 2021
35aeb61
Adjust createoffer opt parser for bsq swaps
ghubstan Nov 25, 2021
eff1084
Tighten createoffer param validation (only bsq swaps supported)
ghubstan Nov 25, 2021
15621d4
Re-@Disable method tests (don't run 2x from gradle)
ghubstan Nov 25, 2021
132ecc9
Adjust CliMain's createoffer for BSQ swaps
ghubstan Nov 25, 2021
0aa0852
Add CLI createoffer smoketest (for bsq swaps)
ghubstan Nov 25, 2021
05d1916
Fix help text typo
ghubstan Nov 26, 2021
64f228d
Make rpc GetOfferCategory service work for my+avail offers
ghubstan Nov 27, 2021
b95e4b3
Block attempts to edit BsqSwap offers from CLI
ghubstan Nov 27, 2021
000fe9b
Test blocking attempts to edit BsqSwap offers on server
ghubstan Nov 27, 2021
b5981b5
There is no --swap opt in editoffer command
ghubstan Nov 27, 2021
0d8559d
Force rebuild after github action ECONNRESET
ghubstan Nov 27, 2021
66115f3
Revert "There is no --swap opt in editoffer command"
ghubstan Nov 28, 2021
1b7e43a
Add apitest/scripts/bsqswap-simulation.sh script
ghubstan Nov 28, 2021
8b2dec7
Remove unused function outputs
ghubstan Nov 28, 2021
6b89254
Adjust core api method help docs for bsq swaps
ghubstan Nov 29, 2021
b1dd205
Allow unrecognized options in OfferIdOptionParser where appropriate
ghubstan Nov 29, 2021
a1db0d1
Update API docs for Bitcoin Core version v22.0
ghubstan Nov 29, 2021
3015554
Adjust API beta-test guide for BSQ swaps
ghubstan Nov 29, 2021
946ca46
Merge branch 'master' into 5-api-bsqswap-simulation-n-docs-update
ghubstan Nov 30, 2021
bb68605
Add missing --currency-code=bsq param to createoffer example
ghubstan Dec 3, 2021
f195b76
Tell user bsqswap offer cannot be edited, but can be canceled at no c…
ghubstan Dec 3, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions apitest/docs/api-beta-test-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ option adjustments to compensate.

**Shell**: Bash

**Java SDK**: Version 10, 11, 12 or 15
**Java SDK**: Version 11 - 15 (src and class generation version 11)

**Bitcoin-Core**: Version 0.19, 0.20, or 0.21
**Bitcoin-Core**: Version 0.19 - 22

**Git Client**

Expand Down Expand Up @@ -372,6 +372,22 @@ The `trade-simulation.sh` script options that would generate the previous `creat
$ apitest/scripts/trade-simulation.sh -d sell -c jp -m 0.5 -a 0.125
```

The `createoffer` command can also be used to create BSQ swap offers, where trade execution is performed immediately
after a BSQ swap offer is taken. To swap 0.5 BTC for BSQ at a price of 0.00005 BSQ per 1 BTC:
```
$ ./bisq-cli --password=xyz --port=9998 createoffer \
--swap=true \
--direction=BUY \
--amount=0.5 \
--currency-code=BSQ \
--fixed-price=0.00005
```

The `bsqswap-simulation.sh` script options that would generate the previous `createoffer` example is:
```
$ apitest/scripts/bsqswap-simulation.sh -d buy -a 0.5 -f 0.00005
```

### Browsing Your Own Offers

There are different commands to browse available offers you can take, and offers you created.
Expand Down Expand Up @@ -530,16 +546,18 @@ A CLI user browses available offers with the getoffers command. For example, th
$ ./bisq-cli --password=xyz --port=9998 getoffers --direction=SELL --currency-code=EUR
```

And takes one of the available offers with an EUR payment account ( id `fe20cdbd-22be-4b8a-a4b6-d2608ff09d6e`)
Then takes one of the available offers with an EUR payment account ( id `fe20cdbd-22be-4b8a-a4b6-d2608ff09d6e`)
with the `takeoffer` command:
```
$ ./bisq-cli --password=xyz --port=9998 takeoffer \
--offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea \
--payment-account=fe20cdbd-22be-4b8a-a4b6-d2608ff09d6e \
--fee-currency=btc
```
The taken offer will be used to create a trade contract. The next section describes how to use the Api to execute
the trade.
Depending on the offer type, the taken offer will be used to (1) create a trade contract, or (2) execute a BSQ swap.

The next section describes how to use the Api to execute a trade. The following <b>Completing a BSQ Swap Trade</b>
section explains how to use the `takeoffer` command to complete a BSQ swap.

### Completing Trade Protocol

Expand Down Expand Up @@ -598,6 +616,14 @@ $ ./bisq-cli --password=xyz --port=9998 keepfunds --trade-id=<trade-id>
$ ./bisq-cli --password=xyz --port=9999 withdrawfunds --trade-id=<trade-id> --address=<btc-address> [--memo=<"memo">]
```

### Completing a BSQ Swap Trade

The `takeoffer` command will immediately perform the BSQ swap, assuming both sides' wallets have sufficient BTC and
BSQ to cover the trade amount, and maker or taker fee. It takes one argument: `--offer-id=<offer-id>`:
```
$ ./bisq-cli --password=xyz --port=9998 takeoffer --offer-id=Xge8b2e2-51b6-3TOOB-z748-3ebd29c2kj99
```

## Shutting Down Test Harness

The test harness should cleanly shutdown all the background apps in proper order after entering ^C.
Expand Down
2 changes: 1 addition & 1 deletion apitest/docs/build-run.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The Java based API runs on Linux and OSX.

## Mainnet

To build from the source, clone the github repository found at `https://github.com/bisq-network/bisq`,
To build from the source, clone the GitHub repository found at `https://github.com/bisq-network/bisq`,
and build with gradle:

$ ./gradlew clean build
Expand Down
79 changes: 79 additions & 0 deletions apitest/scripts/bsqswap-simulation-utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#! /bin/bash

# This file must be sourced by the driver script.

source "$APITEST_SCRIPTS_HOME/trade-simulation-env.sh"
source "$APITEST_SCRIPTS_HOME/trade-simulation-utils.sh"

gencreatebsqswapoffercommand() {
PORT="$1"
CMD="$CLI_BASE --port=$PORT createoffer"
CMD+=" --swap=true"
CMD+=" --direction=$DIRECTION"
CMD+=" --amount=$AMOUNT"
CMD+=" --fixed-price=$FIXED_PRICE"
CMD+=" --currency-code=$CURRENCY_CODE"
echo "$CMD"
}

createbsqswapoffer() {
CREATE_OFFER_CMD="$1"
OFFER_DESC=$($CREATE_OFFER_CMD)

# If the CLI command exited with an error, print the CLI error, and
# return from this function now, passing the error status code to the caller.
commandalert $? "Could not create offer."

OFFER_DETAIL=$(echo -e "$OFFER_DESC" | sed -n '2p')
NEW_OFFER_ID=$(echo -e "$OFFER_DETAIL" | awk '{print $NF}')
echo "$NEW_OFFER_ID"
}

executebsqswap() {
# Bob list available BSQ offers. (If a v1 BSQ offer is picked this simulation will break.)
printdate "Bob looking at $DIRECTION $CURRENCY_CODE offers."
CMD="$CLI_BASE --port=$BOB_PORT getoffers --direction=$DIRECTION --currency-code=$CURRENCY_CODE"
printdate "BOB CLI: $CMD"
OFFERS=$($CMD)
exitoncommandalert $?
echo "$OFFERS"
printbreak

OFFER_ID=$(getfirstofferid "$BOB_PORT")
exitoncommandalert $?
printdate "First BSQ offer found: $OFFER_ID"

# Take Alice's BSQ swap offer.
CMD="$CLI_BASE --port=$BOB_PORT takeoffer --offer-id=$OFFER_ID"
printdate "BOB CLI: $CMD"
TRADE=$($CMD)
commandalert $? "Could not take BSQ swap offer."
# Print the takeoffer command's console output.
printdate "$TRADE"
printbreak

# Generate 1 btc block
printdate "Generating 1 btc block after BSQ swap execution."
genbtcblocks 1 2
printbreak

printdate "BSQ swap trade $OFFER_ID complete."
printbreak

printdate "Alice looking at her trade with id $OFFER_ID."
CMD="$CLI_BASE --port=$ALICE_PORT gettrade --trade-id=$OFFER_ID"
printdate "ALICE CLI: $CMD"
GETTRADE_CMD_OUTPUT=$(gettrade "$CMD")
exitoncommandalert $?
echo "$GETTRADE_CMD_OUTPUT"
printbreak

printdate "Bob looking at his trade with id $OFFER_ID."
CMD="$CLI_BASE --port=$BOB_PORT gettrade --trade-id=$OFFER_ID"
printdate "BOB CLI: $CMD"
GETTRADE_CMD_OUTPUT=$(gettrade "$CMD")
exitoncommandalert $?
echo "$GETTRADE_CMD_OUTPUT"
printbreak
}

90 changes: 90 additions & 0 deletions apitest/scripts/bsqswap-simulation.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#! /bin/bash

# Demonstrates a bsq <-> btc swap trade using the API CLI with a local regtest bitcoin node.
#
# Prerequisites:
#
# - Linux or OSX with bash, Java 11-15 (JDK language compatibility 11), and bitcoin-core (v0.19 - v22).
#
# - Bisq must be fully built with apitest dao setup files installed.
# Build command: `./gradlew clean build :apitest:installDaoSetup`
#
# - All supporting nodes must be run locally, in dev/dao/regtest mode:
# bitcoind, seednode, arbdaemon, alicedaemon, bobdaemon
#
# These should be run using the apitest harness. From the root project dir, run:
# `$ ./bisq-apitest --apiPassword=xyz --supportingApps=bitcoind,seednode,arbdaemon,alicedaemon,bobdaemon --shutdownAfterTests=false`
#
# Usage:
#
# This script must be run from the root of the project, e.g.:
#
# `$ apitest/scripts/bsqswap-simulation.sh -d buy -f 0.00005 -a 0.125`
#
# Script options: -d <direction> -c <country-code> -f <fixed-price> -a <amount(btc)>
#
# Examples:
#
# Create and take a bsq swap offer to buy 0.05 btc at a fixed-price of 0.00005 bsq (per 1 btc):
#
# `$ apitest/scripts/bsqswap-simulation.sh -d buy -a 0.05 -f 0.00005`
#
# Create and take a bsq swap offer to buy 1 btc at a fixed-price of 0.00005 bsq (per 1 btc):
#
# `$ apitest/scripts/bsqswap-simulation.sh -d buy -a 1 -f 0.0005`

export APP_BASE_NAME=$(basename "$0")
export APP_HOME=$(pwd -P)
export APITEST_SCRIPTS_HOME="$APP_HOME/apitest/scripts"

source "$APITEST_SCRIPTS_HOME/trade-simulation-env.sh"
source "$APITEST_SCRIPTS_HOME/trade-simulation-utils.sh"
source "$APITEST_SCRIPTS_HOME/bsqswap-simulation-utils.sh"

checksetup
parsebsqswaporderopts "$@"

printdate "Started $APP_BASE_NAME with parameters:"
printbsqswapscriptparams
printbreak

# Alice creates a bsq swap offer.
printdate "Alice creating BSQ swap offer: $DIRECTION $AMOUNT BTC for BSQ at fixed price of $FIXED_PRICE BTC per 1 BSQ."
CMD=$(gencreatebsqswapoffercommand "$ALICE_PORT" "$ALICE_ACCT_ID")
printdate "ALICE CLI: $CMD"
OFFER_ID=$(createbsqswapoffer "$CMD")
exitoncommandalert $?
printdate "Alice created bsq swap offer with id: $OFFER_ID."
printbreak
sleeptraced 2

# Show Alice's new bsq swap offer.
printdate "Alice looking at her new $DIRECTION $CURRENCY_CODE offer."
CMD="$CLI_BASE --port=$ALICE_PORT getmyoffer --offer-id=$OFFER_ID"
printdate "ALICE CLI: $CMD"
OFFER=$($CMD)
exitoncommandalert $?
echo "$OFFER"
printbreak
sleeptraced 2

# Generate 1 btc block.
printdate "Generating 1 btc block after publishing Alice's offer."
genbtcblocks 1 1
printbreak

# Execute the BSQ swap.
executebsqswap
exitoncommandalert $?
printbreak

# Get balances after trade completion.
printdate "Bob & Alice's balances after BSQ swap trade."
printdate "ALICE CLI:"
printbalances "$ALICE_PORT"
printbreak
printdate "BOB CLI:"
printbalances "$BOB_PORT"
printbreak

exit 0
2 changes: 1 addition & 1 deletion apitest/scripts/limit-order-simulation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#
# Prerequisites:
#
# - Linux or OSX with bash, Java 10, or Java 11-12 (JDK language compatibility 10), and bitcoin-core (v0.19, v0.20, v0.21).
# - Linux or OSX with bash, Java 11-15 (JDK language compatibility 11), and bitcoin-core (v0.19 - v22).
#
# - Bisq must be fully built with apitest dao setup files installed.
# Build command: `./gradlew clean build :apitest:installDaoSetup`
Expand Down
2 changes: 1 addition & 1 deletion apitest/scripts/rolling-offer-simulation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# Prerequisites:
#
# - Linux or OSX with bash, Java 10, or Java 11-12 (JDK language compatibility 10), and bitcoin-core (v0.19, v0.20, v0.21).
# - Linux or OSX with bash, Java 11-15 (JDK language compatibility 11), and bitcoin-core (v0.19 - v22).
#
# - Bisq must be fully built with apitest dao setup files installed.
# Build command: `./gradlew clean build :apitest:installDaoSetup`
Expand Down
41 changes: 41 additions & 0 deletions apitest/scripts/trade-simulation-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,41 @@ parselimitorderopts() {
fi
}

parsebsqswaporderopts() {
usage() {
echo "Usage: $0 [-d buy|sell] [-f <fixed-price>] [-a <amount in btc>]" 1>&2
exit 1;
}

local OPTIND o d f a
while getopts "d:f:a:" o; do
case "${o}" in
d) d=$(echo "${OPTARG}" | tr '[:lower:]' '[:upper:]')
((d == "BUY" || d == "SELL")) || usage
export DIRECTION=${d}
;;
f) f=${OPTARG}
export FIXED_PRICE=${f}
;;
a) a=${OPTARG}
export AMOUNT=${a}
;;
*) usage ;;
esac
done
shift $((OPTIND-1))

if [ -z "${d}" ] || [ -z "${a}" ]; then
usage
fi

if [ -z "${f}" ] ; then
usage
fi

export CURRENCY_CODE="BSQ"
}

checkbitcoindrunning() {
# There may be a '+' char in the path and we have to escape it for pgrep.
if [[ $APP_HOME == *"+"* ]]; then
Expand Down Expand Up @@ -310,3 +345,9 @@ printscriptparams() {
echo " WAIT = $WAIT"
fi
}

printbsqswapscriptparams() {
echo " DIRECTION = $DIRECTION"
echo " FIXED_PRICE = $FIXED_PRICE"
echo " AMOUNT = $AMOUNT"
}
11 changes: 5 additions & 6 deletions apitest/scripts/trade-simulation-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,10 @@ delayconfirmpaymentreceived() {
printbreak
}

# This is a large function that should be broken up if it ever makes sense to not treat a trade
# execution simulation as an bsq swap operation. But we are not testing api methods here, just
# demonstrating how to use them to get through the trade protocol. It should work for any trade
# between Bob & Alice, as long as Alice is maker, Bob is taker, and the offer to be taken is the
# first displayed in Bob's getoffers command output.
# This is a large function that might be split into smaller functions. But we are not testing
# api methods here, just demonstrating how to use them to get through the V1 trade protocol with
# the CLI. It should work for any trade between Bob & Alice, as long as Alice is maker, Bob is
# taker, and the offer to be taken is the first displayed in Bob's getoffers command output.
executetrade() {
# Bob list available offers.
printdate "BOB $BOB_ROLE: Looking at $DIRECTION $CURRENCY_CODE offers."
Expand All @@ -477,7 +476,7 @@ executetrade() {
printdate "First offer found: $OFFER_ID"

# Take Alice's offer.
CMD="$CLI_BASE --port=$BOB_PORT takeoffer --offer-id=$OFFER_ID --payment-account=$BOB_ACCT_ID --fee-currency=bsq"
CMD="$CLI_BASE --port=$BOB_PORT takeoffer --offer-id=$OFFER_ID --payment-account=$BOB_ACCT_ID --fee-currency=BSQ"
printdate "BOB CLI: $CMD"
TRADE=$($CMD)
commandalert $? "Could not take offer."
Expand Down
13 changes: 6 additions & 7 deletions apitest/scripts/trade-simulation.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#! /bin/bash

# Runs fiat <-> btc trading scenarios using the API CLI with a local regtest bitcoin node.
# Demonstrates a fiat <-> btc trade using the API CLI with a local regtest bitcoin node.
#
# A country code argument is used to create a country based face to face payment account for the simulated
# trade, and the maker's face to face payment account's currency code is used when creating the offer.
#
# Prerequisites:
#
# - Linux or OSX with bash, Java 10, or Java 11-12 (JDK language compatibility 10), and bitcoin-core (v0.19, v0.20, or v0.21).
# - Linux or OSX with bash, Java 11-15 (JDK language compatibility 11), and bitcoin-core (v0.19 - v22).
#
# - Bisq must be fully built with apitest dao setup files installed.
# Build command: `./gradlew clean build :apitest:installDaoSetup`
Expand All @@ -26,15 +26,16 @@
#
# `$ apitest/scripts/trade-simulation.sh -d buy -c fr -m 3.00 -a 0.125`
#
# Script options: -d <direction> -c <country-code> -m <mkt-price-margin(%)> - f <fixed-price> -a <amount(btc)>
# Script options: -d <direction> -c <country-code> -m <mkt-price-margin(%)> -f <fixed-price> -a <amount(btc)>
#
# Examples:
#
# Create a buy/eur offer to buy 0.125 btc at a mkt-price-margin of 0%, using an Italy face to face payment account:
# Create and take a buy/eur offer to buy 0.125 btc at a mkt-price-margin of 0%, using an Italy face to face
# payment account:
#
# `$ apitest/scripts/trade-simulation.sh -d buy -c it -m 0.00 -a 0.125`
#
# Create a sell/eur offer to sell 0.125 btc at a fixed-price of 38,000 euros, using a France face to face
# Create and take a sell/eur offer to sell 0.125 btc at a fixed-price of 38,000 euros, using a France face to face
# payment account:
#
# `$ apitest/scripts/trade-simulation.sh -d sell -c fr -f 38000 -a 0.125`
Expand All @@ -53,8 +54,6 @@ printdate "Started $APP_BASE_NAME with parameters:"
printscriptparams
printbreak

registerdisputeagents

# Demonstrate how to create a country based, face to face account.
showcreatepaymentacctsteps "Alice" "$ALICE_PORT"

Expand Down
Loading