def exec_permission_cmd(self): """ execute permission cmd """ func_name = "self.premisson_service." + self._cmd if self._cmd.startswith("grantUserTable") or self._cmd.startswith("revokeUserTable"): self.check_param_num(2, True) return eval(func_name)(self._args[0], self._args[1]) if self._cmd.startswith("listUser"): self.check_param_num(1, True) result = eval(func_name)(self._args[0]) PermissionService.print_permission_info(result) return None # list functions if self._cmd.startswith("list"): result = eval(func_name)() PermissionService.print_permission_info(result) return None # other functions self.check_param_num(1, True) return eval(func_name)(self._args[0])
def register(self, username, password): ac = Account.create(password) kf = Account.encrypt(ac.privateKey, password) keyfile = "{}/{}.keystore".format(client_config.account_keyfile_path, username) # file is exist, account is registed if os.access(keyfile, os.F_OK): return -1 try: with open(keyfile, "w") as dump_f: json.dump(kf, dump_f) dump_f.close() with open(keyfile, "r") as dump_f: keytext = json.load(dump_f) privkey = Account.decrypt(keytext, password) client_account = Account.from_key(privkey) ps = PermissionService("./pythonsdk/contracts/precompile") ps.grant("t_rep1", client_account.address) ps.grant("t_company", client_account.address) del ps # write file failed except Exception as e: return -2 return 0
def call_permission_precompile(self): """ call permission precompile """ if self._cmd not in self.functions["permission"]: return self.premisson_service = PermissionService(self._contract_path) try: result = self.exec_permission_cmd() self.print_succ_msg(result) except TransactionException as e: self.print_transaction_exception(e) except PrecompileError as e: self.print_error_msg(e) except BcosError as e: self.print_error_msg(e) except CompileError as e: self.print_error_msg(e) except ArgumentsError as e: common.print_error_msg(self._cmd, e) self.print_permission_usage()