From f57c38e3227165708c5686122c9bce41595e4d2d Mon Sep 17 00:00:00 2001 From: Ladd Hoffman Date: Wed, 1 Feb 2023 23:03:40 -0600 Subject: [PATCH] Simplify sequence diagram --- forum-network/src/classes/business.js | 2 +- forum-network/src/classes/dao.js | 9 +++----- forum-network/src/classes/expert.js | 21 +++++++------------ forum-network/src/classes/forum.js | 17 ++++++--------- forum-network/src/classes/validation-pool.js | 6 +++--- .../tests/scripts/forum/forum.test-util.js | 7 ++++--- 6 files changed, 25 insertions(+), 37 deletions(-) diff --git a/forum-network/src/classes/business.js b/forum-network/src/classes/business.js index 9ddd799..23ff6e3 100644 --- a/forum-network/src/classes/business.js +++ b/forum-network/src/classes/business.js @@ -73,7 +73,7 @@ export class Business extends Actor { post.setTitle(`Work Evidence ${requestIndex + 1}`); await this.actions.submitPost.log(this, this.dao); - const postId = await this.dao.forum.addPost(reputationPublicKey, post); + const { id: postId } = await this.dao.forum.addPost(reputationPublicKey, post); // Initiate a validation pool for this work evidence. await this.actions.initiateValidationPool.log(this, this.dao); diff --git a/forum-network/src/classes/dao.js b/forum-network/src/classes/dao.js index 4a8df80..59c9535 100644 --- a/forum-network/src/classes/dao.js +++ b/forum-network/src/classes/dao.js @@ -18,9 +18,9 @@ export class DAO extends Actor { super(name); /* Contracts */ - this.forum = new Forum(this, `${name} Forum`); - this.availability = new Availability(this, `${name} Availability`); - this.business = new Business(this, `${name} Business`); + this.forum = new Forum(this, 'Forum'); + this.availability = new Availability(this, 'Availability'); + this.business = new Business(this, 'Business'); this.reputation = new ReputationTokenContract(); /* Data */ @@ -28,8 +28,6 @@ export class DAO extends Actor { this.experts = new Map(); this.actions = { - addPost: new Action('add post'), - createValidationPool: new Action('create validation pool'), }; } @@ -63,7 +61,6 @@ export class DAO extends Actor { const name = `Pool${validationPoolNumber}`; const pool = new ValidationPool(this, poolOptions, name); this.validationPools.set(pool.id, pool); - await this.actions.createValidationPool.log(this, pool); pool.activate(); if (stakeOptions) { diff --git a/forum-network/src/classes/expert.js b/forum-network/src/classes/expert.js index b386374..2fff24d 100644 --- a/forum-network/src/classes/expert.js +++ b/forum-network/src/classes/expert.js @@ -37,15 +37,10 @@ export class Expert extends ReputationHolder { await forumNode.receiveMessage(JSON.stringify(postMessage.toJSON())); } - async submitPost(postContent) { - // TODO: Include fee - await this.actions.submitPost.log(this, this.dao); - return this.dao.forum.addPost(this.reputationPublicKey, postContent); - } - async submitPostWithFee(postContent, poolOptions) { - await this.actions.submitPost.log(this, this.dao); - const postId = await this.dao.forum.addPost(this.reputationPublicKey, postContent); + const post = await this.dao.forum.addPost(this.reputationPublicKey, postContent); + await this.actions.submitPost.log(this, post); + const postId = post.id; const pool = await this.initiateValidationPool({ ...poolOptions, postId }); this.tokens.push(pool.tokenId); return { postId, pool }; @@ -54,14 +49,14 @@ export class Expert extends ReputationHolder { async initiateValidationPool(poolOptions) { // For now, directly call bench.initiateValidationPool(); poolOptions.reputationPublicKey = this.reputationPublicKey; - await this.actions.initiateValidationPool.log( - this, - this.dao, - `(fee: ${poolOptions.fee}, stake: ${poolOptions.authorStakeAmount ?? 0})`, - ); const pool = await this.dao.initiateValidationPool(poolOptions); this.tokens.push(pool.tokenId); this.validationPools.set(pool.id, poolOptions); + await this.actions.initiateValidationPool.log( + this, + pool, + `(fee: ${poolOptions.fee}, stake: ${poolOptions.authorStakeAmount ?? 0})`, + ); return pool; } diff --git a/forum-network/src/classes/forum.js b/forum-network/src/classes/forum.js index ef0b477..e099bae 100644 --- a/forum-network/src/classes/forum.js +++ b/forum-network/src/classes/forum.js @@ -20,7 +20,6 @@ export class Forum extends ReputationHolder { this.id = this.reputationPublicKey; this.posts = new WDAG(); this.actions = { - addPost: new Action('add post'), propagateValue: new Action('propagate'), transfer: new Action('transfer'), }; @@ -28,12 +27,11 @@ export class Forum extends ReputationHolder { async addPost(authorId, postContent) { const post = new Post(this, authorId, postContent); - await this.actions.addPost.log(this, post); this.posts.addVertex(post.id, post, post.getLabel()); for (const { postId: citedPostId, weight } of post.citations) { this.posts.addEdge(CITATION, post.id, citedPostId, weight); } - return post.id; + return post; } getPost(postId) { @@ -55,9 +53,8 @@ export class Forum extends ReputationHolder { } async onValidate({ - postId, tokenId, + pool, postId, tokenId, }) { - this.activate(); const initialValue = this.dao.reputation.valueOf(tokenId); const postVertex = this.posts.getVertex(postId); const post = postVertex.data; @@ -73,7 +70,7 @@ export class Forum extends ReputationHolder { // Compute rewards await this.propagateValue( - { to: postVertex, from: { data: this } }, + { to: postVertex, from: { data: pool } }, { rewardsAccumulator, increment: initialValue }, ); @@ -88,10 +85,8 @@ export class Forum extends ReputationHolder { // Transfer ownership of the minted/staked token, from the posts to the post author this.dao.reputation.transferFrom(this.id, post.authorPublicKey, post.tokenId); - const toActor = window?.scene?.findActor((actor) => actor.reputationPublicKey === post.authorPublicKey); - const value = this.dao.reputation.valueOf(post.tokenId); - this.actions.transfer.log(this, toActor, `(${value})`); - this.deactivate(); + // const toActor = window?.scene?.findActor((actor) => actor.reputationPublicKey === post.authorPublicKey); + // const value = this.dao.reputation.valueOf(post.tokenId); } /** @@ -117,7 +112,7 @@ export class Forum extends ReputationHolder { } console.log('propagateValue start', { - from: edge.from.id, + from: edge.from.id ?? edge.from, to: edge.to.id, depth, value: post.value, diff --git a/forum-network/src/classes/validation-pool.js b/forum-network/src/classes/validation-pool.js index e344cc9..92a85e3 100644 --- a/forum-network/src/classes/validation-pool.js +++ b/forum-network/src/classes/validation-pool.js @@ -260,8 +260,8 @@ export class ValidationPool extends ReputationHolder { // Transfer ownership of the minted token, from the pool to the forum this.dao.reputation.transferFrom(this.id, this.dao.forum.id, this.tokenId); - const value = this.dao.reputation.valueOf(this.tokenId); - this.actions.transfer.log(this, this.dao.forum, `(${value})`); + // const value = this.dao.reputation.valueOf(this.tokenId); + // this.actions.transfer.log(this, this.dao.forum, `(${value})`); // Recurse through forum to determine reputation effects await this.dao.forum.onValidate({ @@ -278,7 +278,7 @@ export class ValidationPool extends ReputationHolder { const actor = window?.scene?.findActor((a) => a.reputationPublicKey === voter.reputationPublicKey); await actor.computeValues(); } - await this.dao.forum.computeValues(); + await this.dao.computeValues(); window?.scene?.stateToTable(`validation pool ${this.name} complete`); } diff --git a/forum-network/src/tests/scripts/forum/forum.test-util.js b/forum-network/src/tests/scripts/forum/forum.test-util.js index 0e2cd20..ce290c9 100644 --- a/forum-network/src/tests/scripts/forum/forum.test-util.js +++ b/forum-network/src/tests/scripts/forum/forum.test-util.js @@ -70,7 +70,7 @@ export class ForumTest { scene.addDisplayValue('q4. leachingValue').set(params.leachingValue); scene.addDisplayValue(' '); - this.dao = (window.dao = new DAO('DGF')); + this.dao = (window.dao = new DAO('DAO')); this.forum = this.dao.forum; this.experts = (window.experts = []); this.posts = (window.posts = []); @@ -79,7 +79,8 @@ export class ForumTest { // await newExpert(); // await newExpert(); - // this.dao.addValue('total rep', () => this.dao.reputation.getTotal()); - this.dao.forum.addValue('total value', () => this.dao.forum.getTotalValue()); + this.dao.addValue('total value', () => this.dao.reputation.getTotal()); + // this.dao.addValue('total reputation', () => this.dao.forum.getTotalValue()); + this.dao.computeValues(); } }