Completed
Pull Request — master (#517)
by thomas
72:19
created

PayToPubKeyHashAddress   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 5
cts 5
cp 1
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 38
     */
17
    public function __construct(BufferInterface $hash)
18 38
    {
19 38
        if ($hash->getSize() !== 20) {
20
            throw new \RuntimeException("P2PKH address hash should be 20 bytes");
21
        }
22
23
        parent::__construct($hash);
24
    }
25 16
26
    /**
27 16
     * @param NetworkInterface $network
28
     * @return string
29
     */
30
    public function getPrefixByte(NetworkInterface $network = null)
31
    {
32
        $network = $network ?: Bitcoin::getNetwork();
33
        return pack("H*", $network->getAddressByte());
34
    }
35
36
    /**
37
     * @return ScriptInterface
38
     */
39
    public function getScriptPubKey()
40
    {
41
        return ScriptFactory::scriptPubKey()->payToPubKeyHash($this->getHash());
42
    }
43
}
44