diff --git a/core/sidra-chain/chain.js b/core/sidra-chain/chain.js index d2508a6..e465461 100644 --- a/core/sidra-chain/chain.js +++ b/core/sidra-chain/chain.js @@ -1,24 +1,35 @@ -import { SidraProtocol } from './protocol'; import { Block } from './block'; class SidraChain { constructor() { - this.chain = []; - this.currentBlock = null; - this.protocol = new SidraProtocol(this, new SidraNode()); + this.blocks = []; } - init() { - // Initialize the chain with a genesis block + addBlock(block) { + // Validate the block before adding it to the chain + if (this.validateBlock(block)) { + this.blocks.push(block); + } } - createBlock(transactions) { - const block = new Block(transactions, this.currentBlock.hash); - this.protocol.createBlock(block); + getLatestBlock() { + // Return the latest block in the chain + return this.blocks[this.blocks.length - 1]; } - processTransaction(transaction) { - this.protocol.processTransaction(transaction); + getBlockByHash(hash) { + // Retrieve a block by its hash + return this.blocks.find((block) => block.hash === hash); + } + + getBlockByIndex(index) { + // Retrieve a block by its index + return this.blocks[index]; + } + + validateBlock(block) { + // Validate a block and ensure it meets the chain's requirements + // Check block hash, transactions, and other relevant information } }