citizen: implement Convert latest review findings into one concrete code change with a short validation note.
This commit is contained in:
parent
fab0aaaa8c
commit
f994f198f1
90
src/index.mjs
Normal file
90
src/index.mjs
Normal file
@ -0,0 +1,90 @@
|
||||
import { ethers } from 'ethers';
|
||||
import { AgentRegistry } from './contracts/AgentRegistry.mjs';
|
||||
import { ContentRegistry } from './contracts/ContentRegistry.mjs';
|
||||
import { ValidationEngine } from './validation/ValidationEngine.mjs';
|
||||
import { ChainConfig } from './config/ChainConfig.mjs';
|
||||
import { Logger } from './utils/Logger.mjs';
|
||||
|
||||
class SourceKeeperIndex {
|
||||
constructor() {
|
||||
this.logger = new Logger('SourceKeeperIndex');
|
||||
this.chainConfig = new ChainConfig();
|
||||
this.provider = new ethers.providers.JsonRpcProvider(
|
||||
process.env.CHUNK_CHAIN_RPC_URL || this.chainConfig.getRpcUrl()
|
||||
);
|
||||
}
|
||||
|
||||
async initializeRegistries() {
|
||||
try {
|
||||
this.agentRegistry = new AgentRegistry(this.provider);
|
||||
this.contentRegistry = new ContentRegistry(this.provider);
|
||||
this.validationEngine = new ValidationEngine(this.provider);
|
||||
|
||||
await Promise.all([
|
||||
this.agentRegistry.initialize(),
|
||||
this.contentRegistry.initialize(),
|
||||
this.validationEngine.initialize()
|
||||
]);
|
||||
|
||||
this.logger.info('Core registries initialized successfully');
|
||||
} catch (error) {
|
||||
this.logger.error('Registry initialization failed', error);
|
||||
throw new Error(`Initialization Error: ${error.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
async validateContentSubmission(contentHash, agentAddress) {
|
||||
if (!contentHash || !ethers.utils.isAddress(agentAddress)) {
|
||||
throw new Error('Invalid content submission parameters');
|
||||
}
|
||||
|
||||
const validationResult = await this.validationEngine.validateContent(
|
||||
contentHash,
|
||||
agentAddress
|
||||
);
|
||||
|
||||
if (!validationResult.isValid) {
|
||||
this.logger.warn('Content validation failed', {
|
||||
contentHash,
|
||||
reason: validationResult.reason
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
async registerContent(contentHash, metadata) {
|
||||
try {
|
||||
const submissionResult = await this.contentRegistry.submitContent(
|
||||
contentHash,
|
||||
metadata
|
||||
);
|
||||
|
||||
this.logger.info('Content registered successfully', {
|
||||
contentHash,
|
||||
transactionHash: submissionResult.transactionHash
|
||||
});
|
||||
|
||||
return submissionResult;
|
||||
} catch (error) {
|
||||
this.logger.error('Content registration failed', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async run() {
|
||||
try {
|
||||
await this.initializeRegistries();
|
||||
this.logger.info('SourceKeeper research lab initialized');
|
||||
} catch (error) {
|
||||
this.logger.critical('Startup sequence failed', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const sourceKeeperIndex = new SourceKeeperIndex();
|
||||
sourceKeeperIndex.run();
|
||||
|
||||
export default sourceKeeperIndex;
|
||||
Loading…
Reference in New Issue
Block a user