Completed
Push — 0.0.35 ( b2fc74...d8d049 )
by thomas
28:12 queued 09:10
created

SegwitAddress::getWitnessProgram()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
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\WitnessProgram;
8
use BitWasp\Bitcoin\SegwitBech32;
9
10
class SegwitAddress extends Address implements Bech32AddressInterface
11
{
12
    /**
13
     * @var WitnessProgram
14
     */
15
    protected $witnessProgram;
16
17
    /**
18
     * SegwitAddress constructor.
19
     * @param WitnessProgram $witnessProgram
20
     */
21 9
    public function __construct(WitnessProgram $witnessProgram)
22
    {
23 9
        $this->witnessProgram = $witnessProgram;
24
25 9
        parent::__construct($witnessProgram->getProgram());
26 9
    }
27
28
    /**
29
     * @param NetworkInterface|null $network
30
     * @return bool
31
     */
32 6
    public function getHRP(NetworkInterface $network = null)
33
    {
34 6
        $network = $network ?: Bitcoin::getNetwork();
35 6
        return $network->getSegwitBech32Prefix();
36
    }
37
38
    /**
39
     * @return \BitWasp\Bitcoin\Script\ScriptInterface
40
     */
41 6
    public function getScriptPubKey()
42
    {
43 6
        return $this->witnessProgram->getScript();
44
    }
45
46
    /**
47
     * @return WitnessProgram
48
     */
49
    public function getWitnessProgram()
50
    {
51
        return $this->witnessProgram;
52
    }
53
54
    /**
55
     * @param NetworkInterface|null $network
56
     * @return string
57
     */
58 7
    public function getAddress(NetworkInterface $network = null)
59
    {
60 7
        $network = $network ?: Bitcoin::getNetwork();
61
62 7
        return SegwitBech32::encode($this->witnessProgram, $network);
63
    }
64
}
65