-
Notifications
You must be signed in to change notification settings - Fork 5
/
update_keys.py
executable file
·76 lines (60 loc) · 2.37 KB
/
update_keys.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python
import sys
from pprint import pformat
from typing import List, Tuple
import click
from bitshares.account import Account
from bitshares.exceptions import MissingKeyError
from bitsharesbase import operations
from uptick.decorators import unlock
from bitsharesscripts.decorators import chain, common_options
from bitsharesscripts.functions import generate_password, get_keys_from_password
@click.command()
@common_options
@chain
@unlock
@click.option('-p', '--password', help='manually specify a password (if not, a random will be generated)')
@click.option('--broadcast', default=False, is_flag=True, help='broadcast transaction')
@click.argument('account_name')
@click.pass_context
def main(ctx, password, broadcast, account_name):
"""Use this script to change account keys.
By default, a random will be generated. By default, transaction will not be broadcasted (dry-run mode).
"""
account = Account(account_name, bitshares_instance=ctx.bitshares)
# random password
if not password:
password = generate_password()
print('password: {}\n'.format(password))
key = get_keys_from_password(account_name, password, ctx.bitshares.prefix)
# prepare for json format
account['options']['memo_key'] = key['memo']
owner_key_authority = [(key['owner'], 1)]
active_key_authority = [(key['active'], 1)]
owner_accounts_authority: List[Tuple[str, int]] = []
active_accounts_authority: List[Tuple[str, int]] = []
pre_op = {
'account': account['id'],
'new_options': account['options'],
'owner': {'account_auths': owner_accounts_authority, 'key_auths': owner_key_authority, 'weight_threshold': 1},
'active': {
'account_auths': active_accounts_authority,
'key_auths': active_key_authority,
'weight_threshold': 1,
},
'fee': {'amount': 0, 'asset_id': '1.3.0'},
'extensions': {},
'prefix': ctx.bitshares.prefix,
}
op = operations.Account_update(**pre_op)
ctx.log.debug(pformat(op.json()))
if not broadcast:
ctx.log.info('Not broadcasting!')
sys.exit(0)
try:
ctx.bitshares.finalizeOp(op, account_name, 'owner')
except MissingKeyError:
ctx.log.critical('No key for {} in storage, use `uptick addkey` to add'.format(account_name))
sys.exit(1)
if __name__ == '__main__':
main()