-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5876 from ghubstan/5-api-bsqswap-simulation-n-doc…
…s-update API BSQ swap simulation script and doc updates #5
- Loading branch information
Showing
62 changed files
with
2,442 additions
and
1,600 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.