Automatic staking checks work evidence post content
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 38s Details

This commit is contained in:
Ladd Hoffman 2024-03-26 12:13:23 -05:00
parent 3cfde81600
commit 69d91a6acc
1 changed files with 18 additions and 16 deletions

View File

@ -78,18 +78,22 @@ const poolIsActive = (pool) => {
return true;
};
const poolIsValid = async (pool) => {
const poolIsValid = (pool) => {
switch (pool.sender) {
case getContractAddressByNetworkName(network, 'Work1'): {
// TODO: Read content of post for this pool and verify that it conforms to protocol
console.log(`post ${pool.post.id} content: ${pool.post.content}`);
if (pool.post.content) return true;
return true;
// If this is a valid work evidence
// TODO: Can we decode from the post, a reference to the work request?
// The work request does have its own contentId, the work contract has that
// under availabilityStakes
const expectedContent = 'This is a work evidence post';
return pool.post.content.startsWith(expectedContent);
}
case getContractAddressByNetworkName(network, 'Onboarding'): {
const expectedContent = 'This is an onboarding work evidence post';
return pool.post.content.startsWith(expectedContent);
}
case getContractAddressByNetworkName(network, 'Onboarding'):
// TODO: Read content of post for this pool and verify that it conforms to protocol
return true;
default:
console.log('Unrecognized sender %s', pool.sender);
return false;
}
};
@ -120,7 +124,10 @@ async function main() {
await initialize();
validationPools.forEach((pool) => {
console.log(`pool ${pool.id.toString()}, status: ${getPoolStatus(pool)}, post content: ${pool.post?.content}`);
console.log(`pool ${pool.id.toString()}, `
+ `status: ${getPoolStatus(pool)}, `
+ `is valid: ${poolIsValid(pool)}, `
+ `post content: ${pool.post?.content}`);
});
// Stake half of available reputation on any active pools
@ -137,13 +144,8 @@ async function main() {
await fetchReputation();
if (!reputation) return;
const amountToStake = reputation / BigInt(2);
if (await poolIsValid(pool)) {
// Stake half of available reputation on this validation pool
await stake(pool, amountToStake, true);
} else {
console.log(`pool sender ${pool.sender} is not recognized`);
await stake(pool, amountToStake, false);
}
const inFavor = await poolIsValid(pool);
await stake(pool, amountToStake, inFavor);
});
dao.on('ValidationPoolResolved', async (poolIndex, votePasses) => {