Skip to content

Instantly share code, notes, and snippets.

@buzzkillb
Last active January 19, 2021 03:12
Show Gist options
  • Save buzzkillb/3c176af73adf2e02ccb849dfaa97e8c2 to your computer and use it in GitHub Desktop.
Save buzzkillb/3c176af73adf2e02ccb849dfaa97e8c2 to your computer and use it in GitHub Desktop.
revise to sort through and search only 0 inputs first
#combine inputs and send to a given address, for single address specifically for yiimp 0 input lag
#!/bin/bash
. config.conf
. rpc.sh
minimuminputs=100
minimumbalance=0.0010000
zeroRewards=0.00000000
maximumInput=1.00000000
walletAddress=DSNSwswjkic931atZXKMLsahzUKivvyDWk
#Max Inputs RPC allows is 116
zeroInputstoGrab=116
input_txfee=0.00001
denariusInitialByte=226
denariusAddByte=148
totalInputstoGrab=$((zeroInputstoGrab + 1))
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
#zeroInputsList
zeroInputList=$(rpc_listunspent | jq '[.[] | select(.amount == 0) ] ')
#echo $zeroInputList
#get however many lines to search
unspent_array=$(echo $zeroInputList | jq --arg ADDRESS "$walletAddress" '.[:'${zeroInputstoGrab}']')
#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 entire wallet
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')
echo "Denarius Input Amount we Use: $denariusInput"
subtractfee=$(echo "scale=8; $denariusInput - $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: $zeroInputstoGrab"
echo "txfee: $txfee"
echo "Total Bytes: $totalBytes"
echo "0 Inputs + 1 D input: $totalInputstoGrab"
echo "total tx's left: $txcount"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment