1 | <?php |
||
9 | class MultisigHD |
||
10 | { |
||
11 | /** |
||
12 | * @var int|string |
||
13 | */ |
||
14 | private $m; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | private $path; |
||
20 | |||
21 | /** |
||
22 | * @var HierarchicalKey[] |
||
23 | */ |
||
24 | private $keys; |
||
25 | |||
26 | /** |
||
27 | * @var HierarchicalKeySequence |
||
28 | */ |
||
29 | private $sequences; |
||
30 | |||
31 | /** |
||
32 | * @var P2shScript |
||
33 | */ |
||
34 | private $redeemScript; |
||
35 | |||
36 | /** |
||
37 | * @var bool |
||
38 | */ |
||
39 | private $sort; |
||
40 | |||
41 | /** |
||
42 | * @param int|string $m |
||
43 | * @param string $path |
||
44 | * @param array $keys |
||
45 | * @param HierarchicalKeySequence $sequences |
||
46 | * @param bool $sort |
||
47 | */ |
||
48 | 14 | public function __construct($m, $path, array $keys, HierarchicalKeySequence $sequences, $sort = false) |
|
49 | { |
||
50 | 14 | if (count($keys) < 1) { |
|
51 | 2 | throw new \RuntimeException('Must have at least one HierarchicalKey for Multisig HD Script'); |
|
52 | } |
||
53 | |||
54 | // Sort here to guarantee calls to getKeys() returns keys in the same order as the redeemScript. |
||
55 | 12 | if ($sort) { |
|
56 | 10 | $keys = $this->sortHierarchicalKeys($keys); |
|
57 | } |
||
58 | |||
59 | 12 | foreach ($keys as $key) { |
|
60 | 12 | $this->keys[] = $key; |
|
61 | } |
||
62 | |||
63 | 12 | $this->m = $m; |
|
64 | 12 | $this->path = $path; |
|
65 | 12 | $this->sort = $sort; |
|
66 | 12 | $this->sequences = $sequences; |
|
67 | 12 | $this->redeemScript = new P2shScript(ScriptFactory::scriptPubKey()->multisig($m, array_map( |
|
68 | 12 | function (HierarchicalKey $key) { |
|
69 | 12 | return $key->getPublicKey(); |
|
70 | 12 | }, |
|
71 | 12 | $this->keys |
|
72 | 12 | ), false)); |
|
73 | 12 | } |
|
74 | |||
75 | /** |
||
76 | * @param HierarchicalKey[] $keys |
||
77 | * @return HierarchicalKey[] |
||
78 | */ |
||
79 | private function sortHierarchicalKeys(array $keys) |
||
85 | |||
86 | /** |
||
87 | * @return string |
||
88 | */ |
||
89 | 2 | public function getPath() |
|
93 | |||
94 | /** |
||
95 | * Return the composite keys of this MultisigHD wallet entry. |
||
96 | * This will strictly adhere to the choice on whether keys should be sorted, since this is done in the constructor. |
||
97 | * |
||
98 | * @return HierarchicalKey[] |
||
99 | */ |
||
100 | 10 | public function getKeys() |
|
104 | |||
105 | /** |
||
106 | * Returns the redeemScript. Note - keys are already sorted in the constructor, so this is not required in ScriptFactory. |
||
107 | * |
||
108 | * @return P2shScript |
||
109 | */ |
||
110 | 4 | public function getRedeemScript() |
|
114 | |||
115 | /** |
||
116 | * @return \BitWasp\Bitcoin\Script\ScriptInterface |
||
117 | */ |
||
118 | public function getScriptPubKey() |
||
122 | |||
123 | /** |
||
124 | * @return \BitWasp\Bitcoin\Address\ScriptHashAddress |
||
125 | */ |
||
126 | 4 | public function getAddress() |
|
130 | |||
131 | /** |
||
132 | * Derive each HK child and produce a new MultisigHD object |
||
133 | * |
||
134 | * @param int|string $sequence |
||
135 | * @return MultisigHD |
||
136 | */ |
||
137 | 4 | public function deriveChild($sequence) |
|
158 | |||
159 | /** |
||
160 | * @param array|\stdClass|\Traversable $list |
||
161 | * @return MultisigHD |
||
162 | */ |
||
163 | 4 | public function deriveFromList($list) |
|
174 | |||
175 | /** |
||
176 | * Derive a path in the tree of available addresses. |
||
177 | * |
||
178 | * @param string $path |
||
179 | * @return MultisigHD |
||
180 | */ |
||
181 | 4 | public function derivePath($path) |
|
185 | } |
||
186 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.