Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. #! /usr/bin/bash
  2.  
  3. ### setting
  4.  
  5. # max confirmations to pick
  6. confirmMax=1000
  7. # max count to pick (for bash's command arg length limit)
  8. maxInputCount=100
  9. # min amount to pick
  10. minAmount=0
  11. # max amount to pick
  12. maxAmount=5000
  13.  
  14. # from this address
  15. address="" # write your address
  16.  
  17. # to this address (to same address : $address)
  18. #sendto=""
  19. sendto=$address
  20.  
  21. # max amount per output
  22. outputMax=30000
  23. # fee in mocha
  24. fee=1000 # It is also possible to set the required fee indicated in the error message.
  25.  
  26. # xpchain-cli command (like : xpchain-cli, xpchain-cli -datadir=/path/to/datadir/)
  27. cli="xpchain-cli"
  28. # xpchain-tx command
  29. tx="xpchain-tx"
  30.  
  31. ### end
  32.  
  33.  
  34. # working file name
  35. unspentFile=listunspent
  36. amountFile=amount
  37. inputFile=input
  38. outputFile=output
  39. outputMaxMocha=`expr $outputMax \* 10000`
  40.  
  41. ### get transactions
  42. $cli listunspent 1 $confirmMax "[\"$address\"]" true "{\"minimumAmount\":$minAmount, \"maximumAmount\":$maxAmount}" > $unspentFile
  43.  
  44. ### make input json
  45. 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
  46.  
  47. ### calculate total amount
  48. echo -n "expr 0" > $amountFile
  49. cat $unspentFile | grep amount | head -$maxInputCount | cut -d':' -f2 | cut -d',' -f1 | sed -e 's/\.//' | xargs -I{} echo -n " + {}" >> $amountFile
  50. echo -n " - $fee" >> $amountFile
  51. amount=`source $amountFile`
  52.  
  53. ### calculate output amount
  54. outs=1
  55. piece=$amount
  56. while [ $piece -gt $outputMaxMocha ]
  57. do
  58. outs=`expr $outs + 1`
  59. piece=`expr $amount / $outs`
  60. done
  61. piece=`echo -n $piece | sed -e 's/\([0-9]\{4\}\)$/\.\1/'`
  62. amount=`echo -n $amount | sed -e 's/\([0-9]\{4\}\)$/\.\1/'`
  63.  
  64. ### make output json
  65. i=0
  66. while [ $i -lt $outs ]
  67. do
  68. i=`expr $i + 1`
  69. echo -n " outaddr=$piece:$sendto" >> $outputFile
  70. done
  71.  
  72. input=`cat $inputFile`
  73. inputCount=`cat $unspentFile | grep txid | head -$maxInputCount | wc -l`
  74. output=`cat $outputFile`
  75.  
  76. ### cleanup
  77. rm $unspentFile
  78. rm $amountFile
  79. rm $inputFile
  80. rm $outputFile
  81.  
  82. ### summary
  83. echo "#######################################################"
  84. echo "total amount : $amount"
  85. echo "amount per output : $piece"
  86. echo "input count : $inputCount"
  87. echo "output count : $outs"
  88. echo "#######################################################"
  89.  
  90. echo -n "Please press any key to continue. To abort, press Ctrl-C"
  91. read
  92.  
  93. raw=`$tx -create $input $output`
  94.  
  95. $cli decoderawtransaction $raw
  96.  
  97. echo "!!! CHECK THIS RESULT !!!"
  98. echo -n "Please press any key to continue. To abort, press Ctrl-C"
  99. read
  100.  
  101. signed=`$cli signrawtransactionwithwallet $raw | grep hex | cut -d'"' -f4`
  102. echo "signed transaction : "
  103. echo $signed
  104.  
  105. echo "!!! THIS OPERATION IS NOT ABLE TO CANCEL !!!"
  106. echo "Can I send this transaction to network?"
  107. echo -n "Please press any key to continue. To abort, press Ctrl-C"
  108. read
  109.  
  110. $cli sendrawtransaction $signed
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement