Пример #1
0
def apply_user_confirm(header, payload, state):
    confirm_payload = user_transaction_pb2.ConfirmUpdateUserManager()
    confirm_payload.ParseFromString(payload.content)

    proposal_address = addresser.proposal.address(
        object_id=confirm_payload.user_id, target_id=confirm_payload.manager_id
    )

    proposal_entries = state_accessor.get_state(state, [proposal_address])

    if not proposal_validator.proposal_exists_and_open(
        state_entries=proposal_entries,
        proposal_address=proposal_address,
        proposal_id=confirm_payload.proposal_id,
    ):
        raise InvalidTransaction(
            "Proposal id {} for user {} to update manager to {} does not exist or is not open.".format(
                confirm_payload.proposal_id,
                confirm_payload.user_id,
                confirm_payload.manager_id,
            )
        )

    entry = state_accessor.get_state_entry(proposal_entries, proposal_address)
    proposal_container = message_accessor.get_prop_container(entry)
    proposal = message_accessor.get_prop_from_container(
        container=proposal_container, proposal_id=confirm_payload.proposal_id
    )

    if not proposal.target_id == header.signer_public_key:
        raise InvalidTransaction(
            "Confirm update manager txn signed by {} while "
            "proposal expecting {}".format(header.signer_public_key, proposal.target_id)
        )

    state_change.confirm_manager_change(
        container=proposal_container,
        proposal=proposal,
        closer=header.signer_public_key,
        reason=confirm_payload.reason,
        address=proposal_address,
        user_id=confirm_payload.user_id,
        new_manager_id=confirm_payload.manager_id,
        state=state,
    )
def confirm_manager(txn_key, batch_key, proposal_id, user_id, manager_id,
                    reason):
    """Create a BatchList with a ConfirmUpdateUserManager transaction in it.

    Args:
        txn_key (Key): The transaction signer public/private key pair.
        batch_key (Key): The batch signer public/private key pair.
        proposal_id (str): The identifier of the proposal.
        reason (str): The client supplied reason for the confirmation.

    Returns:
        tuple
            BatchList, batch header_signature tuple
    """

    confirm_update_payload = user_transaction_pb2.ConfirmUpdateUserManager(
        proposal_id=proposal_id,
        user_id=user_id,
        manager_id=manager_id,
        reason=reason)

    inputs = [
        addresser.proposal.address(user_id, manager_id),
        addresser.user.address(user_id),
        addresser.user.address(txn_key.public_key),
    ]

    outputs = [
        addresser.proposal.address(user_id, manager_id),
        addresser.user.address(user_id),
    ]

    rbac_payload = rbac_payload_pb2.RBACPayload(
        content=confirm_update_payload.SerializeToString(),
        message_type=rbac_payload_pb2.RBACPayload.CONFIRM_UPDATE_USER_MANAGER,
        inputs=inputs,
        outputs=outputs,
    )

    return make_header_and_batch(rbac_payload, inputs, outputs, txn_key,
                                 batch_key)