def validate_identifier_is_task(state_entries, identifier, address): try: container = message_accessor.get_task_container( state_accessor.get_state_entry(state_entries, address)) if not message_accessor.is_in_task_container(container, identifier): raise InvalidTransaction("{} is not a task.".format(identifier)) except KeyError: raise InvalidTransaction("{} is not a task".format(identifier))
def create_task(state_entries, payload, state): try: entry = state_accessor.get_state_entry( state_entries, addresser.task.address(payload.task_id) ) container = message_accessor.get_task_container(entry) except KeyError: container = task_state_pb2.TaskAttributesContainer() task = container.task_attributes.add() task.task_id = payload.task_id task.name = payload.name task.metadata = payload.metadata address_values = {} pubkeys_by_address = {} for pubkey in payload.admins: address = addresser.task.admin.address(payload.task_id, pubkey) if address in pubkeys_by_address: pubkeys_by_address[address].append(pubkey) else: pubkeys_by_address[address] = [pubkey] address_values.update( _handle_task_rel_container( state_entries=state_entries, task_id=payload.task_id, pubkeys_by_address=pubkeys_by_address, ) ) pubkeys_by_address = {} for pubkey in payload.owners: address = addresser.task.owner.address(payload.task_id, pubkey) if address in pubkeys_by_address: pubkeys_by_address[address].append(pubkey) else: pubkeys_by_address[address] = [pubkey] address_values.update( _handle_task_rel_container( state_entries=state_entries, task_id=payload.task_id, pubkeys_by_address=pubkeys_by_address, ) ) address_values[ addresser.task.address(payload.task_id) ] = container.SerializeToString() state_accessor.set_state(state, address_values)
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