export function resolve()

in src/governance/ccf-app/js/constitution/resolve.js [152:268]


export function resolve(proposal, proposerId, votes) {
  // Operators proposing operator changes can accept them without a vote.
  const resolution = operatorResolve(proposal, proposerId, votes);
  if (resolution == "Accepted") {
    return "Accepted";
  }

  // Custom logic.
  const actions = JSON.parse(proposal)["actions"];

  const canVeto = actions.some(canVetoAction);
  if (canVeto && votes.some((v) => !v.vote)) {
    // Every member has the ability to veto certain proposal types.
    // If they vote against it, it is rejected.
    return "Rejected";
  }

  const anySetContractChange = actions.some(is_set_contract);
  if (anySetContractChange) {
    // A set_contract action cannot be mixed with any other action type.
    if (!actions.every(is_set_contract)) {
      console.log(
        "rejecting proposal as set_contract action should not be mixed with any other actions in the same proposal"
      );
      return "Rejected";
    }

    // All set_contract actions should have different contractId values.
    const uniqueContracts = new Set(actions.map((v) => v.args.contractId));
    if (uniqueContracts.size < actions.length) {
      console.log(
        "rejecting proposal as multiple set_contract actions with the same contractId were found"
      );
      return "Rejected";
    }

    // A set_contract contractId should not be already present under a different proposal.
    if (
      actions.some((action) =>
        contractId_proposal_already_exists(action.args.contractId)
      )
    ) {
      console.log(
        "rejecting proposal as a contractId already exists under a different proposal"
      );
      return "Rejected";
    }
  }

  const anySetDocumentChange = actions.some(is_set_document);
  if (anySetDocumentChange) {
    // A set_document documentId should not be already present under a different proposal.
    if (
      actions.some((action) =>
        documentId_proposal_already_exists(action.args.documentId)
      )
    ) {
      console.log(
        "rejecting proposal as a documentId already exists under a different proposal"
      );
      return "Rejected";
    }
  }

  const memberVoteCount = votes.filter(
    (v) =>
      v.vote &&
      !isOperator(v.member_id) &&
      !isRecoveryOperator(v.member_id) &&
      !isCgsOperator(v.member_id) &&
      !isContractOperator(v.member_id)
  ).length;

  // Certain proposals need no voting by any member (like disabling contract logging/telemetry).
  const autoAccept = actions.every(canAutoAccept);
  if (autoAccept) {
    return "Accepted";
  }

  const activeMemberCount = getActiveCgsMemberCount();
  const acceptedMemberCount = getAcceptedCgsMemberCount();

  if (actions.some(needsAcceptedMembersToVote)) {
    // Certain proposals require accepted members to also participate and not just active members.
    // So accepted members need to become active and then as active members need to accept for
    // any proposal to go thru.
    if (memberVoteCount == activeMemberCount && acceptedMemberCount == 0) {
      return "Accepted";
    } else if (memberVoteCount == activeMemberCount) {
      console.log(
        `Not yet accepting proposal as this proposal requires ` +
          `not just all active members but also members in accepted state to become ` +
          `active and vote. acceptedMembersCount: ${acceptedMemberCount}`
      );
    }
  } else if (memberVoteCount == activeMemberCount) {
    return "Accepted";
  }

  // A proposal is a CGS operator change if it's only applying CGS operator actions.
  const isCgsOperatorChange = actions.every(canCgsOperatorPass);

  // Operators proposing operator changes can accept them without a vote.
  if (isCgsOperatorChange && isCgsOperator(proposerId)) {
    return "Accepted";
  }

  // A proposal is a contract operator change if it's only applying contract operator actions.
  const isContractOperatorChange = actions.every(canContractOperatorPass);

  // Operators proposing operator changes can accept them without a vote.
  if (isContractOperatorChange && isContractOperator(proposerId)) {
    return "Accepted";
  }

  return "Open";
}