Completed
Pull Request — master (#517)
by thomas
68:51 queued 66:33
created

PayToPubKeyHashAddress::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 4
cts 5
cp 0.8
crap 2.032
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace BitWasp\Bitcoin\Address;
4
5
use BitWasp\Bitcoin\Bitcoin;
6
use BitWasp\Bitcoin\Network\NetworkInterface;
7
use BitWasp\Bitcoin\Script\ScriptFactory;
8
use BitWasp\Bitcoin\Script\ScriptInterface;
9
use BitWasp\Buffertools\BufferInterface;
10
11
class PayToPubKeyHashAddress extends Base58Address
12
{
13
    /**
14
     * PayToPubKeyHashAddress constructor.
15
     * @param BufferInterface $hash
16
     */
17 56
    public function __construct(BufferInterface $hash)
18
    {
19 56
        if ($hash->getSize() !== 20) {
20
            throw new \RuntimeException("P2PKH address hash should be 20 bytes");
21
        }
22
23 56
        parent::__construct($hash);
24 56
    }
25
26
    /**
27
     * @param NetworkInterface $network
28
     * @return string
29
     */
30 38
    public function getPrefixByte(NetworkInterface $network = null)
31
    {
32 38
        $network = $network ?: Bitcoin::getNetwork();
33 38
        return pack("H*", $network->getAddressByte());
34
    }
35
36
    /**
37
     * @return ScriptInterface
38
     */
39 16
    public function getScriptPubKey()
40
    {
41 16
        return ScriptFactory::scriptPubKey()->payToPubKeyHash($this->getHash());
42
    }
43
}
44