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

PayToPubKeyHashAddress   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getPrefixByte() 0 5 2
A getScriptPubKey() 0 4 1
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