Skip to content

Instantly share code, notes, and snippets.

@thelazier
Last active June 9, 2017 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thelazier/863f57e36255476fe650468987f96e2a to your computer and use it in GitHub Desktop.
Save thelazier/863f57e36255476fe650468987f96e2a to your computer and use it in GitHub Desktop.
Another sum Mined coins, need "jq", "bc"
#!/bin/bash
# Need following config in dash.conf
## server=1
## rpcuser=AnythingYoulike
## rpcpassword=AnyPassword
#
# Open your wallet and unlock before run the script :)
#
# Suggestion for Loop `while true; do ./sum_mined_jq.sh || break; done`
#
# Define the command
DASH_CMD="/home/thelazier/bin/dash-cli"
DASH_DIR="/home/thelazier/.dashcore"
DASH_TX="/home/thelazier/bin/dash-tx"
DASH_CLI="$DASH_CMD -datadir=$DASH_DIR"
# number of max input
v_numin=50
# Address
TARGET_ADDR="XbDbC3LmKy9VrsFcV9m7BjdsEJtaKPDjTo"
# Get current block
v_blocks=$($DASH_CLI getinfo|grep -iw blocks| cut -d: -f2|cut -d, -f1|awk '{print $1}')
echo Block:$v_blocks
# Get list unspent from Dash Wallet
v_listunspent=$($DASH_CLI listunspent 1000 $v_blocks [\"$TARGET_ADDR\"] )
# Create in
v_ins=$(echo $v_listunspent|jq -r '.|=sort_by(.amount)|.[]|select(.amount != 1000)|"in=\(.txid):\(.vout) "'|head -$v_numin)
if [ -z "$v_ins" ]; then exit 1; fi
#echo $v_ins
# Calculate amount
v_amnt=$(echo $v_listunspent|jq -r '.|=sort_by(.amount)|.[]|select(.amount != 1000)|.amount'|head -$v_numin|paste -sd+ |bc)
#echo $v_amnt
# Create out
v_outs="outaddr=$v_amnt:$TARGET_ADDR"
#echo $v_outs
# Get rawtx
v_rawtx=$($DASH_TX -create $v_ins $v_outs)
echo RAW_TX:$v_rawtx
# Try decode raw transaction.
$DASH_CLI decoderawtransaction $v_rawtx
# Sign tx
v_sign_tx=$($DASH_CLI signrawtransaction $v_rawtx|grep -iw hex|cut -d'"' -f4)
echo SIGN_TX:$v_sign_tx
# Send Tx
v_txid=$($DASH_CLI sendrawtransaction $v_sign_tx )
echo TXID:$v_txid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment