-
Notifications
You must be signed in to change notification settings - Fork 5
/
create_account.py
executable file
·57 lines (45 loc) · 1.67 KB
/
create_account.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
#!/usr/bin/env python
import sys
import click
from bitshares.account import Account
from bitshares.exceptions import MissingKeyError
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('parent_account')
@click.argument('account_name')
@click.pass_context
def main(ctx, password, broadcast, parent_account, account_name):
"""Use this script to create new account.
By default, a random password will be generated. By default, transaction will not be broadcasted (dry-run mode).
"""
account = Account(parent_account, bitshares_instance=ctx.bitshares)
# random password
if not password:
password = generate_password()
print('password: {}\n'.format(password))
# prints keys to stdout
get_keys_from_password(account_name, password, ctx.bitshares.prefix)
if not broadcast:
ctx.log.info('Not broadcasting!')
sys.exit(0)
try:
ctx.bitshares.create_account(
account_name,
registrar=parent_account,
referrer=account['id'],
referrer_percent=0,
password=password,
storekeys=True,
)
except MissingKeyError:
ctx.log.critical('No key for {} in storage, use `uptick addkey` to add'.format(parent_account))
sys.exit(1)
if __name__ == '__main__':
main()