def update_memo_key(self, key, account=None): """ Update an account's memo public key This method does **not** add any private keys to your wallet but merely changes the memo public key. :param str key: New memo public key :param str account: (optional) the account to allow access to (defaults to ``default_account``) """ if not account: if "default_account" in config: account = config["default_account"] if not account: raise ValueError("You need to provide an account") PublicKey(key, prefix=self.rpc.chain_params["prefix"]) account = Account(account, peerplays_instance=self) account["options"]["memo_key"] = key op = operations.Account_update( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "account": account["id"], "new_options": account["options"], "extensions": {} }) return self.finalizeOp(op, account["name"], "active")
def disapprovecommittee(self, committees, account=None): """ Disapprove a committee :param list committees: list of committee name or id :param str account: (optional) the account to allow access to (defaults to ``default_account``) """ if not account: if "default_account" in config: account = config["default_account"] if not account: raise ValueError("You need to provide an account") account = Account(account, peerplays_instance=self) options = account["options"] if not isinstance(committees, (list, set)): committees = set(committees) for committee in committees: committee = Committee(committee, peerplays_instance=self) if committee["vote_id"] in options["votes"]: options["votes"].remove(committee["vote_id"]) options["votes"] = list(set(options["votes"])) options["num_committee"] = len( list( filter(lambda x: float(x.split(":")[0]) == 0, options["votes"]))) op = operations.Account_update( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "account": account["id"], "new_options": options, "extensions": {}, "prefix": self.rpc.chain_params["prefix"] }) return self.finalizeOp(op, account["name"], "active")
def approvewitness(self, witnesses, account=None): """ Approve a witness :param list witnesses: list of Witness name or id :param str account: (optional) the account to allow access to (defaults to ``default_account``) """ if not account: if "default_account" in config: account = config["default_account"] if not account: raise ValueError("You need to provide an account") account = Account(account, peerplays_instance=self) options = account["options"] if not isinstance(witnesses, (list, set)): witnesses = set(witnesses) for witness in witnesses: witness = Witness(witness, peerplays_instance=self) options["votes"].append(witness["vote_id"]) options["votes"] = list(set(options["votes"])) options["num_witness"] = len( list( filter(lambda x: float(x.split(":")[0]) == 1, options["votes"]))) op = operations.Account_update( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "account": account["id"], "new_options": options, "extensions": {}, "prefix": self.rpc.chain_params["prefix"] }) return self.finalizeOp(op, account["name"], "active")
def disallow(self, foreign, permission="active", account=None, threshold=None): """ Remove additional access to an account by some other public key or account. :param str foreign: The foreign account that will obtain access :param str permission: (optional) The actual permission to modify (defaults to ``active``) :param str account: (optional) the account to allow access to (defaults to ``default_account``) :param int threshold: The threshold that needs to be reached by signatures to be able to interact """ if not account: if "default_account" in config: account = config["default_account"] if not account: raise ValueError("You need to provide an account") if permission not in ["owner", "active"]: raise ValueError( "Permission needs to be either 'owner', or 'active") account = Account(account, peerplays_instance=self) authority = account[permission] try: pubkey = PublicKey(foreign, prefix=self.rpc.chain_params["prefix"]) affected_items = list( filter(lambda x: x[0] == str(pubkey), authority["key_auths"])) authority["key_auths"] = list( filter(lambda x: x[0] != str(pubkey), authority["key_auths"])) except: try: foreign_account = Account(foreign, peerplays_instance=self) affected_items = list( filter(lambda x: x[0] == foreign_account["id"], authority["account_auths"])) authority["account_auths"] = list( filter(lambda x: x[0] != foreign_account["id"], authority["account_auths"])) except: raise ValueError( "Unknown foreign account or unvalid public key") removed_weight = affected_items[0][1] # Define threshold if threshold: authority["weight_threshold"] = threshold # Correct threshold (at most by the amount removed from the # authority) try: self._test_weights_treshold(authority) except: log.critical("The account's threshold will be reduced by %d" % (removed_weight)) authority["weight_threshold"] -= removed_weight self._test_weights_treshold(authority) op = operations.Account_update( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "account": account["id"], permission: authority, "extensions": {} }) if permission == "owner": return self.finalizeOp(op, account["name"], "owner") else: return self.finalizeOp(op, account["name"], "active")
def allow(self, foreign, weight=None, permission="active", account=None, threshold=None): """ Give additional access to an account by some other public key or account. :param str foreign: The foreign account that will obtain access :param int weight: (optional) The weight to use. If not define, the threshold will be used. If the weight is smaller than the threshold, additional signatures will be required. (defaults to threshold) :param str permission: (optional) The actual permission to modify (defaults to ``active``) :param str account: (optional) the account to allow access to (defaults to ``default_account``) :param int threshold: The threshold that needs to be reached by signatures to be able to interact """ from copy import deepcopy if not account: if "default_account" in config: account = config["default_account"] if not account: raise ValueError("You need to provide an account") if permission not in ["owner", "active"]: raise ValueError( "Permission needs to be either 'owner', or 'active") account = Account(account, peerplays_instance=self) if not weight: weight = account[permission]["weight_threshold"] authority = deepcopy(account[permission]) try: pubkey = PublicKey(foreign, prefix=self.rpc.chain_params["prefix"]) authority["key_auths"].append([str(pubkey), weight]) except: try: foreign_account = Account(foreign, peerplays_instance=self) authority["account_auths"].append( [foreign_account["id"], weight]) except: raise ValueError( "Unknown foreign account or invalid public key") if threshold: authority["weight_threshold"] = threshold self._test_weights_treshold(authority) op = operations.Account_update( **{ "fee": { "amount": 0, "asset_id": "1.3.0" }, "account": account["id"], permission: authority, "extensions": {}, "prefix": self.rpc.chain_params["prefix"] }) if permission == "owner": return self.finalizeOp(op, account["name"], "owner") else: return self.finalizeOp(op, account["name"], "active")