This commit is contained in:
woodser 2021-05-04 20:20:01 -04:00
commit 8a38081c04
2800 changed files with 344130 additions and 0 deletions

View file

@ -0,0 +1,196 @@
#!/usr/bin/env bash
# This script can be used to create a Bisq DAO genesis transaction on either regtest or testnet.
# Requirements:
# - bc and jq must be installed (e.g. sudo apt install bc jq)
set -e
BTC_NETWORK=regtest
GENESIS_BSQ_AMOUNT=0
GENESIS_BSQ_DISTRIBUTION=()
BITCOIND_CONFIG=/var/lib/bitcoind/bitcoin.conf
function show_help() {
cat << END
Usage: ${0##*/} [-h] [-c CONF_FILE] [-n NETWORK] [GENESIS_BSQ_AMOUNT] [GENESIS_BSQ_DISTRIBUTION]
GENESIS_BSQ_AMOUNT
Total amount of BSQ to include in the genesis transaction (if not specified, will be prompted).
GENESIS_BSQ_DISTRIBUTION
Distribution of BSQ within the genesis transaction [bsq_amount:bsq_address,...] (if not specified, will be prompted).
-h --help
Display this help message and exit.
-c --conf <CONF_FILE>
Path to bitcoind configuration file (default is /var/lib/bitcoind/bitcoin.conf).
-n --network <NETWORK>
Bitcoin network [REGTEST|TESTNET] (default is REGTEST).
END
}
function read_input() {
while true; do
read input
if [[ ${input} =~ $1 ]]; then
echo "${input}"
break
fi
echo >&2 "Invalid input, try again"
done
}
function generate_prevtx_json() {
json_file="prevtxs.json"
local tx_data=$1
local txid=$2
local vout=$(echo ${tx_data} | jq '.n')
local scriptPubkey=$(echo ${tx_data} | jq '.scriptPubKey.hex')
local amount=$(echo ${tx_data} | jq '.value')
echo -en "[{\n" > ${json_file}
echo -en " \"txid\": \"${txid}\",\n" >> ${json_file}
echo -en " \"vout\": ${vout},\n" >> ${json_file}
echo -en " \"scriptPubKey\": ${scriptPubkey},\n" >> ${json_file}
echo -en " \"amount\": ${amount}\n" >> ${json_file}
echo -en "}]\n" >> ${json_file}
}
function generate_privkeys_json() {
json_file="privatekeys.json"
local address=$1
local privkey=$(${BITCOIN_CLI} dumpprivkey ${address})
echo -en "[\"$privkey\"]\n" > ${json_file}
}
while (( $# )); do
case ${1:-} in
-h|-\?|--help)
show_help
exit
;;
-c|--conf)
if [[ -f "$2" ]]; then
BITCOIND_CONFIG=$2
shift
else
echo "ERROR: Specified 'conf' file does not exist"
exit 1
fi
;;
-n|--network)
if [[ $2 =~ ^REGTEST|TESTNET$ ]]; then
BTC_NETWORK=$2
shift
else
echo "ERROR: Specified 'network' is not valid, must be REGTEST or TESTNET"
exit 1
fi
;;
--) # End of all options
shift
break
;;
-?*)
printf "ERROR: Unknown option: %s\n" "$1"
exit 1
;;
*) # Default case; no more options, so break out of the loop
break
esac
shift
done
if [[ $1 =~ ^[0-9]+\.?[0-9]*$ ]]; then
GENESIS_BSQ_AMOUNT=$1
elif [[ "$1" ]]; then
echo "ERROR: Invalid BSQ amount"
exit 1
fi
if [[ $2 =~ ^([0-9]+\.?[0-9]*:B.+)(,[0-9]+\.?[0-9]*:B.+)*$ ]]; then
IFS=',' read -r -a GENESIS_BSQ_DISTRIBUTION <<< "$2"
elif [[ "$2" ]]; then
echo "ERROR: Invalid BSQ distribution format, must be [bsq_amount:bsq_address,...]"
exit 1
fi
BITCOIN_CLI="bitcoin-cli -conf=${BITCOIND_CONFIG}"
BITCOIN_TX="bitcoin-tx -${BTC_NETWORK}"
${BITCOIN_CLI} getblockcount &>/dev/null
if [[ $? -eq 1 ]]; then
echo "ERROR: bitcoind must be running"
exit 1
fi
if (( $(echo "${GENESIS_BSQ_AMOUNT} == 0" | bc -l) )); then
echo "How much BSQ would you like to distribute in the genesis transaction?"
GENESIS_BSQ_AMOUNT=$(read_input "^[0-9]+\.?[0-9]*$")
fi
GENESIS_BTC_AMOUNT=$(awk "BEGIN {printf \"%.8f\",${GENESIS_BSQ_AMOUNT}/1000000.00}")
GENESIS_BTC_FUNDING_AMOUNT=$(awk "BEGIN {printf \"%.8f\",${GENESIS_BTC_AMOUNT}+0.0001}")
btc_balance=$(${BITCOIN_CLI} getbalance)
if (( $(echo "${btc_balance} < ${GENESIS_BTC_FUNDING_AMOUNT}" | bc -l) )); then
printf "ERROR: Insufficient balance; %'.8f BTC is required but only %'.8f BTC is available\n" ${GENESIS_BTC_FUNDING_AMOUNT} ${btc_balance}
exit 1
fi
distributed_bsq_amount=0
if [[ ${#GENESIS_BSQ_DISTRIBUTION[@]} -eq 0 ]]; then
printf "How many contributors would you like to include in the genesis transaction? (totaling %'.2f BSQ)\n" ${GENESIS_BSQ_AMOUNT}
contributor_count=$(read_input "^[0-9]+$")
for (( i = 1; i <= ${contributor_count}; ++i )); do
echo "Enter the BSQ address of contributor ${i}:"
bsq_address=$(read_input "^B.+$")
echo "Enter the amount of BSQ for contributor ${i}:"
bsq_amount=$(read_input "^[0-9]+\.?[0-9]*$")
GENESIS_BSQ_DISTRIBUTION+=("${bsq_amount}:${bsq_address}")
distributed_bsq_amount=$(awk "BEGIN {printf \"%.2f\",${distributed_bsq_amount}+${bsq_amount}}")
done
else
for item in "${GENESIS_BSQ_DISTRIBUTION[@]}"; do
bsq_amount="${item%%:*}"
distributed_bsq_amount=$(awk "BEGIN {printf \"%.2f\",${distributed_bsq_amount}+${bsq_amount}}")
done
fi
if (( $(echo "${distributed_bsq_amount} != ${GENESIS_BSQ_AMOUNT}" | bc -l) )); then
printf "ERROR: The BSQ amount being distributed is %'.2f but must total %'.2f\n" ${distributed_bsq_amount} ${GENESIS_BSQ_AMOUNT}
exit 1
fi
genesis_input_address=$(${BITCOIN_CLI} getnewaddress "Genesis funding address")
printf "Sending %'.8f BTC to genesis funding address ${genesis_input_address}\n" ${GENESIS_BTC_FUNDING_AMOUNT}
genesis_input_txid=$(${BITCOIN_CLI} sendtoaddress ${genesis_input_address} ${GENESIS_BTC_FUNDING_AMOUNT})
echo "Genesis funding txid is ${genesis_input_txid}"
echo "Creating genesis transaction"
tx_hex=$(${BITCOIN_CLI} gettransaction ${genesis_input_txid} | jq '.hex'|tr -d '"')
vin_json=$(${BITCOIN_CLI} decoderawtransaction ${tx_hex} | jq ".vout | map(select(.value==${GENESIS_BTC_FUNDING_AMOUNT}))[0]" | tr -d "[ \n\t]")
vout=$(echo ${vin_json}|jq '.n')
generate_prevtx_json ${vin_json} ${genesis_input_txid}
generate_privkeys_json ${genesis_input_address}
outaddr=
for item in "${GENESIS_BSQ_DISTRIBUTION[@]}"; do
bsq_amount="${item%%:*}"
btc_amount="$(awk "BEGIN {printf \"%.8f\",${bsq_amount}/1000000.00}")"
bsq_address="${item##*:}"
outaddr="${outaddr}outaddr=${btc_amount}:${bsq_address##B} "
done
genesis_raw=$(${BITCOIN_TX} -create in=${genesis_input_txid}:${vout} ${outaddr} load=prevtxs:prevtxs.json load=privatekeys:privatekeys.json sign=ALL)
echo "The raw genesis transaction is $genesis_raw"
echo "Decoded transaction:"
genesis_decoded=$(${BITCOIN_CLI} decoderawtransaction ${genesis_raw})
echo ${genesis_decoded}| jq '.'
genesis_txid=$(echo ${genesis_decoded}| jq '.txid'|tr -d '"')
echo "Please ensure the above decoded transaction looks valid, and then press Enter to broadcast the genesis transaction (Ctrl+C otherwise)"
read
echo "Genesis txid is $(${BITCOIN_CLI} sendrawtransaction ${genesis_raw})"

56
scripts/install_java.bat Normal file
View file

@ -0,0 +1,56 @@
:: This script will download and install the appropriate JDK for use with Bisq development.
:: It will also configure it as the default system JDK.
:: If you need to change to another default JDK for another purpose later, you just need to
:: change the JAVA_HOME environment variable. For example, use the following command:
:: setx /M JAVA_HOME "<JDK_PATH>"
@echo off
:: Ensure we have administrative privileges in order to install files and set environment variables
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' == '0' (
::If no error is encountered, we have administrative privileges
goto GotAdminPrivileges
)
echo Requesting administrative privileges...
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadminprivileges.vbs"
set params = %*:"=""
echo UAC.ShellExecute "%~s0", "%params%", "", "runas", 1 >> "%temp%\getadminprivileges.vbs"
"%temp%\getadminprivileges.vbs"
exit /B
:GotAdminPrivileges
if exist "%temp%\getadminprivileges.vbs" ( del "%temp%\getadminprivileges.vbs" )
pushd "%CD%"
cd /D "%~dp0"
title Install Java
set jdk_version=11.0.2
set jdk_filename=openjdk-%jdk_version%_windows-x64_bin
set jdk_url=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_windows-x64_bin.zip
if exist "%PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%" (
echo %PROGRAMFILES%\Java\openjdk\jdk-%jdk_version% already exists, skipping install
goto SetEnvVars
)
echo Downloading required files to %TEMP%
powershell -Command "Invoke-WebRequest %jdk_url% -OutFile $env:temp\%jdk_filename%.zip"
echo Extracting and installing JDK to %PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%
powershell -Command "Expand-Archive $env:temp\%jdk_filename%.zip -DestinationPath %TEMP%\openjdk-%jdk_version% -Force"
md "%PROGRAMFILES%\Java\openjdk"
move "%TEMP%\openjdk-%jdk_version%\jdk-%jdk_version%" "%PROGRAMFILES%\Java\openjdk"
echo Removing downloaded files
rmdir /S /Q %TEMP%\openjdk-%jdk_version%
del /Q %TEMP%\%jdk_filename%.zip
:SetEnvVars
echo Setting environment variables
powershell -Command "[Environment]::SetEnvironmentVariable('JAVA_HOME', '%PROGRAMFILES%\Java\openjdk\jdk-%jdk_version%', 'Machine')"
set java_bin=%%JAVA_HOME%%\bin
echo %PATH%|find /i "%java_bin%">nul || powershell -Command "[Environment]::SetEnvironmentVariable('PATH', '%PATH%;%java_bin%', 'Machine')"
echo Done!
pause

82
scripts/install_java.sh Executable file
View file

@ -0,0 +1,82 @@
#!/usr/bin/env bash
# This script will download and install the appropriate JDK for use with Bisq development.
# It will also configure it as the default system JDK.
# If you need to change to another default JDK for another purpose later, you can use the
# following commands and select the default JDK:
# Linux:
# update-alternatives --config java
# update-alternatives --config javac
# MacOS:
# echo 'export JAVA_HOME=/Library/Java/JavaVirtualMachines/<ENTER_NEW_JDK>/Contents/Home' >>~/.bash_profile
# echo 'export PATH=$JAVA_HOME/bin:$PATH' >>~/.bash_profile
# source ~/.bash_profile
set -e
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*)
JAVA_HOME=/usr/lib/jvm/openjdk-11.0.2
JDK_FILENAME=openjdk-11.0.2_linux-x64_bin.tar.gz
JDK_URL=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_linux-x64_bin.tar.gz
# Determine which package manager to use depending on the distribution
declare -A osInfo;
osInfo[/etc/redhat-release]=yum
osInfo[/etc/arch-release]=pacman
osInfo[/etc/gentoo-release]=emerge
osInfo[/etc/SuSE-release]=zypp
osInfo[/etc/debian_version]=apt-get
for f in "${!osInfo[@]}"
do
if [[ -f $f ]]; then
PACKAGE_MANAGER=${osInfo[$f]}
break
fi
done
if [ ! -d "$JAVA_HOME" ]; then
# Ensure curl is installed since it may not be
$PACKAGE_MANAGER -y install curl
curl -L -O $JDK_URL
mkdir -p $JAVA_HOME
tar -zxf $JDK_FILENAME -C $JAVA_HOME --strip 1
rm $JDK_FILENAME
update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 2000
update-alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac 2000
fi
update-alternatives --set java $JAVA_HOME/bin/java
update-alternatives --set javac $JAVA_HOME/bin/javac
;;
Darwin*)
JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home
JDK_FILENAME=openjdk-11.0.2_osx-x64_bin.tar.gz
JDK_URL=https://download.java.net/java/GA/jdk11/9/GPL/openjdk-11.0.2_osx-x64_bin.tar.gz
if [ ! -d "$JAVA_HOME" ]; then
if [[ $(command -v brew) == "" ]]; then
echo "Installing Homebrew"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
else
echo "Updating Homebrew"
brew update
fi
brew install curl
curl -L -O $JDK_URL
sudo mkdir /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk | sudo bash
gunzip -c $JDK_FILENAME | tar xopf -
sudo mv jdk-11.0.2.jdk/* /Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk
sudo rmdir jdk-11.0.2.jdk
rm $JDK_FILENAME
fi
echo export JAVA_HOME=$JAVA_HOME >>~/.bash_profile
echo export PATH=$JAVA_HOME/bin:"$PATH" >>~/.bash_profile
source "$HOME/.bash_profile"
;;
*)
esac
java -version