Refactor to clarify input parameters for validation pool
This commit is contained in:
parent
e602466800
commit
7e74773242
|
@ -1,5 +1,4 @@
|
|||
import { Action } from '../display/action.js';
|
||||
import { PostMessage } from '../forum-network/message.js';
|
||||
import { CryptoUtil } from '../supporting/crypto.js';
|
||||
import { ReputationHolder } from '../reputation/reputation-holder.js';
|
||||
import { EdgeTypes } from '../../util/constants.js';
|
||||
|
@ -18,7 +17,6 @@ export class Expert extends ReputationHolder {
|
|||
getAssignedWork: new Action('get assigned work', scene),
|
||||
submitWork: new Action('submit work evidence', scene),
|
||||
};
|
||||
this.validationPools = new Map();
|
||||
this.tokens = [];
|
||||
}
|
||||
|
||||
|
@ -49,21 +47,23 @@ export class Expert extends ReputationHolder {
|
|||
return this;
|
||||
}
|
||||
|
||||
async submitPostWithFee(postContent, poolOptions) {
|
||||
async submitPostWithFee(postContent, { fee }, params) {
|
||||
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 });
|
||||
const pool = await this.initiateValidationPool({ fee, postId }, params);
|
||||
this.tokens.push(pool.tokenId);
|
||||
return { postId, pool };
|
||||
}
|
||||
|
||||
async initiateValidationPool(poolOptions) {
|
||||
async initiateValidationPool({ postId, fee }, params) {
|
||||
// For now, make direct call rather than network
|
||||
poolOptions.reputationPublicKey = this.reputationPublicKey;
|
||||
const pool = await this.dao.initiateValidationPool(this, poolOptions);
|
||||
const pool = await this.dao.initiateValidationPool(this, {
|
||||
reputationPublicKey: this.reputationPublicKey,
|
||||
postId,
|
||||
fee,
|
||||
}, params);
|
||||
this.tokens.push(pool.tokenId);
|
||||
this.validationPools.set(pool.id, poolOptions);
|
||||
return pool;
|
||||
}
|
||||
|
||||
|
|
|
@ -80,12 +80,16 @@ export class Business extends Actor {
|
|||
const pool = await this.dao.initiateValidationPool(this, {
|
||||
postId,
|
||||
fee: request.fee,
|
||||
reputationPublicKey,
|
||||
}, {
|
||||
duration,
|
||||
tokenLossRatio,
|
||||
}, {
|
||||
reputationPublicKey,
|
||||
authorStakeAmount: request.worker.stakeAmount,
|
||||
});
|
||||
|
||||
await pool.stake(reputationPublicKey, {
|
||||
tokenId: request.worker.tokenId,
|
||||
amount: request.worker.stakeAmount,
|
||||
position: true,
|
||||
});
|
||||
|
||||
// When the validation pool concludes,
|
||||
|
|
|
@ -3,6 +3,7 @@ import { ReputationTokenContract } from '../reputation/reputation-token.js';
|
|||
import { ValidationPool } from './validation-pool.js';
|
||||
import { Availability } from './availability.js';
|
||||
import { Business } from './business.js';
|
||||
import { Voter } from '../supporting/voter.js';
|
||||
import { Actor } from '../display/actor.js';
|
||||
|
||||
/**
|
||||
|
@ -33,6 +34,12 @@ export class DAO extends Actor {
|
|||
Array.from(this.validationPools.values());
|
||||
}
|
||||
|
||||
addVoteRecord(reputationPublicKey, validationPool) {
|
||||
const voter = this.experts.get(reputationPublicKey) ?? new Voter(reputationPublicKey);
|
||||
voter.addVoteRecord(validationPool);
|
||||
this.experts.set(reputationPublicKey, voter);
|
||||
}
|
||||
|
||||
listActiveVoters({ activeVoterThreshold } = {}) {
|
||||
return Array.from(this.experts.values()).filter((voter) => {
|
||||
const hasVoted = !!voter.dateLastVote;
|
||||
|
@ -54,21 +61,14 @@ export class DAO extends Actor {
|
|||
.reduce((acc, cur) => (acc += cur), 0);
|
||||
}
|
||||
|
||||
async initiateValidationPool(fromActor, poolOptions, stakeOptions) {
|
||||
async initiateValidationPool(fromActor, { postId, reputationPublicKey, fee }, params) {
|
||||
const validationPoolNumber = this.validationPools.size + 1;
|
||||
const name = `Pool${validationPoolNumber}`;
|
||||
const pool = new ValidationPool(this, poolOptions, name, this.scene, fromActor);
|
||||
const pool = new ValidationPool(this, {
|
||||
postId, reputationPublicKey, fee,
|
||||
}, params, name, this.scene, fromActor);
|
||||
this.validationPools.set(pool.id, pool);
|
||||
|
||||
if (stakeOptions) {
|
||||
const { reputationPublicKey, tokenId, authorStakeAmount } = stakeOptions;
|
||||
await pool.stake(reputationPublicKey, {
|
||||
tokenId,
|
||||
position: true,
|
||||
amount: authorStakeAmount,
|
||||
});
|
||||
}
|
||||
|
||||
return pool;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { ReputationHolder } from '../reputation/reputation-holder.js';
|
||||
import { Stake } from '../supporting/stake.js';
|
||||
import { Voter } from '../supporting/voter.js';
|
||||
import { Action } from '../display/action.js';
|
||||
import { displayNumber } from '../../util/helpers.js';
|
||||
|
||||
|
@ -47,6 +46,8 @@ export class ValidationPool extends ReputationHolder {
|
|||
postId,
|
||||
reputationPublicKey,
|
||||
fee,
|
||||
},
|
||||
{
|
||||
duration,
|
||||
tokenLossRatio,
|
||||
contentiousDebate = false,
|
||||
|
@ -147,9 +148,7 @@ export class ValidationPool extends ReputationHolder {
|
|||
this.actions.mint.log(this, this, `(${this.mintedValue})`);
|
||||
|
||||
// Keep a record of voters and their votes
|
||||
const voter = this.dao.experts.get(reputationPublicKey) ?? new Voter(reputationPublicKey);
|
||||
voter.addVoteRecord(this);
|
||||
this.dao.experts.set(reputationPublicKey, voter);
|
||||
this.dao.addVoteRecord(reputationPublicKey, this);
|
||||
}
|
||||
|
||||
getTokenLossRatio() {
|
||||
|
@ -232,12 +231,10 @@ export class ValidationPool extends ReputationHolder {
|
|||
|
||||
// Keep a record of voters and their votes
|
||||
if (reputationPublicKey !== this.id) {
|
||||
const voter = this.dao.experts.get(reputationPublicKey) ?? new Voter(reputationPublicKey);
|
||||
voter.addVoteRecord(this);
|
||||
this.dao.experts.set(reputationPublicKey, voter);
|
||||
this.dao.addVoteRecord(reputationPublicKey, this);
|
||||
|
||||
// Update computed display values
|
||||
const actor = this.scene?.findActor((a) => a.reputationPublicKey === voter.reputationPublicKey);
|
||||
const actor = this.scene?.findActor((a) => a.reputationPublicKey === reputationPublicKey);
|
||||
await actor.computeDisplayValues();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,8 @@ const setup = async () => {
|
|||
new PostContent({ hello: 'there' }).setTitle('Post 1'),
|
||||
{
|
||||
fee: 10,
|
||||
},
|
||||
{
|
||||
duration: POOL_DURATION,
|
||||
tokenLossRatio: 1,
|
||||
},
|
||||
|
@ -68,6 +70,8 @@ const setup = async () => {
|
|||
.addCitation(postId1, 0.5),
|
||||
{
|
||||
fee: 10,
|
||||
},
|
||||
{
|
||||
duration: POOL_DURATION,
|
||||
tokenLossRatio: 1,
|
||||
},
|
||||
|
|
|
@ -42,6 +42,8 @@ export class ForumTest {
|
|||
postContent,
|
||||
{
|
||||
fee,
|
||||
},
|
||||
{
|
||||
duration: this.options.poolDurationMs,
|
||||
tokenLossRatio: 1,
|
||||
},
|
||||
|
|
|
@ -57,6 +57,7 @@ describe('Validation Pool', function tests() {
|
|||
await scene.sequence.startSection();
|
||||
const { pool } = await experts[0].submitPostWithFee(new PostContent(), {
|
||||
fee: 7,
|
||||
}, {
|
||||
duration: POOL_DURATION_MS,
|
||||
tokenLossRatio: 1,
|
||||
});
|
||||
|
@ -84,6 +85,7 @@ describe('Validation Pool', function tests() {
|
|||
try {
|
||||
const { pool } = await experts[1].submitPostWithFee(new PostContent(), {
|
||||
fee: 1,
|
||||
}, {
|
||||
duration: POOL_DURATION_MS,
|
||||
tokenLossRatio: 1,
|
||||
});
|
||||
|
@ -98,6 +100,7 @@ describe('Validation Pool', function tests() {
|
|||
it('Second expert must be approved by first expert', async () => {
|
||||
const { pool } = await experts[1].submitPostWithFee(new PostContent(), {
|
||||
fee: 1,
|
||||
}, {
|
||||
duration: POOL_DURATION_MS,
|
||||
tokenLossRatio: 1,
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue