citizen: implement Convert latest review findings into one concrete code change with a short validation note.
This commit is contained in:
parent
fab0aaaa8c
commit
d595cfef3e
72
src/index.mjs
Normal file
72
src/index.mjs
Normal file
@ -0,0 +1,72 @@
|
||||
import { ethers } from 'ethers';
|
||||
import { AgentRegistry } from './contracts/AgentRegistry.mjs';
|
||||
import { ContentRegistry } from './contracts/ContentRegistry.mjs';
|
||||
import { ValidationEngine } from './validation/ValidationEngine.mjs';
|
||||
import { ReputationScorer } from './reputation/ReputationScorer.mjs';
|
||||
import { Logger } from './utils/Logger.mjs';
|
||||
|
||||
const RPC_URL = process.env.CHUNK_CHAIN_RPC_URL || 'https://rpc.chunknet.org';
|
||||
const AGENT_REGISTRY_ADDRESS = '0x60d490519E18c806A1F4364cBd34A8693D9f3745';
|
||||
|
||||
class SourceKeeperCore {
|
||||
constructor() {
|
||||
this.provider = new ethers.providers.JsonRpcProvider(RPC_URL);
|
||||
this.logger = new Logger('SourceKeeperCore');
|
||||
this.agentRegistry = new AgentRegistry(this.provider, AGENT_REGISTRY_ADDRESS);
|
||||
this.contentRegistry = new ContentRegistry(this.provider);
|
||||
this.validationEngine = new ValidationEngine();
|
||||
this.reputationScorer = new ReputationScorer();
|
||||
}
|
||||
|
||||
async initializeResearchFlow(researchPayload) {
|
||||
try {
|
||||
// Validate research submission payload
|
||||
if (!this.validatePayload(researchPayload)) {
|
||||
throw new Error('Invalid research payload structure');
|
||||
}
|
||||
|
||||
// Register research agent if not existing
|
||||
const agentId = await this.agentRegistry.registerOrGetAgent(researchPayload.agentDid);
|
||||
|
||||
// Store content hash and metadata
|
||||
const contentHash = await this.contentRegistry.registerContent({
|
||||
agentId,
|
||||
contentType: 'research',
|
||||
metadata: researchPayload.metadata
|
||||
});
|
||||
|
||||
// Run validation checks
|
||||
const validationResults = await this.validationEngine.runValidations(contentHash);
|
||||
|
||||
// Update reputation based on validation outcome
|
||||
await this.reputationScorer.updateScore(agentId, validationResults);
|
||||
|
||||
this.logger.info('Research flow completed successfully', {
|
||||
contentHash,
|
||||
agentId,
|
||||
validationStatus: validationResults.status
|
||||
});
|
||||
|
||||
return {
|
||||
contentHash,
|
||||
agentId,
|
||||
validationResults
|
||||
};
|
||||
} catch (error) {
|
||||
this.logger.error('Research flow failed', { error: error.message });
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
validatePayload(payload) {
|
||||
const requiredFields = ['agentDid', 'metadata', 'content'];
|
||||
return requiredFields.every(field => payload[field] !== undefined && payload[field] !== null);
|
||||
}
|
||||
|
||||
async getLatestResearch() {
|
||||
const latestContent = await this.contentRegistry.getLatestContent('research');
|
||||
return latestContent;
|
||||
}
|
||||
}
|
||||
|
||||
export default new SourceKeeperCore();
|
||||
Loading…
Reference in New Issue
Block a user