9 def handle_input(_path, _account_id, _password):
11 with open(_path, 'r', encoding='utf-8') as file:
14 if len(lines) < max_output:
17 handle_transaction(lines, _path, _account_id, _password)
21 handle_transaction(lines, _path, _account_id, _password)
22 print('Transactions are completed.Please check completed.txt')
25 def handle_transaction(lines, _path, _account_id, _password):
26 data = build_transaction(lines, _account_id)
27 data = sign_transaction(_password, data)
28 if data['sign_complete']:
29 data = submit_transaction(data)
32 print('transaction_id:\n' + txid)
33 write_lines_to_file(lines, _path)
35 print('Sign transaction is failed.Please check account password.')
39 # parameter lines: max_output line list
40 def build_transaction(_lines, _account_id):
44 data = line.strip().split(',')
48 address_dict = get_address_dict(amount, address)
49 action_list.append(address_dict)
50 amount_sum += miner_fee
51 spend_dict = get_spend_dict(_account_id, int(amount_sum))
52 action_list.insert(0, spend_dict)
53 parameter = {'base_transaction': None, 'actions': action_list, 'ttl': 0}
54 return httprequest.post('build-transaction', parameter)
57 # parameter transaction: dict from build_transaction function return
58 def sign_transaction(_password, _transaction):
59 parameter = {'password': _password, 'transaction': _transaction}
60 return httprequest.post('sign-transaction', parameter)
63 def submit_transaction(_transaction):
64 parameter = {'raw_transaction': _transaction['transaction']['raw_transaction']}
65 return httprequest.post('submit-transaction', parameter)
68 # write complete transactions lines to file
69 def write_lines_to_file(lines, _path):
70 _path = os.path.abspath(os.path.dirname(_path)) + os.path.sep + 'completed.txt'
71 with open(_path, 'a', encoding='utf-8') as file:
72 file.write('\n'.join(lines) + '\n\n')
75 # control_address action
76 def get_address_dict(_amount, _address):
77 return {'amount': _amount,
78 'asset_id': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
80 'type': 'control_address'}
83 # spend_account action
84 def get_spend_dict(_account_id, _amount_sum):
85 return {'account_id': _account_id,
86 'amount': _amount_sum,
87 'asset_id': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
88 'type': 'spend_account'}
90 # if __name__ == "__main__":
91 # path = '/Users/john/Desktop/btm.txt'
92 # account_id = '0F0BV1OLG0A04'
94 # sys.exit(handle_input(path, account_id, password))