import { Actor } from './actor.js'; import { CryptoUtil } from './crypto.js'; import { PostContent } from './post.js'; class Request { constructor(fee, content) { this.id = CryptoUtil.randomUUID(); this.fee = fee; this.content = content; } } /** * Purpose: Enable fee-driven work requests, to be completed by workers from the availability pool */ export class Business extends Actor { requests = new Map(); constructor(bench, forum, availability, name, scene) { super(name, scene); this.bench = bench; this.forum = forum; this.availability = availability; } /** * Fee should be held in escrow. * That means there should be specific conditions under which the fee will be refunded. * That means the submission should include some time value to indicate when it expires. * There could be separate thresholds to indicate the earliest that the job may be cancelled, * and the time at which the job will be automatically cancelled. */ async submitRequest(fee, content) { const request = new Request(fee, content); this.requests.set(request.id, request); await this.availability.assignWork(request.id); return request.id; } async submitWork(reputationPublicKey, requestId, workEvidence, { tokenLossRatio, duration }) { const { fee } = this.requests.get(requestId); // Create a post representing this submission. const post = new PostContent({ requestId, workEvidence, }); await this.forum.addPost(reputationPublicKey, post); // Initiate a validation pool for this work evidence. // Validation pool supports secret ballots but we aren't using that here, since we want // the post to be attributable to the reputation holder. const pool = await this.bench.initiateValidationPool(reputationPublicKey, { postId: post.id, fee, duration, tokenLossRatio, signingPublicKey: reputationPublicKey, }); // When the validation pool concludes, // reputation should be awarded and fees should be distributed. return pool; } }