Skip to content

Instantly share code, notes, and snippets.

@buzzkillb
Created January 20, 2021 21:42
Show Gist options
  • Save buzzkillb/f812e2eff1f29b6e034f4a2ff24dcc78 to your computer and use it in GitHub Desktop.
Save buzzkillb/f812e2eff1f29b6e034f4a2ff24dcc78 to your computer and use it in GitHub Desktop.
#combine inputs and send to a given address, for single address specifically for yiimp 0 input lag
#!/bin/bash
. config.conf
. rpc.sh
#this is meant to clean a mining pool Denarius address as it will retie addresses together searching for a D input greater than txfee from change address and main wallet
#auto finds ZERO inputs to send, gets txfee, finds input with D > txfee and sends back on itself
#####################
#wget https://raw.githubusercontent.com/buzzkillb/bash-denariusrpc/master/rpc.sh
#
#wget https://raw.githubusercontent.com/buzzkillb/bash-denariusrpc/master/config.conf.template
#update and rename config.conf
#
#Change address to the pool address to clean, nothing else needs to be touched
#
#to run
#bash doctordauto.sh
#####################
minimuminputs=100
minimumbalance=0.0010000
zeroRewards=0.00000000
maximumInput=1.00000000
walletAddress=DTNGJBgn3VTCPDcAa9TZzb978Ghc7dTZsC
#Max Inputs RPC allows is 116
maxZeroInputstoGrab=116
#zeroInputList
zeroInputList=$(rpc_listunspent | jq '[.[] | select(.amount == 0) ] ')
echo $zeroInputList
#Count number of 0 inputs from zeroInputList
zeroInputCount=$(echo $zeroInputList | jq '. | length')
echo "0 Input Count: $zeroInputCount"
input_txfee=0.00001
denariusInitialByte=226
denariusAddByte=148
totalInputstoGrab=$((zeroInputCount + 1))
if [[ $totalInputstoGrab -le 117 ]]
then
echo "uning $totalInputstoGrab inputs"
totalInputstoGrab=$((zeroInputCount + 1))
else
echo "max inputs RPC can handle is 116, using 116"
totalInputstoGrab=116
fi
totalBytes=$(echo "scale=5; ($denariusInitialByte * 1) + (($totalInputstoGrab - 1) * $denariusAddByte)" | bc)
#echo "Total Bytes: $totalBytes"
#Rough txfee Estimator based on number of inputs
if [ $totalInputstoGrab -le 6 ]
then
txfee=0.00001
elif [ $totalInputstoGrab -le 12 ]
then
txfee=0.00002
elif [ $totalInputstoGrab -le 19 ]
then
txfee=0.00003
elif [ $totalInputstoGrab -le 26 ]
then
txfee=0.00004
elif [ $totalInputstoGrab -le 33 ]
then
txfee=0.00005
elif [ $totalInputstoGrab -le 40 ]
then
txfee=0.00006
elif [ $totalInputstoGrab -le 47 ]
then
txfee=0.00007
elif [ $totalInputstoGrab -le 54 ]
then
txfee=0.00008
elif [ $totalInputstoGrab -le 61 ]
then
txfee=0.00009
elif [ $totalInputstoGrab -le 68 ]
then
txfee=0.00010
elif [ $totalInputstoGrab -le 75 ]
then
txfee=0.00011
elif [ $totalInputstoGrab -le 82 ]
then
txfee=0.00012
elif [ $totalInputstoGrab -le 89 ]
then
txfee=0.00013
elif [ $totalInputstoGrab -le 96 ]
then
txfee=0.00014
elif [ $totalInputstoGrab -le 103 ]
then
txfee=0.00015
elif [ $totalInputstoGrab -le 110 ]
then
txfee=0.00016
elif [ $totalInputstoGrab -le 117 ]
then
txfee=0.00017
else
echo "Fail"
fi
#functions used: rpc_listunspent rpc_createrawtransaction rpc_signrawtransaction rpc_sendrawtransaction
#echo $unspentaddress transaction count
txcount=$(rpc_listunspent | jq --arg ADDRESS "$walletAddress" '[.[] | select(.address == $ADDRESS) | .txid ] | length')
fullAddressList=$(rpc_listunspent | jq --arg ADDRESS "$walletAddress" '.[] | select(.address==$ADDRESS) ')
#echo $fullAddressList
#get however many lines to search
unspent_array=$(echo $zeroInputList | jq --arg ADDRESS "$walletAddress" '.[:'${zeroInputCount}']')
#remove old raw.txt we created last time
rm raw.txt
#loop through 0 inputs
echo "loop through 0 inputs"
echo $unspent_array | jq --arg ADDRESS "$walletAddress" '.[] | select(.address==$ADDRESS) | .txid,.vout,.amount ' | (
while read txid; do
read vout
read amount
if [ 1 -eq "$(echo "${amount} == ${zeroRewards}" | bc)" ]; then
echo '{"txid":'$txid',"vout":'$vout'},' | tr -d ' \t\n\r\f' >> raw.txt
else
echo "skip $amount"
fi
done
)
#find first input greater than txfee required to send
#grab entire list from single address
fullAddressList=$(rpc_listunspent | jq '.[] ')
#loop through looking for first greater than txfee Denarius input from entire single address list
firstnonzerofee=$(echo $fullAddressList | jq -n 'first(inputs|select(.amount > '${txfee}'))')
echo "first nonzero tx to use"
echo $firstnonzerofee
echo "grab what we need from first nonzero tx"
echo $firstnonzerofee | jq '. | .txid,.vout,.amount' | (
while read txid; do
read vout
read amount
echo '{"txid":'$txid',"vout":'$vout'},' | tr -d ' \t\n\r\f' >> raw.txt
done
)
#get fee for sending and subtract fee to send back on itself
denariusInput=$(echo $firstnonzerofee | jq '. | .amount')
convert_notation=$(printf "%.8f" $denariusInput)
echo "Denarius Input Amount we Use: $convert_notation"
subtractfee=$(echo "scale=8; $convert_notation - $txfee" | bc)
echo "Send Fee: $subtractfee"
QUOTE="'"
sed -i '1s/^/'$QUOTE''$QUOTE'[/' raw.txt
sed -i '$ s/,$//g' raw.txt
echo ']'$QUOTE''$QUOTE', '$QUOTE''$QUOTE'{"'$walletAddress'":'$subtractfee'}'$QUOTE''$QUOTE'' | tr -d ' \t\n\r\f' >> raw.txt
#store rawtransaction
startrawtransaction=$(head -1 raw.txt)
#put startrawtransaction json into curl function command
rpc_createrawtransaction "${startrawtransaction}"
#bring full curl rpc string into _createrawtransaction
_createrawtransaction=$(eval "${createRawTransaction}")
#RawTX builds the complete json from .result array
RawTX=$(echo $_createrawtransaction | jq '.result')
echo $RawTX
rpc_signrawtransaction "$RawTX"
_signrawtransaction=$(eval "${signRawTransaction}")
RawSIGN=$(echo $_signrawtransaction | jq '.result.hex')
echo $RawSIGN
rpc_sendrawtransaction "$RawSIGN"
_sendrawtransaction=$(eval "${sendRawTransaction}")
echo $_sendrawtransaction
RawSEND=$(echo $_sendrawtransaction | jq '.result')
echo $RawSEND
echo "combined dust minus fee: "$subtractfee
echo "txfee: $txfee"
echo "Inputs to Grab: $totalInputstoGrab"
echo "txfee: $txfee"
echo "Total Bytes: $totalBytes"
echo "0 Inputs + 1 D input: $totalInputstoGrab"
echo "total tx's before Send: $txcount"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment