def _role_already_exists(state_return, role_id): if not state_return: return False role_attr_container = role_state_pb2.RoleAttributesContainer() role_attr_container.ParseFromString(state_return[0].data) return message_accessor.is_in_role_attributes_container( container=role_attr_container, identifier=role_id)
def validate_identifier_is_role(state_entries, identifier, address): """Validate that the identifier references a Role or raise an InvalidTransaction if that user does not exist. Args: state_entries (list): List of StateEntry as returned from state get. identifier (str): The identifier of the role. address (str): The address used to get the role container. Raises: InvalidTransaction: No Role with that identifier exists. """ try: container = message_accessor.get_role_container( state_accessor.get_state_entry(state_entries, address) ) if not message_accessor.is_in_role_attributes_container(container, identifier): raise InvalidTransaction("{} is not a role".format(identifier)) except KeyError: raise InvalidTransaction("{} is not a role".format(identifier))