OSDN Git Service

Time Range and Use Unconfirmed UTXO (#4)
authorJohn Chi <jcunionmatrix@gmail.com>
Fri, 28 Sep 2018 04:32:15 +0000 (12:32 +0800)
committerPaladz <yzhu101@uottawa.ca>
Fri, 28 Sep 2018 04:32:15 +0000 (12:32 +0800)
* fix(build transaction): build transaction function add time range and use unconfirmed utxo support

* docs(btmsender): update btmsender document

README.md
btmsender/README.md
btmsender/btm.txt
btmsender/btmsender.py
btmsender/transaction.py
btmsender/validation.py

index 8088ddc..f608df7 100644 (file)
--- a/README.md
+++ b/README.md
@@ -28,6 +28,8 @@ Options:
   -a account      wallet account id
   -p password     wallet account password
   -c count        transaction output count
+  -u              use unconfirmed UTXO build transaction
+  -t time_range   the transaction will not be submitted into block after this height
   ```
 See more details in btm-sender [README.md](https://github.com/Bytom/btm-spanner/blob/master/btmsender/README.md) file.
 ## utxo-merger
index a959785..e9b99aa 100644 (file)
@@ -11,11 +11,13 @@ Options:
   -a account      wallet account id
   -p password     wallet account password
   -c count        transaction output count
+  -u              use unconfirmed UTXO build transaction
+  -t time_range   the transaction will not be submitted into block after this height
   ```
 
 Example:
    ```
-    btmspanner.py btmsender -i btmsender/btm.txt -a 0F0BV1OLG0A04 -p 123456 -c 1000
+    btmspanner.py btmsender -i btmsender/btm.txt -a 0F0BV1OLG0A04 -p 123456 -c 1000 -u -t 96310
    ```
 
 Transaction txt file format:
index 4380661..d4500e9 100644 (file)
@@ -1,5 +1,3 @@
-bm1qqn5mrdcaz00d0rvqd0zuuh6z4u4a860qfquwys,265024793
-bm1qufvnqamhyjwl2c58n0t4ej27kr0xzpm4r94578,296430573
-bm1qyenrv6thy5pl2jhz08xqj7ukg3kcyn2j3mfc7n,266596998
-bm1qkkwln4xwgxfl4j838ykudecqehxes6szxmy4fl,366249088
-bm1qhsk20pnxu2yudxrucmx5pccltgew3z0e3wfqv4,225333795
\ No newline at end of file
+sm1qkg026fh7g0v0fang53xscsz6wjc4q8prfanc7s,5000000000
+sm1q96zhtsnqxtnn7ydgkyslsgc8hntccu8yyue4yv,5500000000
+sm1q8fs0625xe6x0k060cluwxtqj7n7q5ju76krchd,3500000000
\ No newline at end of file
index 04c9e7f..d3e1bd9 100755 (executable)
@@ -3,5 +3,5 @@ from . import transaction
 
 
 def sender():
-    path, account_id, password, output_count = validation.validate_input()
-    transaction.handle_input(path, account_id, password, output_count)
+    path, account_id, password, output_count, use_unconfirmed, time_range = validation.validate_input()
+    transaction.handle_input(path, account_id, password, output_count, use_unconfirmed, time_range)
index 0a6e4df..9203665 100644 (file)
@@ -6,7 +6,7 @@ miner_fee = 40000000
 max_output_count = 1500
 
 
-def handle_input(_path, _account_id, _password, _output_count):
+def handle_input(_path, _account_id, _password, _output_count, _use_unconfirmed, _time_range):
     if _output_count <= 0:
         _output_count = max_output_count
     lines = list()
@@ -16,16 +16,16 @@ def handle_input(_path, _account_id, _password, _output_count):
             if len(lines) < _output_count:
                 lines.append(line)
             else:
-                handle_transaction(lines, _path, _account_id, _password)
+                handle_transaction(lines, _path, _account_id, _password, _use_unconfirmed, _time_range)
                 lines.clear()
                 lines.append(line)
     if len(lines) > 0:
-        handle_transaction(lines, _path, _account_id, _password)
+        handle_transaction(lines, _path, _account_id, _password, _use_unconfirmed, _time_range)
     print('Transactions are completed.Please check completed.txt')
 
 
-def handle_transaction(lines, _path, _account_id, _password):
-    data = build_transaction(lines, _account_id)
+def handle_transaction(lines, _path, _account_id, _password, _use_unconfirmed, _time_range):
+    data = build_transaction(lines, _account_id, _use_unconfirmed, _time_range)
     data = sign_transaction(_password, data)
     if data['sign_complete']:
         data = submit_transaction(data)
@@ -39,7 +39,7 @@ def handle_transaction(lines, _path, _account_id, _password):
 
 
 # parameter lines: max_output line list
-def build_transaction(_lines, _account_id):
+def build_transaction(_lines, _account_id, _use_unconfirmed, _time_range):
     amount_sum = 0
     action_list = list()
     for line in _lines:
@@ -50,9 +50,11 @@ def build_transaction(_lines, _account_id):
         address_dict = get_address_dict(amount, address)
         action_list.append(address_dict)
     amount_sum += miner_fee
-    spend_dict = get_spend_dict(_account_id, int(amount_sum))
+    spend_dict = get_spend_dict(_account_id, int(amount_sum), _use_unconfirmed)
     action_list.insert(0, spend_dict)
     parameter = {'base_transaction': None, 'actions': action_list, 'ttl': 0}
+    if _time_range != 0:
+        parameter.update(time_range=_time_range)
     return httprequest.post('build-transaction', parameter)
 
 
@@ -83,8 +85,9 @@ def get_address_dict(_amount, _address):
 
 
 # spend_account action
-def get_spend_dict(_account_id, _amount_sum):
+def get_spend_dict(_account_id, _amount_sum, _use_unconfirmed):
     return {'account_id': _account_id,
             'amount': _amount_sum,
             'asset_id': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
-            'type': 'spend_account'}
+            'type': 'spend_account',
+            'use_unconfirmed': _use_unconfirmed}
index 9af6800..85c89c1 100755 (executable)
@@ -26,12 +26,15 @@ def get_input():
     parser.add_argument('-a', required=True, help='wallet account id')
     parser.add_argument('-p', required=True, help='wallet account password')
     parser.add_argument('-c', type=int, default=0, help='transaction max output count')
+    parser.add_argument('-u', action='store_true', help='use unconfirmed UTXO build transaction')
+    parser.add_argument('-t', type=int, default=0,
+                        help='the transaction will not be submitted into block after this height')
     args = parser.parse_args()
-    return args.i, args.a, args.p, args.c
+    return args.i, args.a, args.p, args.c, args.u, args.t
 
 
 def validate_input():
-    input_path, account_id, password, output_count = get_input()
+    input_path, account_id, password, output_count, use_unconfirmed, time_range = get_input()
     # relative path
     file_path = os.path.abspath('.') + os.path.sep + input_path
     if not os.path.exists(file_path):
@@ -49,4 +52,4 @@ def validate_input():
           '\nTotal amount is %.2f BTM(without gas).Send BTM or not?(y/n)' % (total_amount / pow(10, 8)))
     if input() != 'y':
         sys.exit(0)
-    return file_path, account_id, password, output_count
+    return file_path, account_id, password, output_count, use_unconfirmed, time_range