Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/bash
- ### setting
- # max confirmations to pick
- confirmMax=1000
- # max count to pick (for bash's command arg length limit)
- maxInputCount=100
- # min amount to pick
- minAmount=0
- # max amount to pick
- maxAmount=5000
- # from this address
- address="" # write your address
- # to this address (to same address : $address)
- #sendto=""
- sendto=$address
- # max amount per output
- outputMax=30000
- # fee in mocha
- fee=1000 # It is also possible to set the required fee indicated in the error message.
- # xpchain-cli command (like : xpchain-cli, xpchain-cli -datadir=/path/to/datadir/)
- cli="xpchain-cli"
- # xpchain-tx command
- tx="xpchain-tx"
- ### end
- # working file name
- unspentFile=listunspent
- amountFile=amount
- inputFile=input
- outputFile=output
- outputMaxMocha=`expr $outputMax \* 10000`
- ### get transactions
- $cli listunspent 1 $confirmMax "[\"$address\"]" true "{\"minimumAmount\":$minAmount, \"maximumAmount\":$maxAmount}" > $unspentFile
- ### make input json
- cat $unspentFile | grep -e txid -e vout | cut -d' ' -f6 | head -`expr $maxInputCount \* 2` | sed -e 's/",/:/' -e 's/"/ in=/' -e 's/,/ /' | xargs -I{} echo -n {} >> $inputFile
- ### calculate total amount
- echo -n "expr 0" > $amountFile
- cat $unspentFile | grep amount | head -$maxInputCount | cut -d':' -f2 | cut -d',' -f1 | sed -e 's/\.//' | xargs -I{} echo -n " + {}" >> $amountFile
- echo -n " - $fee" >> $amountFile
- amount=`source $amountFile`
- ### calculate output amount
- outs=1
- piece=$amount
- while [ $piece -gt $outputMaxMocha ]
- do
- outs=`expr $outs + 1`
- piece=`expr $amount / $outs`
- done
- piece=`echo -n $piece | sed -e 's/\([0-9]\{4\}\)$/\.\1/'`
- amount=`echo -n $amount | sed -e 's/\([0-9]\{4\}\)$/\.\1/'`
- ### make output json
- i=0
- while [ $i -lt $outs ]
- do
- i=`expr $i + 1`
- echo -n " outaddr=$piece:$sendto" >> $outputFile
- done
- input=`cat $inputFile`
- inputCount=`cat $unspentFile | grep txid | head -$maxInputCount | wc -l`
- output=`cat $outputFile`
- ### cleanup
- rm $unspentFile
- rm $amountFile
- rm $inputFile
- rm $outputFile
- ### summary
- echo "#######################################################"
- echo "total amount : $amount"
- echo "amount per output : $piece"
- echo "input count : $inputCount"
- echo "output count : $outs"
- echo "#######################################################"
- echo -n "Please press any key to continue. To abort, press Ctrl-C"
- read
- raw=`$tx -create $input $output`
- $cli decoderawtransaction $raw
- echo "!!! CHECK THIS RESULT !!!"
- echo -n "Please press any key to continue. To abort, press Ctrl-C"
- read
- signed=`$cli signrawtransactionwithwallet $raw | grep hex | cut -d'"' -f4`
- echo "signed transaction : "
- echo $signed
- echo "!!! THIS OPERATION IS NOT ABLE TO CANCEL !!!"
- echo "Can I send this transaction to network?"
- echo -n "Please press any key to continue. To abort, press Ctrl-C"
- read
- $cli sendrawtransaction $signed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement