예제 #1
0
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)
예제 #2
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)