Completed
Pull Request — master (#99)
by thomas
18:19
created

BitcoinCash::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 1
dl 0
loc 21
ccs 16
cts 16
cp 1
crap 2
rs 9.3142
c 0
b 0
f 0
1
<?php
2
3
namespace Blocktrail\SDK\Network;
4
5
use BitWasp\Bitcoin\Network\Network;
6
use BitWasp\Bitcoin\Network\NetworkFactory;
7
8
class BitcoinCash extends Network implements BitcoinCashNetworkInterface
9
{
10
    /**
11
     * @var string
12
     */
13
    private $cashAddressPrefix;
14
15
    /**
16
     * BitcoinCash constructor.
17
     * @param bool $testnet
18
     * @throws \Exception
19
     */
20 10
    public function __construct($testnet = false) {
21 10
        if ($testnet) {
22 6
            $base = NetworkFactory::bitcoinTestnet();
23 6
            $cashAddressPrefix = "bchtest";
24
        } else {
25 4
            $base = NetworkFactory::bitcoin();
26 4
            $cashAddressPrefix = "bitcoincash";
27
        }
28
29 10
        parent::__construct(
30 10
            $base->getAddressByte(),
31 10
            $base->getP2shByte(),
32 10
            $base->getPrivByte(),
33 10
            $base->isTestnet()
34
        );
35
36 10
        $this->setHDPrivByte($base->getHDPrivByte());
37 10
        $this->setHDPubByte($base->getHDPubByte());
38 10
        $this->setNetMagicBytes($base->getNetMagicBytes());
39 10
        $this->cashAddressPrefix = $cashAddressPrefix;
40 10
    }
41
42
    /**
43
     * @return string
44
     */
45 7
    public function getCashAddressPrefix() {
46 7
        return $this->cashAddressPrefix;
47
    }
48
}
49