Simplify sequence diagram

This commit is contained in:
Ladd Hoffman 2023-02-01 23:03:40 -06:00
parent be71d4f3cd
commit f57c38e322
6 changed files with 25 additions and 37 deletions

View File

@ -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);

View File

@ -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) {

View File

@ -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;
}

View File

@ -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,

View File

@ -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`);
}

View File

@ -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();
}
}