Completed
Pull Request — 0.0.35 (#707)
by thomas
23:28 queued 13:02
created

Slip132::p2shP2pkh()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace BitWasp\Bitcoin\Key\Deterministic\Slip132;
4
5
use BitWasp\Bitcoin\Bitcoin;
6
use BitWasp\Bitcoin\Key\Deterministic\HdPrefix\ScriptPrefix;
7
use BitWasp\Bitcoin\Key\KeyToScript\ScriptDataFactory;
8
use BitWasp\Bitcoin\Key\KeyToScript\KeyToScriptHelper;
9
10
class Slip132
11
{
12
    /**
13
     * @var KeyToScriptHelper
14
     */
15
    private $helper;
16
17
    /**
18
     * Slip132PrefixRegistry constructor.
19
20
     * @param KeyToScriptHelper $helper
21
     */
22 20
    public function __construct(KeyToScriptHelper $helper = null)
23
    {
24 20
        $this->helper = $helper ?: new KeyToScriptHelper(Bitcoin::getEcAdapter());
25 20
    }
26
27
    /**
28
     * @param PrefixRegistry $registry
29
     * @param ScriptDataFactory $factory
30
     * @return ScriptPrefix
31
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
32
     */
33 20
    private function loadPrefix(PrefixRegistry $registry, ScriptDataFactory $factory)
34
    {
35 20
        list ($private, $public) = $registry->getPrefixes($factory->getScriptType());
36 20
        return new ScriptPrefix($factory, $private, $public);
37
    }
38
39
    /**
40
     * xpub on bitcoin
41
     * @param PrefixRegistry $registry
42
     * @return ScriptPrefix
43
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
44
     */
45 6
    public function p2pkh(PrefixRegistry $registry)
46
    {
47 6
        return $this->loadPrefix($registry, $this->helper->getP2pkhFactory());
48
    }
49
50
    /**
51
     * ypub on bitcoin
52
     * @param PrefixRegistry $registry
53
     * @return ScriptPrefix
54
     * @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException
55
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
56
     */
57 4
    public function p2shP2wpkh(PrefixRegistry $registry)
58
    {
59 4
        return $this->loadPrefix($registry, $this->helper->getP2shFactory($this->helper->getP2wpkhFactory()));
60
    }
61
62
    /**
63
     * Ypub on bitcoin
64
     * @param PrefixRegistry $registry
65
     * @return ScriptPrefix
66
     * @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException
67
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
68
     * @deprecated
69
     */
70 2
    public function p2shP2wshP2pkh(PrefixRegistry $registry)
71
    {
72 2
        return $this->loadPrefix($registry, $this->helper->getP2shP2wshFactory($this->helper->getP2pkhFactory()));
73
    }
74
75
    /**
76
     * zpub on bitcoin
77
     * @param PrefixRegistry $registry
78
     * @return ScriptPrefix
79
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
80
     */
81 6
    public function p2wpkh(PrefixRegistry $registry)
82
    {
83 6
        return $this->loadPrefix($registry, $this->helper->getP2wpkhFactory());
84
    }
85
86
    /**
87
     * Zpub on bitcoin
88
     * @param PrefixRegistry $registry
89
     * @return ScriptPrefix
90
     * @throws \BitWasp\Bitcoin\Exceptions\DisallowedScriptDataFactoryException
91
     * @throws \BitWasp\Bitcoin\Exceptions\InvalidNetworkParameter
92
     * @deprecated
93
     */
94 2
    public function p2wshP2pkh(PrefixRegistry $registry)
95
    {
96 2
        return $this->loadPrefix($registry, $this->helper->getP2wshFactory($this->helper->getP2pkhFactory()));
97
    }
98
}
99