1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace BitWasp\Bitcoin\Transaction\Factory; |
4
|
|
|
|
5
|
|
|
use BitWasp\Bitcoin\Script\ScriptInterface; |
6
|
|
|
use BitWasp\Bitcoin\Script\WitnessScript; |
7
|
|
|
|
8
|
|
|
class SignData |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var ScriptInterface |
12
|
|
|
*/ |
13
|
|
|
protected $redeemScript = null; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var ScriptInterface |
17
|
|
|
*/ |
18
|
|
|
protected $witnessScript = null; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var int |
22
|
|
|
*/ |
23
|
|
|
protected $signaturePolicy = null; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var bool[] |
27
|
|
|
*/ |
28
|
|
|
protected $logicalPath = null; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param ScriptInterface $redeemScript |
32
|
|
|
* @return $this |
33
|
|
|
*/ |
34
|
17 |
|
public function p2sh(ScriptInterface $redeemScript) |
35
|
|
|
{ |
36
|
17 |
|
if ($redeemScript instanceof WitnessScript) { |
37
|
|
|
throw new \InvalidArgumentException("Cannot pass WitnessScript as a redeemScript"); |
38
|
|
|
} |
39
|
17 |
|
$this->redeemScript = $redeemScript; |
40
|
17 |
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return bool |
45
|
|
|
*/ |
46
|
55 |
|
public function hasRedeemScript() |
47
|
|
|
{ |
48
|
55 |
|
return $this->redeemScript instanceof ScriptInterface; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return ScriptInterface |
53
|
|
|
*/ |
54
|
38 |
|
public function getRedeemScript() |
55
|
|
|
{ |
56
|
38 |
|
if (null === $this->redeemScript) { |
57
|
1 |
|
throw new \RuntimeException('Redeem script requested but not set'); |
58
|
|
|
} |
59
|
|
|
|
60
|
37 |
|
return $this->redeemScript; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param ScriptInterface $witnessScript |
65
|
|
|
* @return $this |
66
|
|
|
*/ |
67
|
17 |
|
public function p2wsh(ScriptInterface $witnessScript) |
68
|
|
|
{ |
69
|
17 |
|
$this->witnessScript = $witnessScript; |
70
|
17 |
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return bool |
75
|
|
|
*/ |
76
|
55 |
|
public function hasWitnessScript() |
77
|
|
|
{ |
78
|
55 |
|
return $this->witnessScript instanceof ScriptInterface; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return ScriptInterface |
83
|
|
|
*/ |
84
|
35 |
|
public function getWitnessScript() |
85
|
|
|
{ |
86
|
35 |
|
if (null === $this->witnessScript) { |
87
|
1 |
|
throw new \RuntimeException('Witness script requested but not set'); |
88
|
|
|
} |
89
|
|
|
|
90
|
34 |
|
return $this->witnessScript; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param int $flags |
95
|
|
|
* @return $this |
96
|
|
|
*/ |
97
|
16 |
|
public function signaturePolicy($flags) |
98
|
|
|
{ |
99
|
16 |
|
$this->signaturePolicy = $flags; |
100
|
16 |
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @return bool |
105
|
|
|
*/ |
106
|
85 |
|
public function hasSignaturePolicy() |
107
|
|
|
{ |
108
|
85 |
|
return $this->signaturePolicy !== null; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return int |
113
|
|
|
*/ |
114
|
42 |
|
public function getSignaturePolicy() |
115
|
|
|
{ |
116
|
42 |
|
if (null === $this->signaturePolicy) { |
117
|
1 |
|
throw new \RuntimeException('Signature policy requested but not set'); |
118
|
|
|
} |
119
|
41 |
|
return $this->signaturePolicy; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param bool[] $vfPathTaken |
124
|
|
|
* @return $this |
125
|
|
|
*/ |
126
|
18 |
|
public function logicalPath(array $vfPathTaken) |
127
|
|
|
{ |
128
|
18 |
|
foreach ($vfPathTaken as $value) { |
129
|
11 |
|
if (!is_bool($value)) { |
130
|
11 |
|
throw new \RuntimeException("Invalid values for logical path, must be a boolean array"); |
131
|
|
|
} |
132
|
|
|
} |
133
|
|
|
|
134
|
18 |
|
$this->logicalPath = $vfPathTaken; |
135
|
18 |
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return bool |
140
|
|
|
*/ |
141
|
|
|
public function hasLogicalPath() |
142
|
|
|
{ |
143
|
|
|
return is_array($this->logicalPath); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return bool[] |
148
|
|
|
*/ |
149
|
11 |
|
public function getLogicalPath() |
150
|
|
|
{ |
151
|
11 |
|
if (null === $this->logicalPath) { |
152
|
|
|
throw new \RuntimeException("Logical path requested but not set"); |
153
|
|
|
} |
154
|
|
|
|
155
|
11 |
|
return $this->logicalPath; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|