Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: integrate eliza with trustless-work api #36

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

brolag
Copy link

@brolag brolag commented Feb 2, 2025

WIP for a POC integrating eliza with Trustless Work

import { Escrow, EscrowMilestoneStatus } from '../models/Escrow'; // Adjust the import path as needed

/**
 * Changes the flag property of a specific milestone in an escrow to approve that milestone.
 *
 * URL: /escrow/change-milestone-flag
 *
 * @param contractId - The ID (address) identifying the escrow contract.
 * @param milestoneIndex - The index of the milestone within the escrow.
 * @param newFlag - The new value for the flag property of the milestone.
 * @param client - The address of the client who approves the milestone.
 * @returns The updated escrow object.
 * @throws Error if the escrow or milestone is not found.
 */
export async function changeMilestoneFlag(contractId: string, milestoneIndex: number, newFlag: boolean, client: string): Promise<typeof Escrow> {
  // Retrieve the escrow by its contractId
  const escrow = await Escrow.findById(contractId);
  if (!escrow) {
    throw new Error(`Escrow with contractId ${contractId} not found`);
  }

  // Validate the milestoneIndex is within bounds for the milestones array
  if (milestoneIndex < 0 || milestoneIndex >= escrow.milestones.length) {
    throw new Error(`Milestone index ${milestoneIndex} is out of bounds for escrow ${contractId}`);
  }

  // Retrieve the milestone using the milestoneIndex
  const milestone = escrow.milestones[milestoneIndex];
  
  // Optionally, you can add a check for client authorization here if needed
  // Example:
  // if (escrow.client !== client) {
  //   throw new Error(`Client ${client} is not authorized to approve milestones for escrow ${contractId}`);
  // }

  // Update the milestone's flag to the new value
  milestone.flag = newFlag;

  // Save the updated escrow record
  await escrow.save();

  // Return the updated escrow object
  return escrow;
}

@techrebelgit
Copy link
Contributor

Awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants