• R/O
  • HTTP
  • SSH
  • HTTPS

bytom-spanner: Commit

Python based Bytom wallet tools


Commit MetaInfo

Revision8ca30ba7041e5c0aa4f6a49f24ba2c12f0ba0fd8 (tree)
Zeit2018-09-28 13:32:15
AutorJohn Chi <jcunionmatrix@gmai...>
CommiterPaladz

Log Message

Time Range and Use Unconfirmed UTXO (#4)

* fix(build transaction): build transaction function add time range and use unconfirmed utxo support

* docs(btmsender): update btmsender document

Ändern Zusammenfassung

Diff

--- a/README.md
+++ b/README.md
@@ -28,6 +28,8 @@ Options:
2828 -a account wallet account id
2929 -p password wallet account password
3030 -c count transaction output count
31+ -u use unconfirmed UTXO build transaction
32+ -t time_range the transaction will not be submitted into block after this height
3133 ```
3234 See more details in btm-sender [README.md](https://github.com/Bytom/btm-spanner/blob/master/btmsender/README.md) file.
3335 ## utxo-merger
--- a/btmsender/README.md
+++ b/btmsender/README.md
@@ -11,11 +11,13 @@ Options:
1111 -a account wallet account id
1212 -p password wallet account password
1313 -c count transaction output count
14+ -u use unconfirmed UTXO build transaction
15+ -t time_range the transaction will not be submitted into block after this height
1416 ```
1517
1618 Example:
1719 ```
18- btmspanner.py btmsender -i btmsender/btm.txt -a 0F0BV1OLG0A04 -p 123456 -c 1000
20+ btmspanner.py btmsender -i btmsender/btm.txt -a 0F0BV1OLG0A04 -p 123456 -c 1000 -u -t 96310
1921 ```
2022
2123 Transaction txt file format:
--- a/btmsender/btm.txt
+++ b/btmsender/btm.txt
@@ -1,5 +1,3 @@
1-bm1qqn5mrdcaz00d0rvqd0zuuh6z4u4a860qfquwys,265024793
2-bm1qufvnqamhyjwl2c58n0t4ej27kr0xzpm4r94578,296430573
3-bm1qyenrv6thy5pl2jhz08xqj7ukg3kcyn2j3mfc7n,266596998
4-bm1qkkwln4xwgxfl4j838ykudecqehxes6szxmy4fl,366249088
5-bm1qhsk20pnxu2yudxrucmx5pccltgew3z0e3wfqv4,225333795
\ No newline at end of file
1+sm1qkg026fh7g0v0fang53xscsz6wjc4q8prfanc7s,5000000000
2+sm1q96zhtsnqxtnn7ydgkyslsgc8hntccu8yyue4yv,5500000000
3+sm1q8fs0625xe6x0k060cluwxtqj7n7q5ju76krchd,3500000000
\ No newline at end of file
--- a/btmsender/btmsender.py
+++ b/btmsender/btmsender.py
@@ -3,5 +3,5 @@ from . import transaction
33
44
55 def sender():
6- path, account_id, password, output_count = validation.validate_input()
7- transaction.handle_input(path, account_id, password, output_count)
6+ path, account_id, password, output_count, use_unconfirmed, time_range = validation.validate_input()
7+ transaction.handle_input(path, account_id, password, output_count, use_unconfirmed, time_range)
--- a/btmsender/transaction.py
+++ b/btmsender/transaction.py
@@ -6,7 +6,7 @@ miner_fee = 40000000
66 max_output_count = 1500
77
88
9-def handle_input(_path, _account_id, _password, _output_count):
9+def handle_input(_path, _account_id, _password, _output_count, _use_unconfirmed, _time_range):
1010 if _output_count <= 0:
1111 _output_count = max_output_count
1212 lines = list()
@@ -16,16 +16,16 @@ def handle_input(_path, _account_id, _password, _output_count):
1616 if len(lines) < _output_count:
1717 lines.append(line)
1818 else:
19- handle_transaction(lines, _path, _account_id, _password)
19+ handle_transaction(lines, _path, _account_id, _password, _use_unconfirmed, _time_range)
2020 lines.clear()
2121 lines.append(line)
2222 if len(lines) > 0:
23- handle_transaction(lines, _path, _account_id, _password)
23+ handle_transaction(lines, _path, _account_id, _password, _use_unconfirmed, _time_range)
2424 print('Transactions are completed.Please check completed.txt')
2525
2626
27-def handle_transaction(lines, _path, _account_id, _password):
28- data = build_transaction(lines, _account_id)
27+def handle_transaction(lines, _path, _account_id, _password, _use_unconfirmed, _time_range):
28+ data = build_transaction(lines, _account_id, _use_unconfirmed, _time_range)
2929 data = sign_transaction(_password, data)
3030 if data['sign_complete']:
3131 data = submit_transaction(data)
@@ -39,7 +39,7 @@ def handle_transaction(lines, _path, _account_id, _password):
3939
4040
4141 # parameter lines: max_output line list
42-def build_transaction(_lines, _account_id):
42+def build_transaction(_lines, _account_id, _use_unconfirmed, _time_range):
4343 amount_sum = 0
4444 action_list = list()
4545 for line in _lines:
@@ -50,9 +50,11 @@ def build_transaction(_lines, _account_id):
5050 address_dict = get_address_dict(amount, address)
5151 action_list.append(address_dict)
5252 amount_sum += miner_fee
53- spend_dict = get_spend_dict(_account_id, int(amount_sum))
53+ spend_dict = get_spend_dict(_account_id, int(amount_sum), _use_unconfirmed)
5454 action_list.insert(0, spend_dict)
5555 parameter = {'base_transaction': None, 'actions': action_list, 'ttl': 0}
56+ if _time_range != 0:
57+ parameter.update(time_range=_time_range)
5658 return httprequest.post('build-transaction', parameter)
5759
5860
@@ -83,8 +85,9 @@ def get_address_dict(_amount, _address):
8385
8486
8587 # spend_account action
86-def get_spend_dict(_account_id, _amount_sum):
88+def get_spend_dict(_account_id, _amount_sum, _use_unconfirmed):
8789 return {'account_id': _account_id,
8890 'amount': _amount_sum,
8991 'asset_id': 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
90- 'type': 'spend_account'}
92+ 'type': 'spend_account',
93+ 'use_unconfirmed': _use_unconfirmed}
--- a/btmsender/validation.py
+++ b/btmsender/validation.py
@@ -26,12 +26,15 @@ def get_input():
2626 parser.add_argument('-a', required=True, help='wallet account id')
2727 parser.add_argument('-p', required=True, help='wallet account password')
2828 parser.add_argument('-c', type=int, default=0, help='transaction max output count')
29+ parser.add_argument('-u', action='store_true', help='use unconfirmed UTXO build transaction')
30+ parser.add_argument('-t', type=int, default=0,
31+ help='the transaction will not be submitted into block after this height')
2932 args = parser.parse_args()
30- return args.i, args.a, args.p, args.c
33+ return args.i, args.a, args.p, args.c, args.u, args.t
3134
3235
3336 def validate_input():
34- input_path, account_id, password, output_count = get_input()
37+ input_path, account_id, password, output_count, use_unconfirmed, time_range = get_input()
3538 # relative path
3639 file_path = os.path.abspath('.') + os.path.sep + input_path
3740 if not os.path.exists(file_path):
@@ -49,4 +52,4 @@ def validate_input():
4952 '\nTotal amount is %.2f BTM(without gas).Send BTM or not?(y/n)' % (total_amount / pow(10, 8)))
5053 if input() != 'y':
5154 sys.exit(0)
52- return file_path, account_id, password, output_count
55+ return file_path, account_id, password, output_count, use_unconfirmed, time_range
Show on old repository browser