def create_master_account(account_object_name, account_name=None, owner_key=None, active_key=None): '''Create master account object in caller's global namespace. Start a singleton :class:`.shell.wallet.Wallet` object if there is no one in the global namespace already. If a local testnet is running, create an account object representing the *eosio* account. Put the account into the wallet. Put the account object into the global namespace of the caller, and return. Otherwise, an outer testnet has to be defined with the function :func:`.core.setup.set_nodeos_address`. If the *account_name* argument is set, check the testnet for presence of the account. If present, create a corresponding object and put the account into the wallet, and put the account object into the global namespace of the caller, and return. Otherwise start a registration procedure: - if the argument *account_name* is not set, make it random - print registration data, namely: - account name - owner public key - active public key - owner private key - active private key - wait for the user to register the master account - . . . . - detect the named account on the remote testnet - put the account into the wallet - put the account object into the global namespace of the caller and \ return Note: Name conflict: If a new account object, named as an existing one, is going to be added to the wallet, an error is reported. Then an offer is given to edith the mapping file in order to resolve the conflict. When the conflict is resolved, the procedure finishes successfully. Args: account_object_name (str): The name of the account object returned. account_name (str or .core.testnet.Testnet): The name of an valid EOSIO account. Must be set if the testnode is not local. owner_key (str or .core.interface.Key): The owner public key. Must be set if the testnode is not local. active_key (str or .core.interface.Key): The active public key. Must be set if the testnode is not local. ''' globals = inspect.stack()[1][0].f_globals if isinstance(account_name, testnet.Testnet): owner_key = account_name.owner_key active_key = account_name.active_key account_name = account_name.account_name if account_object_name: # account_object_name==None in register_testnet ''' Check the conditions: * a *Wallet* object is defined. * the account object name is not in use, already. ''' if not is_wallet_defined(logger, globals): return None if is_in_globals(account_object_name, globals): logger.INFO(''' ######## Account object ``{}`` restored from the blockchain. '''.format(account_object_name)) return globals[account_object_name] logger.INFO(''' ######### Create a master account object ``{}``. '''.format(account_object_name)) ''' If the local testnet is running, create an account object representing the *eosio* account. Put the account into the wallet. Put the account object into the global namespace of the caller, and **return**. ''' if setup.is_local_address: account_object = account.Eosio(account_object_name) put_account_to_wallet_and_on_stack(account_object_name, account_object, logger) return account_object ''' Otherwise, an outer testnet has to be defined with *setup.set_nodeos_address(<url>)*. ''' if manager.is_local_testnet(): if teos.is_local_node_process_running(): raise errors.Error(''' There is an local testnode process running, but its 'eosio` account is not like expected. ''') sys.exit() raise errors.Error(''' If the local testnet is not running, an outer testnet has to be defined with `setup.set_nodeos_address(<url>)`: use 'setup.set_nodeos_address(<URL>)' ''') ''' If the *account_name* argument is not set, it is randomized. Check the testnet for presence of the account. If present, create the corresponding object and see whether it is in the wallets. If so, put the account object into the global namespace of the caller. and **return**. ''' first_while = True while True: account_object = account.GetAccount(account_object_name, account_name, owner_key, active_key) if first_while and account_name and owner_key and active_key \ and not account_object.exists: raise errors.Error(''' There is no account named ``{}`` in the blockchain. '''.format(account_name)) first_while = False if account_object.exists: if account_object.has_keys: # it is your account logger.TRACE(''' * Checking whether the wallet has keys to the account ``{}`` '''.format(account_object.name)) logger.TRACE(''' * The account object is created. ''') if account_object_name: if Account.add_methods_and_finalize( account_object_name, account_object): logger.TRACE(''' * The account ``{}`` is in the wallet. '''.format(account_object.name)) return account_object else: return account_object else: # the name is taken by somebody else logger.TRACE(''' ### You can try another name. Do you wish to do this? ''') decision = input("y/n <<< ") if decision == "y": account_name = input( "enter the account name or nothing to make the name random <<< " ) else: return None else: owner_key_new = cleos.CreateKey(is_verbose=False) active_key_new = cleos.CreateKey(is_verbose=False) logger.OUT(''' Use the following data to register a new account on a public testnet: Account Name: {} Owner Public Key: {} Active Public Key: {} Owner Private Key: {} Active Private Key: {} '''.format(account_object.name, owner_key_new.key_public, active_key_new.key_public, owner_key_new.key_private, active_key_new.key_private)) while True: is_ready = input("enter 'go' when ready or 'q' to quit <<< ") if is_ready == "q": return None else: if is_ready == "go": break account_name = account_object.name owner_key = owner_key_new active_key = active_key_new
def create_master_account(account_object_name, account_name=None, owner_key=None, active_key=None, verbosity=None): '''Create account object in caller's global namespace. - **parameters**:: account_object_name:: the name of the account object account_name: the name of the account; random, if not set verbosity: argument to the internal logger ### Preconditions Check the following conditions: * precisely one ``Wallet`` object is defined; ### Local testnet If the local testnet is running, create an account object representing the ``eosio`` account. Put the account into the wallet. Put the account object into the global namespace of the caller, and **return**. ### Remote testnet Otherwise, an outer testnet has to be defined with ``setup.set_nodeos_address(<url>)``. ### Existing account If the ``account_name`` argument is set, check the testnet for presence of the account. If present, create the corresponding object and put the account into the wallet, and put the account object into the global namespace of the caller. and **return**. Otherwise start a registration procedure, described in the next paragraph. ### Registration to a remote testnet If the ``account_name`` argument is not set or it does not address any existing account, see the previous paragraph, start a registration procedure. * if the ``account_name`` argument is not set, make it random * print registration data, namely: * account name * owner public key * active public key * owner private key * active private key * wait for the user to register the master account * . . . . * detect the named account on the remote testnet * put the account into the wallet * put the account object into the global namespace of the caller ### Name conflict between account objects If the new account object is going to be added to the wallet, an error is reported. Then an offer is given to edith the mapping file in order to resolve the conflict. When the conflict is resolved, the procedure finishes successfully. ''' globals = inspect.stack()[1][0].f_globals if account_object_name: # account_object_name==None in register_testnet ''' Check the conditions: * a ``Wallet`` object is defined. * the account object name is not in use, already. ''' is_wallet_defined(logger, globals) global wallet_singleton if wallet_singleton is None: return if account_object_name in globals: if not isinstance(globals[account_object_name], interface.Account): raise errors.Error(''' The global variable {} type is not ``Account``. '''.format(account_object_name)) return logger.INFO(''' ######## Account object ``{}`` restored from the blockchain. '''.format(account_object_name)) return #wallet_singleton.is_name_taken(account_object_name, account_name) if isinstance(account_name, testnet.Testnet): owner_key = account_name.owner_key active_key = account_name.active_key account_name = account_name.account_name logger.INFO(''' ######### Create a master account object ``{}``. '''.format(account_object_name)) ''' If the local testnet is running, create an account object representing the ``eosio`` account. Put the account into the wallet. Put the account object into the global namespace of the caller, and **return**. ''' account_object = Eosio(account_object_name) if is_local_testnet_running(account_object): put_account_to_wallet_and_on_stack(account_object_name, account_object, logger) return ''' Otherwise, an outer testnet has to be defined with ``setup.set_nodeos_address(<url>)``. ''' if manager.is_local_testnet(): if teos.is_local_node_process_running(): raise errors.Error(''' There is an local testnode process running, but its 'eosio` account is not like expected. ''') raise errors.Error(''' If the local testnet is not running, an outer testnet has to be defined with `setup.set_nodeos_address(<url>)`: use 'setup.set_nodeos_address(<URL>)' ''') ''' If the ``account_name`` argument is not set, it is randomized. Check the testnet for presence of the account. If present, create the corresponding object and see whether it is in the wallets. If so, put the account object into the global namespace of the caller. and **return**. ''' first_while = True while True: account_object = GetAccount(account_object_name, account_name, owner_key, active_key, verbosity) if first_while and account_name and owner_key and active_key \ and not account_object.exists: raise errors.Error(''' There is no account named ``{}`` in the blockchain. '''.format(account_name)) return first_while = False if account_object.exists: if account_object.has_keys: # it is your account logger.TRACE(''' * Checking whether the wallet has keys to the account ``{}`` '''.format(account_object.name)) logger.TRACE(''' * The account object is created. ''') if account_object_name: if append_account_methods_and_finish( account_object_name, account_object): logger.TRACE(''' * The account ``{}`` is in the wallet. '''.format(account_object.name)) return else: return account_object else: # the name is taken by somebody else logger.TRACE(''' ### You can try another name. Do you wish to do this? ''') decision = input("y/n <<< ") if decision == "y": account_name = input( "enter the account name or nothing to make the name random <<< " ) else: return else: owner_key_new = cleos.CreateKey("owner", is_verbose=False) active_key_new = cleos.CreateKey("active", is_verbose=False) logger.OUT(''' Use the following data to register a new account on a public testnet: Account Name: {} Owner Public Key: {} Active Public Key: {} Owner Private Key: {} Active Private Key: {} '''.format(account_object.name, owner_key_new.key_public, active_key_new.key_public, owner_key_new.key_private, active_key_new.key_private)) while True: is_ready = input("enter 'go' when ready or 'q' to quit <<< ") if is_ready == "q": return else: if is_ready == "go": break account_name = account_object.name owner_key = owner_key_new active_key = active_key_new