Python based Bytom wallet tools
修訂 | 6f0296b1aa220c8f4de56d7f04ca7f8abb039377 (tree) |
---|---|
時間 | 2018-06-28 16:58:31 |
作者 | successli <successli@outl...> |
Commiter | successli |
docs(utxomeger/README.md): add some details to doc.
@@ -3,21 +3,25 @@ | ||
3 | 3 | |
4 | 4 | > **One last disclaimer:** |
5 | 5 | |
6 | -**the code we are about to go over is in no way intended to be used as an example of a robust solution.** | |
6 | +**The code we are about to go over is in no way intended to be used as an example of a robust solution.** | |
7 | 7 | |
8 | 8 | **We wouldn't be responsible for the consequences of using this tool.** |
9 | 9 | |
10 | -**please check this python code carefully and use it later.** | |
10 | +**Please check this python code carefully and use it later.** | |
11 | 11 | |
12 | 12 | |
13 | -Requirements: Python 3.x, with requests package | |
13 | +## Preparation | |
14 | 14 | |
15 | -Dependencies: | |
15 | +- Requirements: Python 3.x, with requests package | |
16 | + | |
17 | +- Dependencies: | |
16 | 18 | ``` |
17 | 19 | pip install requests |
18 | 20 | ``` |
19 | 21 | |
20 | -Usage: | |
22 | +## Usage: | |
23 | + | |
24 | + | |
21 | 25 | ``` |
22 | 26 | ./bytomd init --chain_id mainnet |
23 | 27 | ``` |
@@ -27,7 +31,9 @@ Usage: | ||
27 | 31 | ``` |
28 | 32 | If you don't know how to run bytomd please check this [wiki](https://github.com/Bytom/bytom/wiki/Build-and-Install) |
29 | 33 | |
30 | -Options: | |
34 | +- Options: | |
35 | + | |
36 | + | |
31 | 37 | ``` |
32 | 38 | $ python btmspanner.py utxomerger -h |
33 | 39 | usage: btmspanner.py [-h] [-o URL] [-a ACCOUNT_ALIAS] [-p PASSWORD] |
@@ -56,12 +62,31 @@ optional arguments: | ||
56 | 62 | |
57 | 63 | ``` |
58 | 64 | |
59 | -Example: | |
65 | +## Example | |
66 | + | |
67 | + | |
68 | +**eg.01:** | |
69 | + | |
70 | + ``` | |
71 | +$ python btmspanner.py utxomerger -l | |
72 | + ``` | |
73 | + this example can list all utxos at localhost. | |
74 | + | |
75 | +**eg.02:** | |
76 | + | |
77 | + ``` | |
78 | +$ python btmspanner.py utxomerger -o http://127.0.0.1:9888 -l | |
79 | + ``` | |
80 | + this example can list all utxos at host http://127.0.0.1:9888. | |
81 | + | |
82 | +**eg.03:** | |
83 | + | |
60 | 84 | ``` |
61 | 85 | $ python btmspanner.py utxomerger -o http://127.0.0.1:9888 -a your_account_alias -p your_password -x 41250000000 -s 0 -m 20 -f 3 -y |
62 | 86 | ``` |
63 | 87 | |
64 | -Result: | |
88 | +**Result:** | |
89 | + | |
65 | 90 | ``` |
66 | 91 | $ python btmspanner.py utxomerger -o http://52.83.158.112:9888 -a btmpool_test -p btmpool -x 41250000000 -s 0 -m 20 -f 3 -y |
67 | 92 | 0. 412.50000000 BTM fac1fa4776c43e2159683c6ce7ffdd64734be2bd982d997b59fa8198c6af4d1c (mature) |
@@ -85,19 +85,42 @@ def send_tx(connection, utxo_list, to_address, password): | ||
85 | 85 | |
86 | 86 | def main(): |
87 | 87 | options = parser.parse_args() |
88 | + | |
89 | + if options.only_list: | |
90 | + data, ret = UnspentOutputs.list_UTXO(connection=Connection(options.url)) | |
91 | + if ret == 1: | |
92 | + for i, utxo in enumerate(data): | |
93 | + print('{:4}. {:13.8f} BTM {}{}'.format(i, utxo['amount'] / 1e8, utxo['id'], ' (mature)')) | |
94 | + if i >= 99: | |
95 | + print('...') | |
96 | + print('...') | |
97 | + print('only print 100 utxos.') | |
98 | + break | |
99 | + print("total size of available utxos is {}".format(len(data))) | |
100 | + elif ret == -1: | |
101 | + print("failed error is {}".format(data)) | |
102 | + else: | |
103 | + print(data) | |
104 | + | |
105 | + return | |
106 | + | |
88 | 107 | utxo_total = [] |
89 | 108 | utxolist = list_utxo(options.url, options.account_alias, options.min_amount, options.max_amount) |
90 | 109 | |
91 | 110 | for i, utxo in enumerate(utxolist): |
92 | 111 | print('{:4}. {:13.8f} BTM {}{}'.format(i, utxo['amount'] / 1e8, utxo['id'], ' (mature)')) |
112 | + if i >= 99: | |
113 | + print('...') | |
114 | + print('...') | |
115 | + print('only print 100 utxos.') | |
116 | + break | |
117 | + | |
118 | + for i, utxo in enumerate(utxolist): | |
93 | 119 | if i >= options.merge_list * options.for_loop: |
94 | 120 | break |
95 | 121 | utxo_total.append(utxo) |
96 | 122 | |
97 | - print("total size of available utxos is {}".format(len(utxolist))) | |
98 | - | |
99 | - if options.only_list: | |
100 | - return | |
123 | + print("total size of available utxos is {}\n".format(len(utxolist))) | |
101 | 124 | |
102 | 125 | print('To merge {} UTXOs with {:13.8f} BTM totally.\n'.format(len(utxo_total), |
103 | 126 | sum(utxo['amount'] for utxo in utxo_total) / 1e8)) |