import os
import time
-
from .Account import Account
from .Transaction import Action, Transaction
from .UnspentOutputs import UnspentOutputs
parser.add_argument('-x', '--max', default=41250000000, type=int, dest='max_amount', help='range lower than max_amount')
parser.add_argument('-s', '--min', default=1, type=int, dest='min_amount', help='range higher than min_amount')
parser.add_argument('-l', '--list', action='store_true', dest='only_list', help='Show UTXO list without merge')
-parser.add_argument('-m', '--merge', default=None, type=int, dest='merge_list', help='UTXO to merge')
+parser.add_argument('-m', '--merge', default=20, type=int, dest='merge_list', help='UTXO to merge')
+parser.add_argument('-f', '--forloop', default=1, type=int, dest='for_loop', help='size for loop of UTXO to merge')
parser.add_argument('-y', '--yes', action='store_true', default=None, dest='confirm', help='confirm transfer')
def main():
options = parser.parse_args()
+ utxo_total = []
utxolist = list_utxo(options.url, options.account_alias, options.min_amount, options.max_amount)
+
for i, utxo in enumerate(utxolist):
print('{:4}. {:13.8f} BTM {}{}'.format(i, utxo['amount'] / 1e8, utxo['id'], ' (mature)'))
- if i >= 21:
+ if i >= options.merge_list * options.for_loop:
break
+ utxo_total.append(utxo)
+
print("total size of available utxos is {}".format(len(utxolist)))
if options.only_list:
return
+ print('To merge {} UTXOs with {:13.8f} BTM totally.\n'.format(len(utxo_total),
+ sum(utxo['amount'] for utxo in utxo_total) / 1e8))
+
merge_size = options.merge_list or input('Merge size of UTXOs (5, 13 or 20): ')
- utxo_mergelist = []
+ for_loop = options.for_loop or input('for loop size (1, 10 or 50): ')
- for i in range(merge_size if merge_size <= len(utxolist) else len(utxolist)):
- utxo_mergelist.append(utxolist[i])
- if len(utxo_mergelist) < 2:
- print('Not Merge UTXOs, Exit...')
- return
- print('To merge {} UTXOs with {:13.8f} BTM'.format(len(utxo_mergelist),
- sum(utxo['amount'] for utxo in utxo_mergelist) / 1e8))
+ print(
+ 'One last disclaimer: the code we are about to go over is in no way intended to be used as an example of a robust solution. ')
+ print('You will transfer BTM to an address, please check this python code and DO IT later.\n')
- if not options.account_alias:
- options.account_alias = input('Transfer account alias: ')
+ for loops in range(for_loop):
- if not options.password:
- options.password = getpass.getpass('Bytom Account Password: ')
+ utxo_mergelist = []
- print(
- 'One last disclaimer: the code we are about to go over is in no way intended to be used as an example of a robust solution. ')
- print('You will transfer BTM to an address, please check this python code and DO IT later.')
+ # for i in range(merge_size if merge_size <= len(utxolist) else len(utxolist)):
+ # utxo_mergelist.append(utxolist[i])
+ for i in range(loops*merge_size, ((loops+1)*merge_size) if (loops*merge_size) < len(utxolist) else len(utxolist)):
+ utxo_mergelist.append(utxolist[i])
- if not (options.confirm or input('Confirm [y/N] ').lower() == 'y'):
- print('Not Merge UTXOs, Exit...')
- return
+ # print(loops*merge_size, ", ", ((loops+1)*merge_size) if (loops*merge_size) < len(utxolist) else len(utxolist))
+ print('this is the {} times to merge utxos. -----begin'.format(loops+1))
+
+ for i, utxo in enumerate(utxo_mergelist):
+ print('{:4}. {:13.8f} BTM {}{}'.format(loops*merge_size+i, utxo['amount'] / 1e8, utxo['id'], ' (mature)'))
+
+ print("total size of available utxos is {}".format(len(utxo_mergelist)))
+
+ if len(utxo_mergelist) < 2:
+ print('Not Merge UTXOs, Exit...')
+ return
+
+ print('To merge {} UTXOs with {:13.8f} BTM'.format(len(utxo_mergelist),
+ sum(utxo['amount'] for utxo in utxo_mergelist) / 1e8))
+
+ if not options.account_alias:
+ options.account_alias = input('Transfer account alias: ')
+
+ if not options.password:
+ options.password = getpass.getpass('Bytom Account Password: ')
+
+ if not (options.confirm or input('Confirm [y/N] ').lower() == 'y'):
+ print('Not Merge UTXOs, Exit...')
+ return
+
+ to_address = Account.find_address_by_alias(Connection(options.url), options.account_alias)
+ if not to_address:
+ to_address = input('Transfer address: ')
+
+ print('tx_id:', send_tx(Connection(options.url), utxo_mergelist, to_address, options.password))
+ print('this is the {} times to merge utxos. -----end\n'.format(loops+1))
- to_address = Account.find_address_by_alias(Connection(options.url), options.account_alias)
- if not to_address:
- to_address = input('Transfer address: ')
- print('tx_id:', send_tx(Connection(options.url), utxo_mergelist, to_address, options.password))
+ time.sleep(2)
+ pass
if __name__ == '__main__':