def restore_accounts(self): ''' ''' self.open_unlock() account_map = manager.account_map() new_map = {} wallet_keys = cleos.WalletKeys(is_verbose=0) if len(account_map) > 0: logger.INFO(''' ######### Restore cached account objects: ''') for name, object_name in account_map.items(): try: account_ = cleos.GetAccount(name, is_info=False, is_verbose=False) if account_.owner_key in wallet_keys.json and \ account_.active_key in wallet_keys.json: new_map[name] = object_name from shell.account import create_account create_account(object_name, name, restore=True, verbosity=None) except errors.AccountDoesNotExistError: pass manager.save_account_map(new_map) else: logger.INFO(''' * The wallet is empty. ''')
def print_stats( accounts, params, last_col="%s", col="%15s" ): def find(element, json): try: keys = element.split('.') rv = json for key in keys: rv = rv[key] except: rv = "n/a" return rv jsons = [] for account in accounts: json = cleos.GetAccount(account, is_info=False, is_verbose=0).json json["account_object_name"] = account.account_object_name jsons.append(json) header = "" for json in jsons: header = header + col % (json["account_object_name"]) output = ".\n" + header + "\n" for param in params: for json in jsons: output = output + col % find(param, json) output = output + " " + last_col % (param) + "\n" logger.OUT(output, translate=False)
def is_local_testnet_running(): account_ = cleos.GetAccount(self.name, is_info=False, is_verbose=False) if not account_.error and \ self.key_public == \ account_.json["permissions"][0]["required_auth"]["keys"] \ [0]["key"]: self.account_info = str(account_) logger.TRACE(''' Local testnet is ON: the `eosio` account is master. ''') return True else: return False
def is_local_testnet_running(account_eosio): try: account_ = cleos.GetAccount( account_eosio.name, is_info=False, is_verbose=0) except: return False try: # remote eosio may have the ["keys"] array empty. return account_eosio.owner_key.key_public == \ account_.json["permissions"][1]["required_auth"]["keys"] \ [0]["key"] except: False
def __init__(self, creator, name, owner_key, active_key, stake_net, stake_cpu, permission=None, buy_ram_kbytes=0, buy_ram="", transfer=False, expiration_sec=30, skip_signature=0, dont_broadcast=0, forceUnique=0, max_cpu_usage=0, max_net_usage=0, ref_block=None, is_verbose=1): stake_net = "{} EOS".format(stake_net) stake_cpu = "{} EOS".format(stake_cpu) if name is None: name = account_name() interface.Account.__init__(self, name) self.owner_key = None # private keys self.active_key = None if active_key is None: active_key = owner_key args = [ interface.account_arg(creator), self.name, interface.key_arg(owner_key, is_owner_key=True, is_private_key=False), interface.key_arg(active_key, is_owner_key=False, is_private_key=False) ] args.append("--json") args.extend(["--stake-net", stake_net, "--stake-cpu", stake_cpu]) if buy_ram_kbytes: args.extend(["--buy-ram-kbytes", str(buy_ram_kbytes)]) if buy_ram: args.extend(["--buy-ram", str(buy_ram)]) if transfer: args.extend(["--transfer"]) if not permission is None: p = interface.permission_arg(permission) for perm in p: args.extend(["--permission", perm]) if skip_signature: args.append("--skip-sign") if dont_broadcast: args.append("--dont-broadcast") if forceUnique: args.append("--force-unique") if max_cpu_usage: args.extend(["--max-cpu-usage-ms", str(max_cpu_usage)]) if max_net_usage: args.extend(["--max-net-usage", str(max_net_usage)]) if not ref_block is None: args.extend(["--ref-block", ref_block]) cleos._Cleos.__init__(self, args, "system", "newaccount", is_verbose) self.json = cleos.GetAccount(self.name, is_verbose=0, is_info=False).json if self.is_verbose: print(self.__str__())
def info(self): print(str(cleos.GetAccount(self.name, is_verbose=1)))
def info(account_object): print("Account object name: {}\n{}".format( account_object_name, str(cleos.GetAccount(account_object.name, is_verbose=0))))
def append_account_methods_and_finish(account_object_name, account_object): def code(account_object, code="", abi="", wasm=False): result = cleos.GetCode(account_object, code, abi, is_verbose=False) logger.INFO(''' * code() ''') logger.OUT(result.out_msg) account_object.code = types.MethodType(code, account_object) def is_code(account_object): get_code = cleos.GetCode(account_object.name, is_verbose=False) if get_code.code_hash == \ "0000000000000000000000000000000000000000000000000000000000000000": return "" else: return get_code.code_hash account_object.is_code = types.MethodType(is_code, account_object) def set_contract( account_object, contract_dir, wast_file="", abi_file="", permission=None, expiration_sec=30, skip_signature=0, dont_broadcast=0, forceUnique=0, max_cpu_usage=0, max_net_usage=0, ref_block=None): result = cleos.SetContract( account_object, contract_dir, wast_file, abi_file, permission, expiration_sec, skip_signature, dont_broadcast, forceUnique, max_cpu_usage, max_net_usage, ref_block, is_verbose=False ) logger.OUT(result) account_object.set_contract = result account_object.set_contract = types.MethodType( set_contract , account_object) def push_action( account_object, action, data, permission=None, expiration_sec=30, skip_signature=0, dont_broadcast=0, forceUnique=0, max_cpu_usage=0, max_net_usage=0, ref_block=None, json=False): data = _data_json(data) result = cleos.PushAction( account_object, action, data, permission, expiration_sec, skip_signature, dont_broadcast, forceUnique, max_cpu_usage, max_net_usage, ref_block, is_verbose=False, json=True) logger.INFO(''' * Push action ``{}``: '''.format(action)) logger.INFO(''' {} '''.format(re.sub(' +',' ', data))) account_object.action = result try: account_object._console = result.console logger.DEBUG(account_object._console) except: pass if json: logger.OUT(result.out_msg) account_object.action = result account_object.push_action = types.MethodType( push_action, account_object) def show_action(account_object, action, data, permission=None): ''' Implements the `push action` command without broadcasting. ''' account_object.push_action( action, data, permission, dont_broadcast=1, json=True) account_object.show_action = types.MethodType( show_action, account_object) def table( account_object, table_name, scope="", binary=False, limit=10, key="", lower="", upper=""): logger.INFO(''' * Table ``{}`` for ``{}`` '''.format(table_name, scope)) result = cleos.GetTable( account_object, table_name, scope, binary, limit, key, lower, upper, is_verbose=False) try: account_map = manager.account_map() scope = account_map[str(scope)] except: pass logger.OUT(result.out_msg) return result account_object.table = types.MethodType(table, account_object) def __str__(account_object): return account_object.name account_object.__str__ = types.MethodType(__str__, account_object) def buy_ram( account_object, amount_kbytes, receiver=None, expiration_sec=30, skip_signature=0, dont_broadcast=0, forceUnique=0, max_cpu_usage=0, max_net_usage=0, ref_block=None): if manager.is_local_testnet(): return if receiver is None: receiver = account_object buy_ram_kbytes = 1 result = cleosys.BuyRam( account_object, receiver, amount_kbytes, buy_ram_kbytes, expiration_sec, skip_signature, dont_broadcast, forceUnique, max_cpu_usage, max_net_usage, ref_block, is_verbose=0 ) logger.INFO(''' * Transfered RAM from {} to {} kbytes: {} '''.format(result.payer, result.receiver, result.amount)) account_object.buy_ram = types.MethodType(buy_ram, account_object) def delegate_bw( account_object, stake_net_quantity, stake_cpu_quantity, receiver=None, permission=None, transfer=False, expiration_sec=30, skip_signature=0, dont_broadcast=0, forceUnique=0, max_cpu_usage=0, max_net_usage=0, ref_block=None, is_verbose=1): if manager.is_local_testnet(): return if receiver is None: receiver = account_object result = cleosys.DelegateBw( account_object, receiver, stake_net_quantity, stake_cpu_quantity, permission, transfer, expiration_sec, skip_signature, dont_broadcast, forceUnique, max_cpu_usage, max_net_usage, ref_block, is_verbose=0 ) logger.INFO(''' * Delegated stake from {} to {} NET: {} CPU: {} '''.format( result.payer, result.receiver, result.stake_net_quantity, result.stake_cpu_quantity)) account_object.delegate_bw = types.MethodType(delegate_bw, account_object) def info(account_object): print("Account object name: {}\n{}".format( account_object_name, str(cleos.GetAccount(account_object.name, is_verbose=0)))) account_object.info = types.MethodType(info, account_object) get_account = cleos.GetAccount(account_object, is_info=False, is_verbose=0) logger.TRACE(''' * Cross-checked: account object ``{}`` mapped to an existing account ``{}``. '''.format(account_object_name, account_object.name), translate=False) return put_account_to_wallet_and_on_stack( account_object_name, account_object)
def info(self): get_account = cleos.GetAccount(self.name, is_verbose=False) print("account object name: {}\n{}".format( self.account_object_name, get_account))
def info(self): print("account object name: {}\nname: {}\n{}".format( self.account_object_name, self.name, cleos.GetAccount(self.name, is_verbose=False).out_msg))