Skip to content

Instantly share code, notes, and snippets.

@thephez
Created October 11, 2018 16:13
Show Gist options
  • Save thephez/ef333075b304b6458f7d1218a94ea66b to your computer and use it in GitHub Desktop.
Save thephez/ef333075b304b6458f7d1218a94ea66b to your computer and use it in GitHub Desktop.
Register a Dash blockchain user
CLI_PATH="$HOME/dashevo/dash/src"
CONF_FILE="$HOME/dashcore_evo/devnet-mydevnet.conf"
RUN_CLI="$CLI_PATH/dash-cli -conf=$CONF_FILE"
USERNAME="myuser0001"
printf "dash-cli in: $CLI_PATH\n"
printf "Dash conf file: $CONF_FILE\n\n"
# Returns the value contained in "$prop" of "$json"
# As found on https://gist.github.com/cjus/1047794
function jsonval {
temp=`echo $json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $prop| cut -d":" -f2| sed -e 's/^ *//g' -e 's/ *$//g'`
echo ${temp##*|}
}
# Check for username
COMMAND="getuser $USERNAME"
BU_INFO="$($RUN_CLI $COMMAND)"
# Don't attempt to create user if already present
if [ -z "$BU_INFO" ];
then
printf "Check for user '$USERNAME' returned no results\n\n"
# Generate address to use for username
COMMAND="getnewaddress"
BU_ADDR="$($RUN_CLI $COMMAND)"
printf "Address for BU (make a note of this for future reference):\n-----\n ${BU_ADDR}\n\n"
# Creates raw SubTx AND signs it
COMMAND="createsubtx register "$USERNAME" $BU_ADDR 0.01"
BU_RAW_TX="$($RUN_CLI $COMMAND)"
printf "Raw SubTxRegister (unsigned):\n-----\n ${BU_RAW_TX}\n\n"
# Get the Hex field required by sendrawtransaction
json=$BU_RAW_TX
prop='hex'
TX_HEX=`jsonval`
printf "Signed Transaction (hex):\n$TX_HEX\n\n"
# Send the SubTx
COMMAND="sendrawtransaction $TX_HEX false false true"
BU_TXID="$($RUN_CLI $COMMAND)"
printf "SubTxRegister submitted!\nResponse:\n-----\n $BU_TXID\n\n"
COMMAND="gettransaction $BU_TXID"
BU_TX="$($RUN_CLI $COMMAND)"
printf "BU Register Tx:\n-----\n $BU_TX\n\n"
# Mine a block
COMMAND="generate 1"
GENERATE="$($RUN_CLI $COMMAND)"
printf "Block generation:\n-----\n $GENERATE\n\n"
else
printf "User '$USERNAME' already registered. User info found:\n-----\n $BU_INFO\n\n\nExiting...\n\n"
fi
unset CLI_PATH
unset CONF_FILE
unset RUN_CLI
unset USERNAME
unset COMMAND
unset BU_INFO
unset BU_ADDR
unset BU_RAW_TX
unset TX_HEX
unset BU_TXID
unset BU_TX
unset GENERATE
unset BU_TX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment