forked from MetacoSA/NBitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Litecoin.cs
500 lines (475 loc) · 23.4 KB
/
Litecoin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
using NBitcoin;
using NBitcoin.DataEncoders;
using System.Reflection;
using NBitcoin.Protocol;
using NBitcoin.RPC;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
namespace NBitcoin.Altcoins
{
public class Litecoin : NetworkSetBase
{
public static Litecoin Instance { get; } = new Litecoin();
public override string CryptoCode => "LTC";
private Litecoin()
{
}
//Format visual studio
//{({.*?}), (.*?)}
//Tuple.Create(new byte[]$1, $2)
static Tuple<byte[], int>[] pnSeed6_main =
{
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x01,0xca,0x80,0xda}, 10333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x18,0x92,0x06,0x11}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x1f,0x1f,0x4f,0x86}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x25,0x3b,0x18,0x0f}, 8331),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x25,0x61,0xa8,0xc8}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x25,0x8b,0x09,0xf8}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x26,0x6d,0xda,0x72}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x2d,0x28,0x89,0x72}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x2d,0x37,0xb0,0x1a}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x2e,0x1c,0xc9,0x44}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x2e,0x94,0x10,0xca}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x2e,0xac,0x04,0x1f}, 9335),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x2e,0xf9,0x2f,0xe9}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x2f,0x5a,0x04,0x29}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x2f,0x5a,0x2e,0xcb}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x2f,0xbd,0x81,0xda}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x32,0x07,0x2f,0x5a}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x32,0x16,0x67,0x82}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x34,0x29,0x09,0x40}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x3c,0xcd,0x3a,0x20}, 7749),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x3f,0xe7,0xef,0xd4}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x49,0x59,0xc3,0x81}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x4a,0xd0,0x2b,0x36}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x50,0xde,0x27,0x4d}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x50,0xf1,0xda,0x38}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x52,0xa5,0x80,0xd5}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x53,0x95,0x7d,0x4f}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x53,0xac,0x45,0x9a}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x53,0xd4,0x75,0x8c}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x54,0x34,0x91,0x24}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x54,0x57,0x79,0x0b}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x54,0x92,0x3f,0xdf}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x55,0x19,0x92,0x4a}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x58,0xb9,0x9b,0x86}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x5b,0xe2,0x0a,0x5a}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x5b,0xf0,0x8d,0xaf}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x5e,0x71,0x9c,0xdd}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x60,0x38,0x91,0xfa}, 10333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x60,0xff,0x06,0xfd}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x68,0xdf,0x3b,0x8c}, 23333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x6c,0x1f,0x0f,0x9a}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x6d,0xec,0x5a,0x7a}, 59333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x6f,0xcd,0x01,0xf6}, 10333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x71,0x0a,0x9c,0xb6}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x72,0x37,0x4a,0x02}, 20044),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x74,0x7d,0x78,0x1a}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x77,0x3f,0x2c,0x85}, 19992),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x77,0x93,0x89,0x9b}, 19992),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x86,0xd5,0xde,0xa1}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x93,0x9c,0x54,0xba}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x95,0xd2,0xab,0xe1}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xa2,0xf3,0xd8,0xf4}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xa3,0xac,0x21,0x4e}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xa3,0xac,0x23,0xf7}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xad,0xd0,0xc2,0x5e}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xae,0x3c,0x89,0x4c}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xb2,0x3f,0x12,0x03}, 9335),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xb2,0x3f,0x72,0x19}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xb2,0xfe,0x28,0x29}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xb7,0x3d,0x92,0x85}, 19992),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xb9,0x3c,0xf4,0xfb}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xb9,0x57,0xb8,0x1d}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xbc,0x00,0xb6,0x0a}, 9335),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xbc,0x8a,0x21,0x21}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xbc,0x9b,0x88,0x46}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xc0,0x63,0x3e,0x17}, 5001),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xc0,0xc6,0x64,0x54}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xc0,0xf1,0xa6,0x70}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xc6,0x0c,0x4b,0x19}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xcb,0xb1,0x8e,0x25}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xd3,0x6e,0x01,0x11}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xd3,0x95,0xf6,0x96}, 1022),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xd4,0x5d,0xe2,0x5a}, 9333),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xd5,0x7e,0x8d,0x3c}, 9333)
};
static Tuple<byte[], int>[] pnSeed6_test =
{
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x68,0xec,0xd3,0xce}, 19335),
Tuple.Create(new byte[]{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x42,0xb2,0xb6,0x23}, 19335)
};
#pragma warning disable CS0618 // Type or member is obsolete
public class LitecoinConsensusFactory : ConsensusFactory
{
private LitecoinConsensusFactory()
{
}
public static LitecoinConsensusFactory Instance { get; } = new LitecoinConsensusFactory();
public override Transaction CreateTransaction()
{
return new LitecoinTransaction();
}
public override BlockHeader CreateBlockHeader()
{
return new LitecoinBlockHeader();
}
public override Block CreateBlock()
{
return new LitecoinBlock(new LitecoinBlockHeader());
}
}
public class LitecoinTransaction : Transaction
{
public LitecoinTransaction()
{
}
public override ConsensusFactory GetConsensusFactory()
{
return LitecoinConsensusFactory.Instance;
}
public override void ReadWrite(BitcoinStream stream)
{
var witSupported = (((uint)stream.TransactionOptions & (uint)TransactionOptions.Witness) != 0) &&
stream.ProtocolCapabilities.SupportWitness;
//var mwebSupported = false; //when mweb is supported in nbitcoin this is to be fixed
byte flags = 0;
if (!stream.Serializing)
{
stream.ReadWrite(ref nVersion);
/* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
stream.ReadWrite(ref vin);
vin.Transaction = this;
var hasNoDummy = (nVersion & NoDummyInput) != 0 && vin.Count == 0;
if (witSupported && hasNoDummy)
nVersion = nVersion & ~NoDummyInput;
if (vin.Count == 0 && witSupported && !hasNoDummy)
{
/* We read a dummy or an empty vin. */
stream.ReadWrite(ref flags);
if (flags != 0)
{
/* Assume we read a dummy and a flag. */
stream.ReadWrite(ref vin);
vin.Transaction = this;
stream.ReadWrite(ref vout);
vout.Transaction = this;
}
else
{
/* Assume read a transaction without output. */
vout = new TxOutList();
vout.Transaction = this;
}
}
else
{
/* We read a non-empty vin. Assume a normal vout follows. */
stream.ReadWrite(ref vout);
vout.Transaction = this;
}
if (((flags & 1) != 0) && witSupported)
{
/* The witness flag is present, and we support witnesses. */
flags ^= 1;
Witness wit = new Witness(Inputs);
wit.ReadWrite(stream);
}
if ((flags & 8) != 0) //MWEB extension tx flag
{
/* The MWEB flag is present, but currently no MWEB data is supported.
* This fix just prevent from throwing exception bellow so cannonical litecoin transaction can be read
*/
flags ^= 8;
}
if (flags != 0)
{
/* Unknown flag in the serialization */
throw new FormatException("Unknown transaction optional data");
}
}
else
{
var version = (witSupported && (vin.Count == 0 && vout.Count > 0)) ? nVersion | NoDummyInput : nVersion;
stream.ReadWrite(ref version);
if (witSupported)
{
/* Check whether witnesses need to be serialized. */
if (HasWitness)
{
flags |= 1;
}
}
if (flags != 0)
{
/* Use extended format in case witnesses are to be serialized. */
TxInList vinDummy = new TxInList();
stream.ReadWrite(ref vinDummy);
stream.ReadWrite(ref flags);
}
stream.ReadWrite(ref vin);
vin.Transaction = this;
stream.ReadWrite(ref vout);
vout.Transaction = this;
if ((flags & 1) != 0)
{
Witness wit = new Witness(this.Inputs);
wit.ReadWrite(stream);
}
}
stream.ReadWriteStruct(ref nLockTime);
}
}
public class LitecoinBlockHeader : BlockHeader
{
public override uint256 GetPoWHash()
{
var headerBytes = this.ToBytes();
var h = NBitcoin.Crypto.SCrypt.ComputeDerivedKey(headerBytes, headerBytes, 1024, 1, 1, null, 32);
return new uint256(h);
}
}
public class LitecoinBlock : Block
{
public LitecoinBlock(LitecoinBlockHeader header) : base(header)
{
}
public override ConsensusFactory GetConsensusFactory()
{
return LitecoinConsensusFactory.Instance;
}
}
public class LitecoinMainnetAddressStringParser : NetworkStringParser
{
public override bool TryParse(string str, Network network, Type targetType, out IBitcoinString result)
{
if(str.StartsWith("Ltpv", StringComparison.OrdinalIgnoreCase) && targetType.GetTypeInfo().IsAssignableFrom(typeof(BitcoinExtKey).GetTypeInfo()))
{
try
{
var decoded = Encoders.Base58Check.DecodeData(str);
decoded[0] = 0x04;
decoded[1] = 0x88;
decoded[2] = 0xAD;
decoded[3] = 0xE4;
result = new BitcoinExtKey(Encoders.Base58Check.EncodeData(decoded), network);
return true;
}
catch
{
}
}
if(str.StartsWith("Ltub", StringComparison.OrdinalIgnoreCase) && targetType.GetTypeInfo().IsAssignableFrom(typeof(BitcoinExtPubKey).GetTypeInfo()))
{
try
{
var decoded = Encoders.Base58Check.DecodeData(str);
decoded[0] = 0x04;
decoded[1] = 0x88;
decoded[2] = 0xB2;
decoded[3] = 0x1E;
result = new BitcoinExtPubKey(Encoders.Base58Check.EncodeData(decoded), network);
return true;
}
catch
{
}
}
return base.TryParse(str, network, targetType, out result);
}
}
public class LitecoinTestnetAddressStringParser : NetworkStringParser
{
public override bool TryParse(string str, Network network, Type targetType, out IBitcoinString result)
{
if (str.StartsWith("ttpv", StringComparison.OrdinalIgnoreCase) && targetType.GetTypeInfo().IsAssignableFrom(typeof(BitcoinExtKey).GetTypeInfo()))
{
try
{
var decoded = Encoders.Base58Check.DecodeData(str);
decoded[0] = 0x04;
decoded[1] = 0x35;
decoded[2] = 0x83;
decoded[3] = 0x94;
result = new BitcoinExtKey(Encoders.Base58Check.EncodeData(decoded), network);
return true;
}
catch
{
}
}
if (str.StartsWith("ttub", StringComparison.OrdinalIgnoreCase) && targetType.GetTypeInfo().IsAssignableFrom(typeof(BitcoinExtPubKey).GetTypeInfo()))
{
try
{
var decoded = Encoders.Base58Check.DecodeData(str);
decoded[0] = 0x04;
decoded[1] = 0x35;
decoded[2] = 0x87;
decoded[3] = 0xCF;
result = new BitcoinExtPubKey(Encoders.Base58Check.EncodeData(decoded), network);
return true;
}
catch
{
}
}
return base.TryParse(str, network, targetType, out result);
}
}
#pragma warning restore CS0618 // Type or member is obsolete
protected override void PostInit()
{
RegisterDefaultCookiePath("Litecoin", new FolderName() { TestnetFolder = "testnet4" });
}
protected override NetworkBuilder CreateMainnet()
{
var bech32 = Encoders.Bech32("ltc");
NetworkBuilder builder = new NetworkBuilder();
builder.SetConsensus(new Consensus()
{
SubsidyHalvingInterval = 840000,
MajorityEnforceBlockUpgrade = 750,
MajorityRejectBlockOutdated = 950,
MajorityWindow = 1000,
BIP34Hash = new uint256("fa09d204a83a768ed5a7c8d441fa62f2043abf420cff1226c7b4329aeb9d51cf"),
PowLimit = new Target(new uint256("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")),
PowTargetTimespan = TimeSpan.FromSeconds(3.5 * 24 * 60 * 60),
PowTargetSpacing = TimeSpan.FromSeconds(2.5 * 60),
PowAllowMinDifficultyBlocks = false,
PowNoRetargeting = false,
RuleChangeActivationThreshold = 6048,
MinerConfirmationWindow = 8064,
CoinbaseMaturity = 100,
LitecoinWorkCalculation = true,
ConsensusFactory = LitecoinConsensusFactory.Instance,
SupportSegwit = true,
SupportTaproot = true
})
.SetBase58Bytes(Base58Type.PUBKEY_ADDRESS, new byte[] { 48 })
.SetBase58Bytes(Base58Type.SCRIPT_ADDRESS, new byte[] { 50 })
.SetBase58Bytes(Base58Type.SECRET_KEY, new byte[] { 176 })
.SetBase58Bytes(Base58Type.EXT_PUBLIC_KEY, new byte[] { 0x04, 0x88, 0xB2, 0x1E })
.SetBase58Bytes(Base58Type.EXT_SECRET_KEY, new byte[] { 0x04, 0x88, 0xAD, 0xE4 })
.SetNetworkStringParser(new LitecoinMainnetAddressStringParser())
.SetBech32(Bech32Type.WITNESS_PUBKEY_ADDRESS, bech32)
.SetBech32(Bech32Type.WITNESS_SCRIPT_ADDRESS, bech32)
.SetBech32(Bech32Type.TAPROOT_ADDRESS, bech32)
.SetMagic(0xdbb6c0fb)
.SetPort(9333)
.SetRPCPort(9332)
.SetName("ltc-main")
.AddAlias("ltc-mainnet")
.AddAlias("litecoin-mainnet")
.AddAlias("litecoin-main")
.SetUriScheme("litecoin")
.AddDNSSeeds(new[]
{
new DNSSeedData("loshan.co.uk", "seed-a.litecoin.loshan.co.uk"),
new DNSSeedData("thrasher.io", "dnsseed.thrasher.io"),
new DNSSeedData("litecointools.com", "dnsseed.litecointools.com"),
new DNSSeedData("litecoinpool.org", "dnsseed.litecoinpool.org"),
new DNSSeedData("koin-project.com", "dnsseed.koin-project.com"),
})
.AddSeeds(ToSeed(pnSeed6_main))
.SetGenesis("010000000000000000000000000000000000000000000000000000000000000000000000d9ced4ed1130f7b7faad9be25323ffafa33232a17c3edf6cfd97bee6bafbdd97b9aa8e4ef0ff0f1ecd513f7c0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4804ffff001d0104404e592054696d65732030352f4f63742f32303131205374657665204a6f62732c204170706c65e280997320566973696f6e6172792c2044696573206174203536ffffffff0100f2052a010000004341040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9ac00000000");
return builder;
}
protected override NetworkBuilder CreateTestnet()
{
var bech32 = Encoders.Bech32("tltc");
var builder = new NetworkBuilder();
builder.SetConsensus(new Consensus()
{
SubsidyHalvingInterval = 840000,
MajorityEnforceBlockUpgrade = 51,
MajorityRejectBlockOutdated = 75,
MajorityWindow = 1000,
PowLimit = new Target(new uint256("00000fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")),
PowTargetTimespan = TimeSpan.FromSeconds(3.5 * 24 * 60 * 60),
PowTargetSpacing = TimeSpan.FromSeconds(2.5 * 60),
PowAllowMinDifficultyBlocks = true,
PowNoRetargeting = false,
RuleChangeActivationThreshold = 1512,
MinerConfirmationWindow = 2016,
CoinbaseMaturity = 100,
LitecoinWorkCalculation = true,
ConsensusFactory = LitecoinConsensusFactory.Instance,
SupportSegwit = true,
SupportTaproot = true
})
.SetBase58Bytes(Base58Type.PUBKEY_ADDRESS, new byte[] { 111 })
.SetBase58Bytes(Base58Type.SCRIPT_ADDRESS, new byte[] { 58 })
.SetBase58Bytes(Base58Type.SECRET_KEY, new byte[] { 239 })
.SetBase58Bytes(Base58Type.EXT_PUBLIC_KEY, new byte[] { 0x04, 0x35, 0x87, 0xCF })
.SetBase58Bytes(Base58Type.EXT_SECRET_KEY, new byte[] { 0x04, 0x35, 0x83, 0x94 })
.SetNetworkStringParser(new LitecoinTestnetAddressStringParser())
.SetBech32(Bech32Type.WITNESS_PUBKEY_ADDRESS, bech32)
.SetBech32(Bech32Type.WITNESS_SCRIPT_ADDRESS, bech32)
.SetBech32(Bech32Type.TAPROOT_ADDRESS, bech32)
.SetMagic(0xf1c8d2fd)
.SetPort(19335)
.SetRPCPort(19332)
.SetName("ltc-test")
.AddAlias("ltc-testnet")
.AddAlias("litecoin-test")
.AddAlias("litecoin-testnet")
.SetUriScheme("litecoin")
.AddDNSSeeds(new[]
{
new DNSSeedData("litecointools.com", "testnet-seed.litecointools.com"),
new DNSSeedData("loshan.co.uk", "seed-b.litecoin.loshan.co.uk"),
new DNSSeedData("thrasher.io", "dnsseed-testnet.thrasher.io"),
})
.AddSeeds(ToSeed(pnSeed6_test))
.SetGenesis("010000000000000000000000000000000000000000000000000000000000000000000000d9ced4ed1130f7b7faad9be25323ffafa33232a17c3edf6cfd97bee6bafbdd97f60ba158f0ff0f1ee17904000101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4804ffff001d0104404e592054696d65732030352f4f63742f32303131205374657665204a6f62732c204170706c65e280997320566973696f6e6172792c2044696573206174203536ffffffff0100f2052a010000004341040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9ac00000000");
return builder;
}
protected override NetworkBuilder CreateRegtest()
{
var bech32 = Encoders.Bech32("rltc");
var builder = new NetworkBuilder();
builder.SetConsensus(new Consensus()
{
SubsidyHalvingInterval = 150,
MajorityEnforceBlockUpgrade = 51,
MajorityRejectBlockOutdated = 75,
MajorityWindow = 144,
PowLimit = new Target(new uint256("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")),
PowTargetTimespan = TimeSpan.FromSeconds(3.5 * 24 * 60 * 60),
PowTargetSpacing = TimeSpan.FromSeconds(2.5 * 60),
PowAllowMinDifficultyBlocks = true,
MinimumChainWork = uint256.Zero,
PowNoRetargeting = true,
RuleChangeActivationThreshold = 108,
MinerConfirmationWindow = 2016,
CoinbaseMaturity = 100,
LitecoinWorkCalculation = true,
ConsensusFactory = LitecoinConsensusFactory.Instance,
SupportSegwit = true,
SupportTaproot = true
})
.SetBase58Bytes(Base58Type.PUBKEY_ADDRESS, new byte[] { 111 })
.SetBase58Bytes(Base58Type.SCRIPT_ADDRESS, new byte[] { 58 })
.SetBase58Bytes(Base58Type.SECRET_KEY, new byte[] { 239 })
.SetBase58Bytes(Base58Type.EXT_PUBLIC_KEY, new byte[] { 0x04, 0x35, 0x87, 0xCF })
.SetBase58Bytes(Base58Type.EXT_SECRET_KEY, new byte[] { 0x04, 0x35, 0x83, 0x94 })
.SetBech32(Bech32Type.WITNESS_PUBKEY_ADDRESS, bech32)
.SetBech32(Bech32Type.WITNESS_SCRIPT_ADDRESS, bech32)
.SetBech32(Bech32Type.TAPROOT_ADDRESS, bech32)
.SetMagic(0xdab5bffa)
.SetPort(19444)
.SetRPCPort(19443)
.SetName("ltc-reg")
.AddAlias("ltc-regtest")
.AddAlias("litecoin-reg")
.AddAlias("litecoin-regtest")
.SetUriScheme("litecoin")
.SetGenesis("010000000000000000000000000000000000000000000000000000000000000000000000d9ced4ed1130f7b7faad9be25323ffafa33232a17c3edf6cfd97bee6bafbdd97dae5494dffff7f20000000000101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff4804ffff001d0104404e592054696d65732030352f4f63742f32303131205374657665204a6f62732c204170706c65e280997320566973696f6e6172792c2044696573206174203536ffffffff0100f2052a010000004341040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9ac00000000");
return builder;
}
}
}