src/blockchain/src/domain/service/BitcoinService.js
/**
   * Mines a new block into the chain. It involves:
   * Recalculate new blocks hash until the difficulty condition is met (mine)
   * Point new block's previous to current
   *
   * @param {Block}  newBlock  New block to add into the chain   
   * @return {Blockchain} Returns a reference to the blockchain with the new block inserted
   */
Mines a new block into the chain. It involves:
Recalculate new blocks hash until the difficulty condition is met (mine)
Point new block's previous to current

@param {Block}  newBlock  New block to add into the chain
@return {Blockchain} Returns a reference to the blockchain with the new block inserted
Mines a new block into the chain . It involves : Recalculate new blocks hash until the difficulty condition is met ( mine ) Point new block ' s previous to current @param { Block } newBlock New block to add into the chain @return { Blockchain } Returns a reference to the blockchain with the new block inserted
async function mineNewBlockIntoChain(newBlock) {
    console.log(`Found ${newBlock.data.length} pending transactions in block`)
    let proofOfWorkModule
    switch (newBlock[Symbol.for('version')]) {
      case '2.0': {
        proofOfWorkModule = await import('./bitcoinService/proof_of_work3.js')
        break;
      }
      default: case '1.0':
        proofOfWorkModule = await import('./bitcoinService/proof_of_work2.js')
        break;
    }
    const { proofOfWork } = proofOfWorkModule
    ledger.push(await proofOfWork(newBlock, ''.padStart(newBlock.difficulty, '0')))
    return ledger
  }
async function mineNewBlockIntoChain ( newBlock ) { console . log ( ` ${ newBlock . data . length } ` ) let proofOfWorkModule switch ( newBlock [ Symbol . for ( 'version' ) ] ) { case '2.0' : { proofOfWorkModule = await import ( './bitcoinService/proof_of_work3.js' ) break ; } default : case '1.0' : proofOfWorkModule = await import ( './bitcoinService/proof_of_work2.js' ) break ; } const { proofOfWork } = proofOfWorkModule ledger . push ( await proofOfWork ( newBlock , '' . padStart ( newBlock . difficulty , '0' ) ) ) return ledger }
Mines a new block into the chain.
Mines a new block into the chain .