/**
  * @param Math $math
  * @param BlockHeaderInterface $genesis
  * @param HeaderStorage $blocks
  * @param BlockIndex $index
  */
 public function __construct(Math $math, BlockHeaderInterface $genesis, HeaderStorage $blocks, BlockIndex $index)
 {
     $this->math = $math;
     $this->index = $index;
     $this->genesis = $genesis;
     $this->headers = $blocks;
     try {
         $this->index()->height()->height();
     } catch (\Exception $e) {
         $this->headers->save($genesis);
         $this->index->saveGenesis($genesis);
     }
     $initBlock = $this->chainTip();
     $this->difficulty = new Difficulty($math, $initBlock->getBits());
     $this->chainDiff = $this->difficulty->getDifficulty($initBlock->getBits());
     $this->pow = new ProofOfWork($this->math, $this->difficulty, $this->chainDiff);
 }
Beispiel #2
0
 /**
  * @param Math $math
  * @param BlockInterface $genesis
  * @param BlockStorage $blocks
  * @param BlockIndex $index
  * @param UtxoSet $utxoSet
  */
 public function __construct(Math $math, BlockInterface $genesis, BlockStorage $blocks, BlockIndex $index, UtxoSet $utxoSet)
 {
     $this->math = $math;
     $this->index = $index;
     $this->genesis = $genesis;
     $this->blocks = $blocks;
     $this->utxoset = $utxoSet;
     $this->difficulty = new Difficulty($math, $genesis->getHeader()->getBits());
     $this->chainDiff = $this->difficulty->getDifficulty($genesis->getHeader()->getBits());
     try {
         $this->index()->height()->height();
     } catch (\Exception $e) {
         $this->blocks->saveGenesis($genesis);
         $this->index->saveGenesis($genesis->getHeader());
     }
     $this->chainDiff = $this->difficulty->getDifficulty($this->chainTip()->getHeader()->getBits());
     $this->pow = new ProofOfWork($this->math, $this->difficulty, $this->chainDiff);
 }