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

SegwitAddress::getAddress()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
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\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
    public function __construct(WitnessProgram $witnessProgram)
22
    {
23
        $this->witnessProgram = $witnessProgram;
24
25
        parent::__construct($witnessProgram->getProgram());
26
    }
27
28
    /**
29
     * @param NetworkInterface|null $network
30
     * @return bool
31
     */
32
    public function getHRP(NetworkInterface $network = null)
33
    {
34
        $network = $network ?: Bitcoin::getNetwork();
35
        return $network->getSegwitBech32Prefix();
36
    }
37
38
    /**
39
     * @return \BitWasp\Bitcoin\Script\ScriptInterface
40
     */
41
    public function getScriptPubKey()
42
    {
43
        return $this->witnessProgram->getScript();
44
    }
45
46
    /**
47
     * @param NetworkInterface|null $network
48
     * @return string
49
     */
50
    public function getAddress(NetworkInterface $network = null)
51
    {
52
        $network = $network ?: Bitcoin::getNetwork();
53
54
        return SegwitBech32::encode($this->witnessProgram, $network);
55
    }
56
}
57