def __init__( self, account_object_name, name=None, owner_key=None, active_key=None, verbosity=None): self.account_object_name = account_object_name if name is None: self.name = cleos.account_name() else: self.name = name if active_key is None: active_key = owner_key self.exists = False self.in_wallet_on_stack = False #self.has_keys = owner_key and not owner_key.key_private is None self.has_keys = not owner_key is None try: cleos.GetAccount.__init__( self, self.name, is_info=False, is_verbose=False) except errors.AccountDoesNotExistError: return self.exists = True if owner_key is None: self.owner_key = cleos.CreateKey( "owner", self.json["permissions"][1]["required_auth"]["keys"] \ [0]["key"], is_verbose=0) else: # an orphan account, private key is restored from cache self.owner_key = cleos.CreateKey( "owner", self.json["permissions"][1]["required_auth"]["keys"] \ [0]["key"], interface.key_arg( owner_key, is_owner_key=True, is_private_key=True), is_verbose=0) if active_key is None: self.owner_key = cleos.CreateKey( "owner", self.json["permissions"][0]["required_auth"]["keys"] \ [0]["key"], is_verbose=0) else: # an orphan account, private key is restored from cache self.active_key = cleos.CreateKey( "active", self.json["permissions"][0]["required_auth"]["keys"] \ [0]["key"], interface.key_arg( active_key, is_owner_key=False, is_private_key=True), is_verbose=0) logger.TRACE(''' * Account ``{}`` exists in the blockchain. '''.format(self.name))
def __init__(self, key, is_verbose=True): public_key = interface.key_arg(key, is_owner_key=True, is_private_key=False) _Cleos.__init__(self, [public_key], "get", "accounts", is_verbose) self.names = self.json['account_names'] self.printself()
def __init__(self, key, wallet="default", is_verbose=True): key_private = interface.key_arg(key, is_owner_key=True, is_private_key=True) _Cleos.__init__(self, [ "--private-key", key_private, "--name", interface.wallet_arg(wallet) ], "wallet", "import", is_verbose) self.json["key_private"] = key_private self.key_private = key_private self.printself()
def __init__(self, key, wallet, password, is_verbose=True): key_public = interface.key_arg(key, is_owner_key=True, is_private_key=False) _Cleos.__init__(self, [ key_public, "--name", interface.wallet_arg(wallet), "--password", password ], "wallet", "remove_key", is_verbose) self.json["key_public"] = key_public self.key_public = key_public self.printself()
def remove_key(self, account_or_key): ''' ''' self.open_unlock() removed_keys = [] account_name = None if isinstance(account_or_key, interface.Account): cleos.WalletRemove_key(interface.key_arg(account_or_key, is_owner_key=True, is_private_key=True), self.name, is_verbose=False) removed_keys.append( interface.key_arg(account_or_key, is_owner_key=True, is_private_key=False)) cleos.WalletRemove_key(interface.key_arg(account_or_key, is_owner_key=False, is_private_key=True), self.name, is_verbose=False) removed_keys.append( interface.key_arg(account_or_key, is_owner_key=False, is_private_key=False)) else: cleos.WalletRemove_key(interface.key_arg(account_or_key, is_private_key=True), self.name, is_verbose=False) removed_keys.append( interface.key_arg(account_or_key, is_private_key=False)) if account_name is None: if len(removed_keys) > 0: logger.TRACE( ''' Removing key '{}' from the wallet '{}' '''.format(removed_keys[0], self.name), verbosity) else: logger.TRACE(''' Removing keys of the account '{}' from the wallet '{}' '''.format(account_name, self.name)) wallet_keys = cleos.WalletKeys(is_verbose=False) for key in removed_keys: if key in wallet_keys.json: raise errors.Error(''' Failed to remove key '{}' from the wallet '{}' '''.format(key, self.name)) logger.TRACE(''' * Cross-checked: all listed keys removed from the wallet. ''') return True
def __init__(self, account, table, scope, binary=False, limit=10, key="", lower="", upper="", is_verbose=True): args = [interface.account_arg(account)] if not scope: scope = self.name else: try: scope_name = scope.name except: scope_name = scope args.append(scope_name) args.append(table) if binary: args.append("--binary") if limit: args.extend(["--limit", str(limit)]) if key: args.extend([ "--key", interface.key_arg(key, is_owner_key=False, is_private_key=False) ]) if lower: args.extend(["--lower", lower]) if upper: args.extend(["--upper", upper]) _Cleos.__init__(self, args, "get", "table", is_verbose) self.printself()
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 __init__(self, creator, name, owner_key, active_key=None, permission=None, expiration_sec=30, skip_signature=0, dont_broadcast=0, forceUnique=0, max_cpu_usage=0, max_net_usage=0, ref_block=None, is_verbose=True): 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 owner_key_public = interface.key_arg(owner_key, is_owner_key=True, is_private_key=False) active_key_public = interface.key_arg(active_key, is_owner_key=False, is_private_key=False) args = [ interface.account_arg(creator), self.name, owner_key_public, active_key_public ] args.append("--json") if not permission is None: p = interface.permission_arg(permission) for perm in p: args.extend(["--permission", perm]) args.extend(["--expiration", str(expiration_sec)]) 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.__init__(self, args, "create", "account", is_verbose) self.json = GetAccount(self.name, is_verbose=False, is_info=False).json self.printself()
def import_key(self, account_or_key): ''' Imports private keys of an account into wallet. Returns list of `cleos.WalletImport` objects ''' self.open_unlock() imported_keys = [] account_name = None if isinstance(account_or_key, interface.Account): account_name = account_or_key.name wallet_import = cleos.WalletImport(interface.key_arg( account_or_key, is_owner_key=True, is_private_key=True), self.name, is_verbose=False) imported_keys.append( interface.key_arg(account_or_key, is_owner_key=True, is_private_key=False)) wallet_import = cleos.WalletImport(interface.key_arg( account_or_key, is_owner_key=False, is_private_key=True), self.name, is_verbose=False) imported_keys.append( interface.key_arg(account_or_key, is_owner_key=False, is_private_key=False)) logger.TRACE(''' * Importing keys of the account ``{}`` into the wallet ``{}`` '''.format(account_name, self.name)) else: wallet_import = cleos.WalletImport(interface.key_arg( account_or_key, is_private_key=True), self.name, is_verbose=False) logger.TRACE(''' * Importing keys into the wallet ``{}`` '''.format(self.name)) return True wallet_keys = cleos.WalletKeys(is_verbose=False) if len(imported_keys) == 0: raise errors.Error(''' The list of imported keys is empty. ''') ok = True for key in imported_keys: if not key in wallet_keys.json: ok = False raise errors.Error(''' Failed to import keys of the account '{}' into the wallet '{}' '''.format(account_name if account_name else "n/a", self.name)) if ok: logger.TRACE(''' * Cross-checked: all account keys are in the wallet. ''') return True