|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Script\Path; |
|
4
|
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Script\Parser\Operation; |
|
6
|
|
|
use BitWasp\Bitcoin\Script\ScriptFactory; |
|
7
|
|
|
use BitWasp\Bitcoin\Script\ScriptInterface; |
|
8
|
|
|
|
|
9
|
|
|
class ScriptBranch |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var ScriptInterface |
|
13
|
|
|
*/ |
|
14
|
|
|
private $fullScript; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var array|\array[] |
|
18
|
|
|
*/ |
|
19
|
|
|
private $segments; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var array|\bool[] |
|
23
|
|
|
*/ |
|
24
|
|
|
private $branch; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* ScriptBranch constructor. |
|
28
|
|
|
* @param ScriptInterface $fullScript |
|
29
|
|
|
* @param array $logicalPath |
|
30
|
|
|
* @param PathTrace $segments |
|
31
|
|
|
*/ |
|
32
|
154 |
|
public function __construct(ScriptInterface $fullScript, array $logicalPath, PathTrace $segments) |
|
33
|
|
|
{ |
|
34
|
154 |
|
$this->fullScript = $fullScript; |
|
35
|
154 |
|
$this->branch = $logicalPath; |
|
36
|
154 |
|
$this->segments = $segments; |
|
|
|
|
|
|
37
|
154 |
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return ScriptInterface |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getFullScript() |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->fullScript; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return array|\bool[] |
|
49
|
|
|
*/ |
|
50
|
154 |
|
public function getPath() |
|
51
|
|
|
{ |
|
52
|
154 |
|
return $this->branch; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return array|\array[]|PathTrace |
|
57
|
|
|
*/ |
|
58
|
136 |
|
public function getSegments() |
|
59
|
|
|
{ |
|
60
|
136 |
|
return $this->segments; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @return array |
|
65
|
|
|
*/ |
|
66
|
18 |
|
public function getOps() |
|
67
|
|
|
{ |
|
68
|
18 |
|
$sequence = []; |
|
69
|
18 |
|
foreach ($this->segments as $segment) { |
|
70
|
18 |
|
$sequence = array_merge($sequence, $segment->all()); |
|
71
|
|
|
} |
|
72
|
18 |
|
return $sequence; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @return ScriptInterface |
|
77
|
|
|
*/ |
|
78
|
18 |
|
public function getNeuteredScript() |
|
79
|
|
|
{ |
|
80
|
18 |
|
return ScriptFactory::fromOperations($this->getOps()); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @return ScriptInterface |
|
85
|
|
|
*/ |
|
86
|
|
|
public function getScript() |
|
87
|
|
|
{ |
|
88
|
|
|
return ScriptFactory::fromOperations(array_filter($this->getOps(), function (Operation $operation) { |
|
89
|
|
|
return !$operation->isLogical(); |
|
90
|
|
|
})); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @return array |
|
95
|
|
|
*/ |
|
96
|
|
|
public function __debugInfo() |
|
97
|
|
|
{ |
|
98
|
|
|
$m = []; |
|
99
|
|
|
foreach ($this->segments as $segment) { |
|
100
|
|
|
$m[] = ScriptFactory::fromOperations($segment->all()); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$path = []; |
|
104
|
|
|
foreach ($this->branch as $flag) { |
|
105
|
|
|
$path[] = $flag ? 'true' : 'false'; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
return [ |
|
109
|
|
|
'branch' => implode(", ", $path), |
|
110
|
|
|
'segments' => $m, |
|
111
|
|
|
]; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @return OperationContainer[] |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getSignSteps() |
|
118
|
|
|
{ |
|
119
|
|
|
$steps = []; |
|
120
|
|
|
foreach ($this->segments as $segment) { |
|
121
|
|
|
if (!$segment->isLoneLogicalOp()) { |
|
122
|
|
|
$steps[] = $segment; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
return $steps; |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..