Created
October 27, 2016 06:39
-
-
Save thelazier/51e55bf5972a1620614f92755de0c2dd to your computer and use it in GitHub Desktop.
Bash script to sum inputs from mining.
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
#!/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.sh || break; done` | |
# | |
# Define the command | |
DASH_CMD="/home/thelazier/bin/dash-cli" | |
DASH_DIR="/home/thelazier/DashData" | |
DASH_TX="/home/thelazier/bin/dash-tx" | |
DASH_CLI="$DASH_CMD -datadir=$DASH_DIR" | |
# Address **** Your Address **** | |
TARGET_ADDR="XbDbC3LmKy9VrsFcV9m7BjdsEJtaKPDjTo" | |
# Get current block | |
v_blocks=$($DASH_CLI getinfo|grep -iw blocks| cut -d: -f2|cut -d, -f1|awk -e '{print $1}') | |
# Get unspent vouts | |
$DASH_CLI listunspent 555 $v_blocks [\"$TARGET_ADDR\"] > listunspent.json | |
pr -mJt \ | |
<(grep -o ".*: .*," listunspent.json | grep -iw txid | cut -d: -f2| cut -d '"' -f2|awk -e '{print $1}') \ | |
<(grep -o ".*: .*," listunspent.json | grep -iw vout | cut -d: -f2| cut -d, -f1|awk -e '{print $1}') \ | |
<(grep -o ".*: .*," listunspent.json | grep -iw amount | cut -d: -f2 | cut -d, -f1|awk -e '{print $1}') \ | |
| awk -e '{print $1":"$2","$3}' |sort -t, -k2 -n > listunspent.in | |
v_outs=$(cat listunspent.in |cut -d, -f1|awk -e '{print "in="$1}'|head -$v_numvin) | |
if [ -z "$v_outs" ]; then exit 1; fi | |
# Get amounts | |
v_amnt=$(cat listunspent.in |cut -d, -f2|head -$v_numvin |paste -sd'+'|xargs -i perl -e 'print '{}) | |
if [ -z "$v_amnt" ]; then exit 1; fi | |
# Get rawtx | |
v_rawtx=$($DASH_TX -create $v_outs outaddr=$v_amnt:$TARGET_ADDR) | |
if [ -z "$v_rawtx" ]; then exit 1; fi | |
# Sign tx | |
v_sign_tx=$($DASH_CLI signrawtransaction $v_rawtx|grep -iw hex|cut -d'"' -f4) | |
if [ -z "$v_sign_tx" ]; then exit 1; fi | |
# Send Tx | |
v_txid=$($DASH_CLI sendrawtransaction $v_sign_tx ) | |
if [ -z "$v_txid" ]; then exit 1; fi | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment