예제 #1
0
    def test_state(self):
        """Grab the entire blockchain state and deserialize it"""
        subtree = addresser.family.namespace
        for item in client.list_state(subtree=subtree)["data"]:
            address_type = item["address_type"] = addresser.address_is(
                item["address"])
            if address_type == addresser.AddressSpace.USER:
                content = user_state_pb2.UserContainer()
                content.ParseFromString(b64decode(item["data"]))
            elif address_type == addresser.AddressSpace.PROPOSALS:
                content = proposal_state_pb2.ProposalsContainer()
                content.ParseFromString(b64decode(item["data"]))
            elif address_type == addresser.AddressSpace.SYSADMIN_ATTRIBUTES:
                content = "SYSADMIN_ATTRIBUTES"
            elif address_type == addresser.AddressSpace.SYSADMIN_MEMBERS:
                content = "SYSADMIN_MEMBERS"
            elif address_type == addresser.AddressSpace.SYSADMIN_OWNERS:
                content = "SYSADMIN_OWNERS"
            elif address_type == addresser.AddressSpace.SYSADMIN_ADMINS:
                content = "SYSADMIN_ADMINS"
            elif address_type == addresser.AddressSpace.ROLES_ATTRIBUTES:
                content = role_state_pb2.RoleAttributesContainer()
                content.ParseFromString(b64decode(item["data"]))
            elif address_type == addresser.AddressSpace.ROLES_MEMBERS:
                content = role_state_pb2.RoleRelationshipContainer()
                content.ParseFromString(b64decode(item["data"]))
            elif address_type == addresser.AddressSpace.ROLES_OWNERS:
                content = role_state_pb2.RoleRelationshipContainer()
                content.ParseFromString(b64decode(item["data"]))
            elif address_type == addresser.AddressSpace.ROLES_ADMINS:
                content = role_state_pb2.RoleRelationshipContainer()
                content.ParseFromString(b64decode(item["data"]))
            elif address_type == addresser.AddressSpace.ROLES_TASKS:
                content = role_state_pb2.RoleRelationshipContainer()
                content.ParseFromString(b64decode(item["data"]))
            elif address_type == addresser.AddressSpace.TASKS_ATTRIBUTES:
                content = task_state_pb2.TaskAttributesContainer()
                content.ParseFromString(b64decode(item["data"]))
            elif address_type == addresser.AddressSpace.TASKS_OWNERS:
                content = task_state_pb2.TaskRelationshipContainer()
                content.ParseFromString(b64decode(item["data"]))
            elif address_type == addresser.AddressSpace.TASKS_ADMINS:
                content = task_state_pb2.TaskRelationshipContainer()
                content.ParseFromString(b64decode(item["data"]))
            else:
                content = "ERROR: unknown type: {}".format(address_type)

            LOGGER.debug("%-80s%-30s%s", item["address"], address_type,
                         content)
예제 #2
0
def _handle_task_rel_container(state_entries, task_id, pubkeys_by_address):
    entries_to_set = {}

    for addr, pubkeys in pubkeys_by_address.items():
        try:
            state_entry = state_accessor.get_state_entry(state_entries, addr)
            container = task_state_pb2.TaskRelationshipContainer()
            container.ParseFromString(state_entry.data)
        except KeyError:
            container = task_state_pb2.TaskRelationshipContainer()

        _add_task_rel_to_container(container, task_id, pubkeys)

        entries_to_set[addr] = container.SerializeToString()

    return entries_to_set
예제 #3
0
def confirm_task_action(state_entries, header, confirm, task_rel_address,
                        state, is_remove):
    """ Updates proposal and task relationship objects according to the
        task admin/owner transaction.

        Args:
            state_entries: List of states for the proposal, task relationship,
            and task admins object.
            header (TransactionHeader): The protobuf TransactionHeader.
            confirm (RBACPayload): The protobuf RBACPayload.
            task_rel_address (str): The task relationship address.
            state (Context): The class that handles state gets and sets.
            is_remove (boolean): Determines if task admin/owner is being removed or added.

    """
    proposal_address = addresser.make_proposal_address(
        object_id=confirm.task_id, related_id=confirm.user_id)

    proposal_entry = state_accessor.get_state_entry(state_entries,
                                                    proposal_address)
    proposal_container = message_accessor.get_prop_container(proposal_entry)
    proposal = message_accessor.get_prop_from_container(
        proposal_container, proposal_id=confirm.proposal_id)

    proposal.status = proposal_state_pb2.Proposal.CONFIRMED
    proposal.closer = header.signer_public_key
    proposal.close_reason = confirm.reason

    address_values = {proposal_address: proposal_container.SerializeToString()}

    try:
        task_rel_entry = state_accessor.get_state_entry(
            state_entries, task_rel_address)
        task_rel_container = message_accessor.get_task_rel_container(
            task_rel_entry)
    except KeyError:
        task_rel_container = task_state_pb2.TaskRelationshipContainer()

    try:
        task_rel = message_accessor.get_task_rel_from_container(
            container=task_rel_container,
            task_id=confirm.task_id,
            identifier=confirm.user_id,
        )
    except KeyError:
        task_rel = task_rel_container.relationships.add()
        task_rel.task_id = confirm.task_id

    if not is_remove:
        task_rel.identifiers.append(confirm.user_id)
    else:
        task_rel.identifiers.remove(confirm.user_id)

    address_values[task_rel_address] = task_rel_container.SerializeToString()

    state_accessor.set_state(state, address_values)