def validate_create_role_state(create_role, state): state_return = state_accessor.get_state( state, [addresser.make_role_attributes_address(create_role.role_id)]) if _role_already_exists(state_return, create_role.role_id): raise InvalidTransaction("Role id {} is already in state".format( create_role.role_id)) users = list(create_role.admins) + list(create_role.owners) user_state_return = state_accessor.get_state( state, [addresser.make_user_address(u) for u in users]) user_validator.validate_list_of_user_are_users(user_state_return, users)
def validate_create_task_state(state_entries, payload): user_validator.validate_list_of_user_are_users(state_entries, payload.admins) user_validator.validate_list_of_user_are_users(state_entries, payload.owners) try: entry = state_accessor.get_state_entry( state_entries, addresser.task.address(payload.task_id)) container = message_accessor.get_task_container(entry) if message_accessor.is_in_task_container(container, payload.task_id): raise InvalidTransaction("Task with id {} already in " "state".format(payload.task_id)) except KeyError: # The task container is not in state, so no at this address. pass