1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace BitWasp\Bitcoin\Chain; |
6
|
|
|
|
7
|
|
|
use BitWasp\Bitcoin\Block\Block; |
8
|
|
|
use BitWasp\Bitcoin\Block\BlockHeader; |
9
|
|
|
use BitWasp\Bitcoin\Block\BlockHeaderInterface; |
10
|
|
|
use BitWasp\Bitcoin\Block\BlockInterface; |
11
|
|
|
use BitWasp\Bitcoin\Math\Math; |
12
|
|
|
use BitWasp\Bitcoin\Script\Opcodes; |
13
|
|
|
use BitWasp\Bitcoin\Script\ScriptFactory; |
14
|
|
|
use BitWasp\Bitcoin\Transaction\Factory\TxBuilder; |
15
|
|
|
use BitWasp\Buffertools\Buffer; |
16
|
|
|
|
17
|
|
|
class Params implements ParamsInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var int |
21
|
|
|
*/ |
22
|
|
|
protected static $maxBlockSizeBytes = 1000000; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var int |
26
|
|
|
*/ |
27
|
|
|
protected static $maxMoney = 21000000; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var int |
31
|
|
|
*/ |
32
|
|
|
protected static $subsidyHalvingInterval = 210000; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var int |
36
|
|
|
*/ |
37
|
|
|
protected static $coinbaseMaturityAge = 120; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var int |
41
|
|
|
*/ |
42
|
|
|
protected static $p2shActivateTime = 1333238400; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* = 14 * 24 * 60 * 60 |
46
|
|
|
* @var int |
47
|
|
|
*/ |
48
|
|
|
protected static $powTargetTimespan = 1209600; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* = 10 * 60 |
52
|
|
|
* @var int |
53
|
|
|
*/ |
54
|
|
|
protected static $powTargetSpacing = 600; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var int |
58
|
|
|
*/ |
59
|
|
|
protected static $powRetargetInterval = 2016; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var string |
63
|
|
|
*/ |
64
|
|
|
protected static $powTargetLimit = '26959946667150639794667015087019630673637144422540572481103610249215'; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Hex: 1d00ffff |
68
|
|
|
* @var int |
69
|
|
|
*/ |
70
|
|
|
protected static $powBitsLimit = 486604799; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var int |
74
|
|
|
*/ |
75
|
|
|
protected static $majorityWindow = 1000; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @var int |
79
|
|
|
*/ |
80
|
|
|
protected static $majorityEnforceBlockUpgrade = 750; |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @var Math |
85
|
|
|
*/ |
86
|
|
|
protected $math; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @param Math $math |
90
|
|
|
*/ |
91
|
5 |
|
public function __construct(Math $math) |
92
|
|
|
{ |
93
|
5 |
|
$this->math = $math; |
94
|
5 |
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return BlockHeaderInterface |
98
|
|
|
*/ |
99
|
1 |
|
public function getGenesisBlockHeader(): BlockHeaderInterface |
100
|
|
|
{ |
101
|
1 |
|
return new BlockHeader( |
102
|
1 |
|
1, |
103
|
1 |
|
Buffer::hex('00', 32), |
104
|
1 |
|
Buffer::hex('4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b', 32), |
105
|
1 |
|
1231006505, |
106
|
1 |
|
0x1d00ffff, |
107
|
1 |
|
2083236893 |
108
|
|
|
); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return BlockInterface |
113
|
|
|
*/ |
114
|
1 |
|
public function getGenesisBlock(): BlockInterface |
115
|
|
|
{ |
116
|
1 |
|
$timestamp = new Buffer('The Times 03/Jan/2009 Chancellor on brink of second bailout for banks', null, $this->math); |
117
|
1 |
|
$publicKey = Buffer::hex('04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f', null, $this->math); |
118
|
|
|
|
119
|
1 |
|
$inputScript = ScriptFactory::create() |
120
|
1 |
|
->push(Buffer::int('486604799', 4, $this->math)->flip()) |
|
|
|
|
121
|
1 |
|
->push(Buffer::int('4', 1, $this->math)) |
122
|
1 |
|
->push($timestamp) |
123
|
1 |
|
->getScript(); |
124
|
|
|
|
125
|
1 |
|
return new Block( |
126
|
1 |
|
$this->math, |
127
|
1 |
|
$this->getGenesisBlockHeader(), |
128
|
1 |
|
(new TxBuilder) |
129
|
1 |
|
->version(1) |
130
|
1 |
|
->input(new Buffer('', 32), 0xffffffff, $inputScript) |
|
|
|
|
131
|
1 |
|
->output(5000000000, ScriptFactory::sequence([$publicKey, Opcodes::OP_CHECKSIG])) |
132
|
1 |
|
->locktime(0) |
133
|
1 |
|
->get() |
134
|
|
|
); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return int |
139
|
|
|
*/ |
140
|
1 |
|
public function maxBlockSizeBytes(): int |
141
|
|
|
{ |
142
|
1 |
|
return static::$maxBlockSizeBytes; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return int |
147
|
|
|
*/ |
148
|
1 |
|
public function subsidyHalvingInterval(): int |
149
|
|
|
{ |
150
|
1 |
|
return static::$subsidyHalvingInterval; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @return int |
155
|
|
|
*/ |
156
|
1 |
|
public function coinbaseMaturityAge(): int |
157
|
|
|
{ |
158
|
1 |
|
return static::$coinbaseMaturityAge; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @return int |
163
|
|
|
*/ |
164
|
1 |
|
public function maxMoney(): int |
165
|
|
|
{ |
166
|
1 |
|
return static::$maxMoney; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return int |
171
|
|
|
*/ |
172
|
1 |
|
public function powTargetTimespan(): int |
173
|
|
|
{ |
174
|
1 |
|
return static::$powTargetTimespan ; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return int |
179
|
|
|
*/ |
180
|
1 |
|
public function powTargetSpacing(): int |
181
|
|
|
{ |
182
|
1 |
|
return static::$powTargetSpacing; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return int |
187
|
|
|
*/ |
188
|
1 |
|
public function powRetargetInterval(): int |
189
|
|
|
{ |
190
|
1 |
|
return static::$powRetargetInterval; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @return int|string |
195
|
|
|
*/ |
196
|
1 |
|
public function powTargetLimit(): string |
197
|
|
|
{ |
198
|
1 |
|
return static::$powTargetLimit; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @return int |
203
|
|
|
*/ |
204
|
190 |
|
public function powBitsLimit(): int |
205
|
|
|
{ |
206
|
190 |
|
return static::$powBitsLimit; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
/** |
210
|
|
|
* @return int |
211
|
|
|
*/ |
212
|
1 |
|
public function majorityEnforceBlockUpgrade(): int |
213
|
|
|
{ |
214
|
1 |
|
return static::$majorityEnforceBlockUpgrade; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @return int |
219
|
|
|
*/ |
220
|
1 |
|
public function majorityWindow(): int |
221
|
|
|
{ |
222
|
1 |
|
return static::$majorityWindow; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @return int |
227
|
|
|
*/ |
228
|
1 |
|
public function p2shActivateTime(): int |
229
|
|
|
{ |
230
|
1 |
|
return static::$p2shActivateTime; |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @return int |
235
|
|
|
*/ |
236
|
1 |
|
public function getMaxBlockSigOps(): int |
237
|
|
|
{ |
238
|
1 |
|
return $this->maxBlockSizeBytes() / 50; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* @return int |
243
|
|
|
*/ |
244
|
1 |
|
public function getMaxTxSigOps(): int |
245
|
|
|
{ |
246
|
1 |
|
return $this->getMaxBlockSigOps() / 5; |
247
|
|
|
} |
248
|
|
|
} |
249
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.