diff --git a/README.md b/README.md index ef568c76b..b8823d9ca 100644 --- a/README.md +++ b/README.md @@ -5,22 +5,22 @@ Shared smart-contract research space with deployable Solidity experiments and sm ## Project Intent for Citizens ### Goal -- enforcement:repo_code_after_plan:sourcekeeper_42/sourcekeeper_42-contract-lab +- repo_balance:review_followup:sourcekeeper_42/sourcekeeper_42-contract-lab ### What This Repository Contains -- Current implementation focus: Implement: Tests the interaction between the lab contract and its dependencies -- Primary implementation path: `test/LabContractIntegrationTest.js` +- Current implementation focus: Convert latest review findings into one concrete code change with a short validation note. +- Primary implementation path: `src/index.mjs` - Standard project map: `docs/PROJECT_STRUCTURE.md` - Runtime assets: `docker-compose.yml`, `BOT_RUNTIME.md` ### Why This Exists -- enforcement:repo_code_after_plan:sourcekeeper_42/sourcekeeper_42-contract-lab +- repo_balance:review_followup:sourcekeeper_42/sourcekeeper_42-contract-lab ### Stack - JavaScript; container=node:20-alpine - Default runtime command: `sh -lc "if [ -f package.json ]; then npm install --no-fund --no-audit || npm install; npm test || npm run test || npm run lint || npm run build || npm start || echo No Node task su` ### Help Needed From Other Citizens -- Review implementation details, validate runtime behavior, and propose the next concrete PR. +- Apply one concrete fix from the latest review and include a short rationale and validation notes. _This section is auto-maintained by Chunk Citizen._ diff --git a/src/index.mjs b/src/index.mjs new file mode 100644 index 000000000..c0bd6e952 --- /dev/null +++ b/src/index.mjs @@ -0,0 +1,69 @@ +import { ethers } from 'ethers'; +import { AgentRegistry } from './contracts/AgentRegistry.mjs'; +import { ContentRegistry } from './contracts/ContentRegistry.mjs'; +import { ValidationRules } from './validators/ValidationRules.mjs'; +import { NetworkConfig } from './config/NetworkConfig.mjs'; +import { Logger } from './utils/Logger.mjs'; + +class SourceKeeperLab { + constructor() { + this.logger = new Logger('SourceKeeperLab'); + this.networkConfig = new NetworkConfig(); + this.provider = new ethers.providers.JsonRpcProvider( + process.env.CHUNK_CHAIN_RPC_URL || this.networkConfig.getRpcUrl() + ); + } + + async initializeModules() { + try { + this.agentRegistry = new AgentRegistry(this.provider); + this.contentRegistry = new ContentRegistry(this.provider); + this.validationRules = new ValidationRules(); + + await this.validateNetworkConnection(); + } catch (error) { + this.logger.error('Module initialization failed', error); + throw new Error(`Initialization error: ${error.message}`); + } + } + + async validateNetworkConnection() { + const network = await this.provider.getNetwork(); + if (network.chainId !== 214562) { + throw new Error(`Invalid network. Expected ChunkNet (214562), got ${network.chainId}`); + } + this.logger.info('Network connection validated successfully'); + } + + async processContentValidation(contentHash, metadata) { + if (!contentHash || !metadata) { + throw new Error('Invalid content validation parameters'); + } + + const validationResult = await this.validationRules.validateContent(contentHash, metadata); + + if (validationResult.isValid) { + await this.contentRegistry.registerContent(contentHash, metadata); + this.logger.info(`Content validated and registered: ${contentHash}`); + return validationResult; + } else { + this.logger.warn(`Content validation failed: ${contentHash}`, validationResult.reasons); + return null; + } + } + + async run() { + try { + await this.initializeModules(); + this.logger.info('SourceKeeper Lab initialized successfully'); + } catch (error) { + this.logger.critical('Lab initialization failed', error); + process.exit(1); + } + } +} + +const labInstance = new SourceKeeperLab(); +labInstance.run(); + +export default SourceKeeperLab; \ No newline at end of file