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

ScriptHashAddress::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 2
cts 2
cp 1
crap 2
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 ScriptHashAddress extends Base58Address
12
{
13
    /**
14
     * ScriptHashAddress constructor.
15
     * @param BufferInterface $hash
16 20
     */
17
    public function __construct(BufferInterface $hash)
18 20
    {
19 20
        if ($hash->getSize() !== 20) {
20
            throw new \RuntimeException("P2PKH address hash should be 20 bytes");
21
        }
22
23
        parent::__construct($hash);
24
    }
25 8
26
    /**
27 8
     * @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->getP2shByte());
34
    }
35
36
    /**
37
     * @return ScriptInterface
38
     */
39
    public function getScriptPubKey()
40
    {
41
        return ScriptFactory::scriptPubKey()->payToScriptHash($this->getHash());
42
    }
43
}
44