Created
January 22, 2021 18:34
-
-
Save buzzkillb/435a53d83f52dc44f57276b33534227a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
############# | |
#The goal is to take all the addresses in a wallet over minimumbalance user sets and send equal amounts of lowest D per | |
#all those addresses and send to that many new addresses, like a very very crude coinjoin on your own wallet. | |
#To try you need snap installed, load QT and run. Use a test wallet with 2 small D addresses to see what happens. | |
############# | |
# daemon location | |
denariusdaemon=/snap/bin/denarius.daemon | |
# debug.log location | |
debuglog=~/snap/denarius/common/.denarius/debug.log | |
# denarius.conf location | |
denariusconf=~/snap/denarius/common/.denarius/denarius.conf | |
minimuminputs=1 | |
minimumbalance=0.333 | |
txfee=0.00001000 | |
zeroRewards=0.00000000 | |
i=0 | |
signer=() | |
#change back onto original address to this arrray | |
existingAddress=() | |
amountD=() | |
sendrawtxtlist=() | |
counterrawhex=0 | |
countamountD=0 | |
countSigned=0 | |
#newAddress=(D5Wg7nv1bUC3PgntDAmzaTN7GZMgdy6oCU DDWJDj24VtaoarzhQ8jrRZioE39xo7AbEP DKtCSHYexnfJ9wsLkmnKwQfFDDndaxBoDU DKAKRUAjAyTpEsTzNUTMqmvwywkWta9reQ) | |
#coinjoin equal amounts to this array | |
countChangeAddress=0 | |
changeAddress=() | |
rm raw* | |
rm sign* | |
rm sendto.txt | |
rm sendtoa.txt | |
rm signme.txt | |
rm sendrawtxt.txt | |
fullListunspent=$($denariusdaemon listunspent) | |
echo $fullListunspent | |
unspentaddresses=$(echo $fullListunspent | jq -r '.[].address' | awk '!seen[$0]++') | |
#printf '%s\n' $unspentaddresses | |
while IFS= read -r | |
do | |
#printf '%s\n' $REPLY | |
inputcount=$(echo $fullListunspent | jq --arg ADDRESS "$REPLY" '[.[] | select(.address == $ADDRESS) | .txid ] | length') | |
echo "inputcount: $inputcount" | |
if [ "$inputcount" -ge "$minimuminputs" ]; then | |
echo "Join addy: $REPLY" | |
#get total balance per address | |
sumdust=$(echo $fullListunspent | jq --arg ADDRESS "$REPLY" '.[] | select(.address== $ADDRESS) | .amount | tonumber ' | jq -s add | awk {' printf "%.8f",$1'}) | |
echo "denarii dust: $sumdust" | |
subtractfee=$(echo "$sumdust - $txfee" | bc) | |
#check if minimumbalance is less than subtractfee | |
if [ 1 -eq "$(echo "${minimumbalance} < ${subtractfee}" | bc)" ] | |
then | |
#variable counter | |
echo "Signer: $i" | |
((i=i+1)) | |
echo "Gonna send it!" | |
#rm raw.txt | |
echo $fullListunspent | jq --arg ADDRESS "$REPLY" '.[] | select(.address==$ADDRESS) | .txid,.vout,.address,.scriptPubKey,.amount ' | ( | |
while read txid; do | |
read vout | |
read address | |
read scriptPubKey | |
read amount | |
#if [ 1 -eq "$(echo "${amount} == ${zeroRewards}" | bc)" ] || [ 1 -eq "$(echo "${amount} > ${maximumInput}" | bc)" ]; then | |
if [ 1 -eq "$(echo "${amount} == ${zeroRewards}" | bc)" ]; then | |
echo "skip $amount" | |
else | |
echo "use $amount" | |
echo '{"txid":'$txid',"vout":'$vout'},' | tr -d ' \t\n\r\f' >> raw.txt | |
#echo '{"txid":'$txid',"vout":'$vout'},' | tr -d ' \t\n\r\f' | |
echo '{"txid":'$txid',"vout":'$vout',"scriptPubKey":'$scriptPubKey'},' | tr -d ' \t\n\r\f' >> sign.txt | |
fi | |
done | |
) | |
#build array of Private Key signers | |
privkey=$($denariusdaemon dumpprivkey $REPLY) | |
signer+=("${privkey}") | |
existingAddress+=("${REPLY}") | |
amountD+=("${subtractfee}") | |
#convert amounts to full integer for comparison on max amount | |
convertToInteger=$(echo "$subtractfee * 100000000 / 1" | bc) | |
amountDInteger+=("${convertToInteger}") | |
#echo "${signer[@]}" | |
#echo "the array contains ${#signer[@]} elements" | |
#for i in "${signer[@]}"; do echo "$i"; done | |
fi | |
fi | |
done <<< "$unspentaddresses" | |
#get new addresses based on array size | |
numbernewaddress=${#signer[@]} | |
echo "number of addresses to send to and create: $numbernewaddress" | |
sendrawtxarraynumber=$(echo "$numbernewaddress - 1" | bc) | |
#Generate as many addresses as signers | |
for each in "${signer[@]}" | |
do | |
#echo "change addy counter: $countChangeAddress" | |
getChangeAddress=$($denariusdaemon getnewaddress) | |
changeAddress+=("${getChangeAddress}") | |
echo "new change address: ${changeAddress[$countChangeAddress]}" | |
((countChangeAddress=countChangeAddress+1)) | |
done | |
#array of amounts of D, add up and do some math | |
for t in "${amountD[@]}"; do echo "$t"; done | |
dc <<< '[+]sa[z2!>az2!>b]sb'"${amountD[*]//-/_}lbxp" | |
#find MIN and MAX of amountD array | |
for i in "${amountDInteger[@]}"; do echo "$i"; done | |
min=0 max=0 | |
for i in ${amountDInteger[@]}; do | |
(( $i > max || max == 0)) && max=$i | |
(( $i < min || min == 0)) && min=$i | |
done | |
#echo "min=$min" | |
converttoMin=$(echo "scale=8; ($min / 100000000) - 0.00000001" | bc) | |
echo "Amount in Common: $converttoMin" | |
#list existing address to change back to | |
for i in "${existingAddress[@]}"; do echo "$i"; done | |
#create list of change to send back to original address | |
for each in "${existingAddress[@]}" | |
do | |
createchange=$(echo "${amountD[$countamountD]} - $converttoMin" | bc) | |
echo $createchange | |
#echo '"'${each}'":'${amountD[$countamountD]}',' >> sendto.txt | |
echo '"'${each}'":'${createchange}',' >> sendto.txt | |
#echo '"'${each}'":'${converttoMin}',' >> sendto.txt | |
echo "AmountD Counter: $countamountD" | |
echo "Check Change: $converttoMin" | |
((countamountD=countamountD+1)) | |
done | |
#create coinjoin list | |
for each in "${changeAddress[@]}" | |
do | |
#createchange=$(echo "${amountD[$countamountD]} - $converttoMin" | bc) | |
#echo $createchange | |
#echo '"'${each}'":'${amountD[$countamountD]}',' >> sendto.txt | |
#echo '"'${each}'":'${createchange}',' >> sendto.txt | |
echo '"'${each}'":'${converttoMin}',' >> sendto.txt | |
echo "AmountD Counter: $countamountD" | |
echo "Check Change: $converttoMin" | |
((countamountD=countamountD+1)) | |
done | |
echo -n $(tr -d "\n" < sendto.txt) > sendto.txt | |
sed -i '1s/^/{/' sendto.txt | |
sed '$ s/,$//g' sendto.txt > sendtoa.txt | |
echo '}' >> sendtoa.txt | |
createsendlist=$(head -1 sendtoa.txt) | |
echo $createsendlist | |
#break here | |
#rawtx | |
tr -d ' \t\n\r\f' <raw.txt > rawb.txt | |
sed -i '1s/^/createrawtransaction [/' rawb.txt | |
#remove last comma | |
sed '$ s/,$//g' rawb.txt > rawc.txt | |
echo '] '${createsendlist}'' >> rawc.txt | |
createrawtransaction=$(head -1 rawc.txt) | |
echo $createrawtransaction | |
echo "creating raw transaction" | |
signrawtransaction=($($denariusdaemon $createrawtransaction)) | |
echo "I need this line to work" | |
echo $signrawtransaction | |
#Get READY to SIGN the BEAST | |
#signrawtransaction | |
echo "Now to Sign raw transaction" | |
#remove last comma | |
sed -i '$ s/.$//' sign.txt | |
#add bracket and quote | |
sed -i '1s/^/[/' sign.txt | |
echo ']' >> sign.txt | |
#add quotes to begin and end (dont do this) | |
#sed -i 's/\(.*\)/"\1"/g' sign.txt | |
signthelist=$(head -1 sign.txt) | |
#echo "sign the list" | |
#echo $signthelist | |
#sendrawtransaction=($(denariusd signrawtransaction $signrawtransaction | jq -r '.hex')) | |
for each in "${signer[@]}" | |
do | |
#echo "'[\"${each[*]}\"]'" | |
echo "[\"${each[*]}\"]" >> signme.txt | |
done | |
#Now Sign | |
while read p; do | |
if [ $counterrawhex -le 0 ] | |
then | |
#echo "${signrawtransaction}" "${signthelist}" "${p}" | |
sendrawtransaction=($($denariusdaemon signrawtransaction "${signrawtransaction}" "${signthelist}" "${p}" | jq -r '.hex')) | |
echo "$denariusdaemon signrawtransaction "${signrawtransaction}" "${signthelist}" "${p}"" | |
echo "1st signed here-------------" | |
echo $sendrawtransaction | |
echo "1st signed here-------------" | |
$denariusdaemon signrawtransaction ${sendrawtxtlist[$counterrawhex]} "${signrawtransaction}" "${signthelist}" "${p}" | jq -r '.complete' | |
sendrawtxtlist+=("${sendrawtransaction}") | |
echo "Signer Counter: $counterrawhex" | |
((counterrawhex=counterrawhex+1)) | |
echo "move to array signing---------" | |
#echo "$p" | |
elif [ $counterrawhex -gt 0 ] | |
then | |
#echo "${signrawtransaction}" "${signthelist}" "${p}" | |
echo "count signed: $countSigned ===================" | |
sendrawtransaction=($($denariusdaemon signrawtransaction "${sendrawtxtlist[$countSigned]}" "${signthelist}" "${p}" | jq -r '.hex')) | |
#echo "$denariusdaemon signrawtransaction "${sendrawtxtlist[$countSigned]}" "${signrawtransaction}" "${signthelist}" "${p}"" | |
$denariusdaemon signrawtransaction ${sendrawtxtlist[$counterrawhex]} "${signrawtransaction}" "${signthelist}" "${p}" | jq -r '.complete' | |
#echo $sendrawtransaction | |
sendrawtxtlist+=("${sendrawtransaction}") | |
echo "Signer Counter: $counterrawhex" | |
((counterrawhex=counterrawhex+1)) | |
((countSigned=countSigned+1)) | |
else | |
echo "Fail" | |
fi | |
done <signme.txt | |
monster=${sendrawtxtlist[${sendrawtxarraynumber}]} | |
echo $monster | |
#The eventual SEND! | |
$denariusdaemon sendrawtransaction $monster | |
#print stuff here maybe | |
#echo "${signer[@]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment