bitcoin-php
bitcoin-php copied to clipboard
allow extending BlockHeader
to allow extending BlockHeader for ZCash
Sorry, this one made me pause for a while, and I regret not getting back to it sooner!
Any reason this can't be achieved with a complementary class ZcashBlockHeader which implements BlockHeaderInterface? That way you avoid the BlockHeader constructor checks, and we can avoid making private properties protected (part of the API, as people can hook into them..)
there is no way to hook into private properties, so it can not be considered as a part of api. it is completely hidden from the users.
you are right. i used decorator pattern to "extend" BlockHeader. but i still think it would be better to use protected props rather then private to allow direct extension.
<?php namespace ZCash;
use BitWasp\Bitcoin\Block\BlockHeader;
use BitWasp\Bitcoin\Block\BlockHeaderInterface;
use BitWasp\Bitcoin\Serializable;
use BitWasp\Buffertools\BufferInterface;
class ZCashBlockHeader extends Serializable implements BlockHeaderInterface
{
/** @var string */
protected $zcashNonce;
/** @var BlockHeader */
protected $blockHeader;
public function __construct(int $version, BufferInterface $prevBlock, BufferInterface $merkleRoot, int $timestamp, int $bits, string $zcashNonce)
{
$this->blockHeader = new BlockHeader($version, $prevBlock, $merkleRoot, $timestamp, $bits, 0);
$this->zcashNonce = $zcashNonce;
}
/**
* {@inheritdoc}
* @see \BitWasp\Bitcoin\Block\BlockHeaderInterface::getNonce()
*/
public function getNonce(): int
{
throw new ZCashGetNonceException("ZCash does not have integer nonce. Call ->getZcashNonce() method instead.");
}
public function getZcashNonce(): string
{
return $this->zcashNonce;
}
public function __call($name, $arguments)
{
$this->blockHeader->$name(...$arguments);
}
}