OSDN Git Service

perf(code refactoring):btw add create address tool
authorJohn Chi <john@8btc-1s-MBP.localdomain>
Thu, 14 Jun 2018 03:35:47 +0000 (11:35 +0800)
committerJohn Chi <john@8btc-1s-MBP.localdomain>
Thu, 14 Jun 2018 05:37:51 +0000 (13:37 +0800)
btmtransaction.py
btmvalidation.py
createaddress.py [new file with mode: 0644]
httprequest.py

index 70a29f2..78e3052 100644 (file)
@@ -3,7 +3,7 @@ import sys
 import httprequest
 
 miner_fee = 40000000
-max_output = 100
+max_output = 1500
 
 
 def handle_input(_path, _account_id, _password):
@@ -19,7 +19,7 @@ def handle_input(_path, _account_id, _password):
                 lines.append(line)
     if len(lines) > 0:
         handle_transaction(lines, _path, _account_id, _password)
-    print('Transaction is accomplished.Please check accomplished.txt')
+    print('Transactions are completed.Please check completed.txt')
 
 
 def handle_transaction(lines, _path, _account_id, _password):
@@ -30,7 +30,6 @@ def handle_transaction(lines, _path, _account_id, _password):
         txid = data['tx_id']
         if txid:
             print('transaction_id:\n' + txid)
-            lines = append_txid_to_lines(lines, txid)
             write_lines_to_file(lines, _path)
     else:
         print('Sign transaction is failed.Please check account password.')
@@ -66,18 +65,11 @@ def submit_transaction(_transaction):
     return httprequest.post('submit-transaction', parameter)
 
 
-def append_txid_to_lines(lines, txid):
-    for i in range(len(lines)):
-        # lines[i] = lines[i] + ',' + txid + '\n'
-        lines[i] = lines[i] + ',' + '\n'
-    return lines
-
-
 # write complete transactions lines to file
 def write_lines_to_file(lines, _path):
-    _path = os.path.abspath(os.path.dirname(_path)) + os.path.sep + 'accomplished.txt'
+    _path = os.path.abspath(os.path.dirname(_path)) + os.path.sep + 'completed.txt'
     with open(_path, 'a', encoding='utf-8') as file:
-        file.writelines(lines)
+        file.write('\n'.join(lines) + '\n\n')
 
 
 # control_address action
index 862ed3c..3eb8fe9 100755 (executable)
@@ -54,4 +54,5 @@ def validate_input(argv):
             splits = line.strip().split(',')
             validate_address(line, splits[0])
             validate_amount(line, splits[1])
+        print('Transactions address and amount are valid')
     return file_path, account_id, password
diff --git a/createaddress.py b/createaddress.py
new file mode 100644 (file)
index 0000000..8b2df98
--- /dev/null
@@ -0,0 +1,18 @@
+import sys
+import httprequest
+
+
+def create_address():
+    address_list = list()
+    for i in range(1000):
+        parameter = {'account_alias': 'alice', 'account_id': '0F0CFLG7G0A08'}
+        data = httprequest.post('create-account-receiver', parameter)
+        address_list.append(str(data['address']).strip() + ',100000000')
+
+    path = '/Users/john/Desktop/btm.txt'
+    with open(path, 'a', encoding='utf-8') as file:
+        file.write('\n'.join(address_list) + '\n')
+
+
+if __name__ == "__main__":
+    sys.exit(create_address())
index cd50767..08e8c59 100644 (file)
@@ -7,9 +7,8 @@ host = 'http://localhost:9888'
 
 def post(endpoint, parameter):
     headers = {'Content-Type': 'application/json'}
-    data = json.dumps(parameter)
     try:
-        request = requests.post(host + '/' + endpoint, headers=headers, data=data)
+        request = requests.post(host + '/' + endpoint, headers=headers, json=parameter)
     except Exception as e:
         print(str(e) + '\n'
               + 'Connection error:Make sure bytomd run at http://localhost:9888 before you run this script.')