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

ScriptHashAddress::__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 ScriptHashAddress extends Base58Address
12
{
13
    /**
14
     * ScriptHashAddress constructor.
15
     * @param BufferInterface $hash
16
     */
17 36
    public function __construct(BufferInterface $hash)
18
    {
19 36
        if ($hash->getSize() !== 20) {
20
            throw new \RuntimeException("P2PKH address hash should be 20 bytes");
21
        }
22
23 36
        parent::__construct($hash);
24 36
    }
25
26
    /**
27
     * @param NetworkInterface $network
28
     * @return string
29
     */
30 20
    public function getPrefixByte(NetworkInterface $network = null)
31
    {
32 20
        $network = $network ?: Bitcoin::getNetwork();
33 20
        return pack("H*", $network->getP2shByte());
34
    }
35
36
    /**
37
     * @return ScriptInterface
38
     */
39 8
    public function getScriptPubKey()
40
    {
41 8
        return ScriptFactory::scriptPubKey()->payToScriptHash($this->getHash());
42
    }
43
}
44