-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconsominer2unit.pas
753 lines (695 loc) · 20.5 KB
/
consominer2unit.pas
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
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
unit consominer2unit;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, IdTCPClient, IdGlobal, strutils, functions, nosotime;
Type
TSourcesData = packed record
ip : string;
port : integer;
Shares : integer;
filled : boolean;
balance : int64;
payinterval: integer;
FailedTrys : integer;
miners : integer;
fee : integer;
LastPay : string;
MaxShares : integer;
end;
TPayment = packed record
Pool : string[30];
block : integer;
ammount : int64;
OrderID : string[60];
end;
TSolution = Packed record
Hash : string;
Target : string;
Diff : string;
end;
Procedure LoadSources();
Function GetPoolInfo(PoolIp:String;PoolPort:integer):String;
Function GetPoolSource(Ip:String;Port:integer):String;
Procedure SendPoolShare(Data:TSolution);
Function RandonStartPool():integer;
Function AllFilled():Boolean;
Procedure FillAllPools();
Procedure ClearAllPools();
Function GetTotalPending():Int64;
Procedure SaveSource(LSource:TSourcesData);
Procedure SetStatusMsg(Lmessage:string;Lcolor:integer);
// Disk access
Procedure CreateConfig();
Procedure LoadConfig();
Function CheckSource():integer;
// Log manage
Procedure CreateLogFile();
Procedure Tolog(LLine:String);
Procedure CheckLog();
// Payments
Procedure CreatePaymentsFile();
Procedure CreateRAWPaymentsFile();
Function GetPoolLastPay(PoolName:String):String;
Procedure LoadPreviousPayments();
Procedure AddNewPayment(LData:Tpayment);
//*************
Procedure AddSolution(Data:TSolution);
Function SolutionsLength():Integer;
function GetSolution():TSolution;
Procedure ClearSolutions();
Procedure AddIntervalHashes(hashes:int64);
function GetTotalHashes : integer;
Procedure ResetIntervalHashes();
Procedure SetOMT(value:integer);
Procedure DecreaseOMT();
Function GetOMTValue():Integer;
Const
AppVer = '1.7';
ReleaseDate = 'Feb 14, 2023';
HasheableChars = '!"#$%&'#39')*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
DeveloperAddress = 'N3VXG1swUP3n46wUSY5yQmqQiHoaDED';
NTPServers = 'ts2.aco.net:hora.roa.es:time.esa.int:time.stdtime.gov.tw:stratum-1.sjc02.svwh.net:ntp1.sp.se:1.de.pool.ntp.org:';
fpcVersion = {$I %FPCVERSION%};
B58Alphabet : string = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
var
ArrSources : Array of TSourcesData;
MainThreadIsFinished : boolean = false;
SourcesStr : string = 'nosofish.xyz:8082 nosopool.estripa.online:8082 pool.nosomn.com:8082 159.196.1.198:8082 47.87.181.190:8082';
ArrLogLines : array of string;
FinishProgram : boolean = false;
MAXCPU : integer = 0;
CurrentBlock : integer = 0;
CurrSpeed : integer = 0;
CurrBlockAge : integer = 0;
ActivePool : integer = 0;
StatusMsg : string = '';
StatusColor : integer;
TimeOffSet : integer = 0;
// Files vars
FileConfig : Textfile;
FileLog : Textfile;
FilePayments : file of TPayment;
FileRAWPayments : Textfile;
// USer config
MyAddress : string = 'NpryectdevepmentfundsGE';
MyCPUCount : integer = 1;
MyHAshlib : integer = 70;
MyRunTest : boolean = True;
MyMaxShares : integer = 0;
MyDonation : integer = 5;
MyPassword : string = 'mypasswrd';
// Miner Variables
MyAddressBalance : int64 = 0;
ArrHashLibs : array[0..3] of integer;
MinerStartUTC : int64 = 0;
ReceivedPayments : integer = 0;
ReceivedNOSO : int64 = 0;
MAINPREFIX : string = '';
MinimunTargetDiff : string = '00000';
TargetHash : string = '00000000000000000000000000000000';
FinishMiners : boolean = false;
HashesForTest : integer = 100000;
ArrSolutions : Array of TSolution;
ThreadsIntervalHashes : integer = 0;
OpenMinerThreads : integer = 0;
LastSpeedCounter : int64 = 100000000;
PoolMinningAddress : string = '';
WaitingNextBlock : boolean = false;
BlockCompleted : boolean = false;
WrongThisPool : Integer = 0;
// Update screen
U_Headers : boolean = false;
U_BlockAge : int64 = 0;
U_ActivePool : boolean = false;
U_ClearPoolsScreen : boolean = false;
U_WaitNextBlock : boolean = false;
U_AddressNosoBalance : boolean = false;
U_TotalPending : boolean = false;
U_NewPayment : int64 = 0;
// Crititical sections
CS_Log : TRTLCriticalSection;
CS_ArrSources : TRTLCriticalSection;
CS_Solutions : TRTLCriticalSection;
CS_Interval : TRTLCriticalSection;
CS_MinerThreads : TRTLCriticalSection;
implementation
Function GetPoolInfo(PoolIp:String;PoolPort:integer):String;
var
TCPClient : TidTCPClient;
ResultLine : String = '';
Begin
Result := 'ERROR';
ResultLine := '';
TCPClient := TidTCPClient.Create(nil);
TCPclient.Host:=PoolIp;
TCPclient.Port:=PoolPort;
TCPclient.ConnectTimeout:= 3000;
TCPclient.ReadTimeout:=3000;
TRY
TCPclient.Connect;
TCPclient.IOHandler.WriteLn('POOLINFO');
ResultLine := TCPclient.IOHandler.ReadLn();
TCPclient.Disconnect();
EXCEPT on E:Exception do
begin
ResultLine := '';
end;
END{try};
TCPClient.Free;
if ResultLine <> '' then Result := ResultLine;
End;
Function GetPoolSource(Ip:String;Port:integer):String;
var
TCPClient : TidTCPClient;
ResultLine : String = '';
Begin
Result := 'ERROR';
ResultLine := '';
TCPClient := TidTCPClient.Create(nil);
TCPclient.Host:=IP;
TCPclient.Port:=Port;
TCPclient.ConnectTimeout:= 3000;
TCPclient.ReadTimeout:=3000;
TRY
TCPclient.Connect;
TCPclient.IOHandler.WriteLn('SOURCE '+MyAddress+' Cm2'+AppVer+' '+mypassword);
ResultLine := TCPclient.IOHandler.ReadLn(IndyTextEncoding_UTF8);
TCPclient.Disconnect();
EXCEPT on E:Exception do
begin
end;
END{try};
TCPClient.Free;
if Parameter(ResultLine,0)='OK' then
begin
Result := ResultLine;
end;
End;
Procedure SendPoolShare(Data:TSolution);
var
TCPClient : TidTCPClient;
IpandPor : String = '';
ResultLine : String = '';
Trys : integer = 0;
Success : boolean;
CreditAddress : String = '';
Begin
Randomize;
if ( (MyDonation>0) and ((Random(100)+1)<=MyDonation) ) then
CreditAddress := DeveloperAddress;
ResultLine := '';
TCPClient := TidTCPClient.Create(nil);
TCPclient.Host:=ArrSources[ActivePool].ip;
TCPclient.Port:=ArrSources[ActivePool].port;
TCPclient.ConnectTimeout:= 3000;
TCPclient.ReadTimeout:=3000;
REPEAT
Success := false;
Inc(Trys);
TRY
TCPclient.Connect;
TCPclient.IOHandler.WriteLn('SHARE '+Myaddress+' '+Data.Hash+' Cm2v'+AppVer+' '+CurrentBlock.ToString+' '+Data.target+' '+CreditAddress+' '+mypassword);
ResultLine := TCPclient.IOHandler.ReadLn(IndyTextEncoding_UTF8);
TCPclient.Disconnect();
Success := true;
EXCEPT on E:Exception do
begin
Success := false;
ToLog('Error sending share: '+E.Message);
end;
END{try};
UNTIL ((Success) or (Trys = 5));
TCPClient.Free;
if Success then
begin
if resultLine = 'True' then
begin
Inc(ArrSources[ActivePool].shares);
U_ActivePool := true;
SetStatusMsg('Submmited share '+ArrSources[ActivePool].shares.ToString+' to '+ArrSources[ActivePool].ip,2{green});
if ArrSources[ActivePool].shares >= ArrSources[ActivePool].MaxShares then
begin
ArrSources[ActivePool].filled:=true;
ClearSolutions();
Sleep(100);
FinishMiners := true;
end;
end
else
begin
SetStatusMsg('Rejected share : '+ResultLine,4{red});
Inc(WrongThisPool);
// Filter here if Shares limit was reached
If ((AnsiContainsStr(ResultLine,'SHARES_LIMIT')) or ( WrongThisPool = 3)) then
begin
ClearSolutions();
Sleep(10);
FinishMiners := true;
if AnsiContainsStr(ResultLine,'SHARES_LIMIT') then ArrSources[ActivePool].filled:=true;
end;
end;
end
else // Not send
begin
ToLog('Unable to send solution to '+TCPclient.Host);
SetStatusMsg('Connection error. Check your internet connection: '+WrongThisPool.ToString,4{red});
Inc(WrongThisPool);
if WrongThisPool = 3 then
begin
FinishMiners := true;
ArrSources[ActivePool].filled:=true;
ClearSolutions();
end;
//AddSolution(Data);
end;
End;
Procedure LoadSources();
var
ThisSource : string;
Counter : integer = 0;
Begin
SetLEngth(ArrSources,0);
Repeat
begin
ThisSource := Parameter(SourcesStr,counter);
If ThisSource<> '' then
begin
ThisSource := StringReplace(ThisSource,':',' ',[rfReplaceAll, rfIgnoreCase]);
SetLEngth(ArrSources,length(ArrSources)+1);
ArrSources[length(ArrSources)-1].ip:=Parameter(ThisSource,0);
ArrSources[length(ArrSources)-1].port:=StrToIntDef(Parameter(ThisSource,1),8082);
ArrSources[length(ArrSources)-1].filled:=false;
ArrSources[length(ArrSources)-1].shares:=0;
ArrSources[length(ArrSources)-1].balance:=0;
ArrSources[length(ArrSources)-1].payinterval:=0;
ArrSources[length(ArrSources)-1].FailedTrys:=0;
ArrSources[length(ArrSources)-1].Miners:=0;
ArrSources[length(ArrSources)-1].Fee:=0;
ArrSources[length(ArrSources)-1].LastPay:=GetPoolLastPay(Parameter(ThisSource,0));
ArrSources[length(ArrSources)-1].maxshares:=MyMaxShares;
end;
Inc(Counter);
end;
until ThisSource = '';
End;
Function RandonStartPool():integer;
Begin
result := Random(Length(ArrSources))-1;
End;
Function AllFilled():Boolean;
var
counter : integer;
Begin
result := true;
EnterCriticalSection(CS_ArrSources);
For counter := 0 to length(ArrSources)-1 do
begin
if ArrSources[counter].filled = false then
begin
result := false;
break;
end;
end;
LeaveCriticalSection(CS_ArrSources);
End;
Procedure FillAllPools();
var
counter : integer;
Begin
EnterCriticalSection(CS_ArrSources);
For counter := 0 to length(ArrSources)-1 do
ArrSources[counter].filled := true;
LeaveCriticalSection(CS_ArrSources);
End;
Procedure ClearAllPools();
var
counter : integer;
Begin
EnterCriticalSection(CS_ArrSources);
For counter := 0 to length(ArrSources)-1 do
begin
ArrSources[counter].filled := false;
ArrSources[counter].Shares := 0;
ArrSources[counter].FailedTrys := 0;
ArrSources[counter].Miners := 0;
ArrSources[counter].Fee := 0;
end;
LeaveCriticalSection(CS_ArrSources);
End;
Function GetTotalPending():Int64;
var
counter : integer;
Begin
Result := 0;
EnterCriticalSection(CS_ArrSources);
For counter := 0 to length(ArrSources)-1 do
Inc(Result,ArrSources[counter].balance);
LeaveCriticalSection(CS_ArrSources);
End;
Procedure SaveSource(LSource:TSourcesData);
var
counter : integer;
Begin
EnterCriticalSection(CS_ArrSources);
For counter := 0 to length(ArrSources)-1 do
begin
if ArrSources[counter].ip = LSource.ip then
begin
ArrSources[counter] := LSource;
break;
end;
end;
LeaveCriticalSection(CS_ArrSources);
End;
Procedure SetStatusMsg(Lmessage:string;Lcolor:integer);
Begin
Statusmsg := Lmessage;
StatusColor := LColor;
End;
Procedure CreateConfig();
Begin
TRY
rewrite(FileConfig);
writeln(FileConfig,'** Replace the default mining address with your own address. Aliases not allowed.');
writeln(FileConfig,'address '+MyAddress);
writeln(FileConfig,'** Set the number of CPUs/Threads you want use to mine.');
writeln(FileConfig,'cpu '+MyCPUCount.ToString);
writeln(FileConfig,'** Valid values: 65,68,69 and 70 (default).');
writeln(FileConfig,'hashlib '+MyHashLib.ToString);
writeln(FileConfig,'** Change to false to start mining when you launch the app.');
writeln(FileConfig,'test '+BoolToStr(MyRunTest,true));
writeln(FileConfig,'** Max number of shares to be submitted to each pool. Use 0 to use pool defined.');
writeln(FileConfig,'maxshares '+MyMaxShares.ToString);
writeln(FileConfig,'** Enter a valid number between 0-99 as your % volunteer donation for developer.');
writeln(FileConfig,'donate '+MyDonation.ToString);
writeln(FileConfig,'** Enter your password to be identified by the pools. 8-16 Base58 chars length.');
writeln(FileConfig,'password '+MyPassword);
CloseFile(FileConfig);
EXCEPT ON E:EXCEPTION do
begin
end
END {TRY};
End;
Procedure LoadConfig();
var
linea : string;
Begin
TRY
reset(FileConfig);
while not eof(FileConfig) do
begin
readln(FileConfig,linea);
if uppercase(Parameter(linea,0)) = 'ADDRESS' then MyAddress := Parameter(linea,1);
if uppercase(Parameter(linea,0)) = 'CPU' then MyCPUCount := StrToIntDef(Parameter(linea,1),1);
if uppercase(Parameter(linea,0)) = 'HASHLIB' then MyHashLib := StrToIntDef(Parameter(linea,1),70);
if uppercase(Parameter(linea,0)) = 'TEST' then MyRunTest := StrToBoolDef(Parameter(linea,1),false);
if uppercase(Parameter(linea,0)) = 'MAXSHARES' then MyMaxShares := StrToIntDef(Parameter(linea,1),9999);
if MyMaxShares < 1 then MyMaxShares := 9999;
if uppercase(Parameter(linea,0)) = 'DONATE' then MyDonation := StrToIntDef(Parameter(linea,1),5);
if uppercase(Parameter(linea,0)) = 'PASSWORD' then MyPassword := Parameter(linea,1);
end;
CloseFile(FileConfig);
EXCEPT ON E:EXCEPTION do
begin
ToLog('Error accessing data file: '+E.Message);
exit
end
END {TRY};
End;
Function CheckSource():integer;
var
ReachedNodes : integer = 0;
ThisSource : TSourcesData;
PoolString : String ='';
PoolPayStr : string = '';
PoolPayData : TPayment;
SourceNoso : Int64;
Begin
Result := 0;
Repeat
Inc(ActivePool);
if ActivePool>=length(ArrSources) then ActivePool := 0;
until not ArrSources[ActivePool].filled;
ThisSource := ArrSources[ActivePool];
ToLog('Connecting '+ThisSource.ip+' ...');
PoolString := GetPoolSource(ThisSource.ip,ThisSource.port);
if PoolString<> 'ERROR' then // Pool reached
begin
ToLog(ThisSource.ip+': '+PoolString);
result := 1;
MAINPREFIX := Parameter(PoolString,1);
PoolMinningAddress := Parameter(PoolString,2);
TargetHash := Parameter(PoolString,4);
CurrentBlock := StrToIntDef(Parameter(PoolString,5),0);
ThisSource.balance := StrToInt64Def(Parameter(PoolString,6),0);
ThisSource.payinterval := StrToIntDef(Parameter(PoolString,7),0);
PoolPayStr := Parameter(PoolString,8);
PoolPayStr := StringReplace(PoolPayStr,':',' ',[rfReplaceAll, rfIgnoreCase]);
PoolPayData.Pool := ThisSource.ip;
PoolPayData.block := StrToIntDef(Parameter(PoolPayStr,0),0);
PoolPayData.ammount := StrToInt64Def(Parameter(PoolPayStr,1),0);
PoolPayData.OrderID := Parameter(PoolPayStr,2);
if ((PoolPayData.OrderID <> GetPoolLastPay(ThisSource.ip)) and (PoolPayData.ammount>0)) then
begin
AddNewPayment(PoolPayData);
Inc(ReceivedPayments);
Inc(ReceivedNoso,PoolPayData.ammount);
U_NewPayment := PoolPayData.ammount;
end;
ThisSource.miners := StrToIntDef(Parameter(PoolString,13),0);
ThisSource.fee := StrToIntDef(Parameter(PoolString,14),0);
SourceNoso := StrToInt64Def(Parameter(PoolString,15),-1);
ThisSource.MaxShares := StrToIntDef(Parameter(PoolString,16),MyMaxShares);
If SourceNoso>-1 then
Begin
MyAddressBalance := SourceNoso;
U_AddressNosoBalance := true;
end;
U_TotalPEnding := true;
SaveSource(ThisSource);
SetStatusMsg('Synced with pool '+ThisSource.ip,2{green});
end
else
begin
Inc(ArrSources[ActivePool].FailedTrys);
Tolog('Connection error. Check your internet connection');
if ArrSources[ActivePool].FailedTrys >= 5 then
begin
ArrSources[ActivePool].filled:=true;
result := 2;
end
else SetStatusMsg(format('Failed connecting to %s (%d)',[ThisSource.ip,ArrSources[ActivePool].FailedTrys]),4{red});
end;
End;
Procedure CreatePaymentsFile();
Begin
TRY
rewrite(FilePayments);
CloseFile(FilePayments);
EXCEPT ON E:EXCEPTION do
begin
end
END {TRY};
End;
Procedure CreateRAWPaymentsFile();
var
FirstLine : string;
Begin
TRY
rewrite(FileRAWPayments);
FirstLine := (Format(' %-17s | %10s | %12s | %-60s |',['Pool','Block','Amount','OrderID']));
WriteLn(FileRAWPayments,FirstLine);
CloseFile(FileRAWPayments);
EXCEPT ON E:EXCEPTION do
begin
end
END {TRY};
End;
Function GetPoolLastPay(PoolName:String):String;
var
Counter : integer;
ThisData : TPayment;
Begin
Result := '';
TRY
reset(FilePayments);
For counter := Filesize(FilePayments)-1 downto 0 do
begin
Seek(FilePayments,counter);Read(FilePayments,ThisData);
if ThisData.Pool=PoolName then
begin
Result := ThisData.OrderID;
break;
end;
end;
CloseFile(FilePayments);
EXCEPT ON E:EXCEPTION do
begin
end
END {TRY};
End;
Procedure LoadPreviousPayments();
var
Counter : integer;
ThisData : TPayment;
Begin
TRY
reset(FilePayments);
For counter := Filesize(FilePayments)-1 downto 0 do
begin
Seek(FilePayments,counter);Read(FilePayments,ThisData);
Inc(ReceivedPayments);
Inc(ReceivedNoso,ThisData.ammount);
end;
CloseFile(FilePayments);
EXCEPT ON E:EXCEPTION do
begin
end
END {TRY};
End;
Procedure AddNewPayment(LData:Tpayment);
var
RawLine : String;
Begin
TRY
reset(FilePayments);
Seek(FilePayments,FileSize(FilePayments));
Write(FilePayments,Ldata);
CloseFile(FilePayments);
EXCEPT ON E:EXCEPTION do
begin
end
END {TRY};
TRY
Append(FileRAWPayments);
if Length(LData.Pool)>16 then SetLength(Ldata.Pool,16);
RawLine := (Format(' %-17s | %10s | %12s | %-60s |',[LData.pool,IntToStr(LData.block),Int2Curr(LData.ammount),LData.OrderID]));
WriteLn(FileRAWPayments,RawLine);
CloseFile(FileRAWPayments);
EXCEPT ON E:EXCEPTION do
begin
end
END {TRY};
End;
Procedure CreateLogFile();
Begin
TRY
rewrite(FileLog);
CloseFile(FileLog);
EXCEPT ON E:EXCEPTION do
begin
end
END {TRY};
End;
Procedure Tolog(LLine:String);
Begin
EnterCriticalSection(CS_Log);
Insert(LLine,ArrLogLines,Length(ArrLogLines));
LEaveCriticalSection(CS_Log);
End;
Procedure CheckLog();
Begin
EnterCriticalSection(CS_Log);
If length(ArrLogLines) > 0 then
begin
TRY
Append(FileLog);
While Length(ArrLogLines)>0 do
begin
WriteLn(FileLog,ArrLogLines[0]);
Delete(ArrLogLines,0,1);
end;
CloseFile(FileLog);
EXCEPT ON E:EXCEPTION DO
//WriteLn(E.Message);
END; {Try}
end;
LeaveCriticalSection(CS_Log);
End;
Procedure AddSolution(Data:TSolution);
Begin
EnterCriticalSection(CS_Solutions);
Insert(Data,ArrSolutions,length(ArrSolutions));
LeaveCriticalSection(CS_Solutions);
End;
Function SolutionsLength():Integer;
Begin
EnterCriticalSection(CS_Solutions);
Result := length(ArrSolutions);
LeaveCriticalSection(CS_Solutions);
End;
function GetSolution():TSolution;
Begin
result := Default(TSolution);
EnterCriticalSection(CS_Solutions);
if length(ArrSolutions)>0 then
begin
result := ArrSolutions[0];
delete(ArrSolutions,0,1);
end;
LeaveCriticalSection(CS_Solutions);
End;
Procedure ClearSolutions();
Begin
EnterCriticalSection(CS_Solutions);
Setlength(ArrSolutions,0);
LeaveCriticalSection(CS_Solutions);
End;
Procedure AddIntervalHashes(hashes:int64);
Begin
EnterCriticalSection(CS_Interval);
ThreadsIntervalHashes := ThreadsIntervalHashes+hashes;
LeaveCriticalSection(CS_Interval);
End;
function GetTotalHashes : integer;
Begin
EnterCriticalSection(CS_Interval);
Result := ThreadsIntervalHashes;
ThreadsIntervalHashes := 0;
LeaveCriticalSection(CS_Interval);
End;
Procedure ResetIntervalHashes();
Begin
EnterCriticalSection(CS_Interval);
ThreadsIntervalHashes := 0;
LeaveCriticalSection(CS_Interval);
End;
Procedure SetOMT(value:integer);
Begin
EnterCriticalSection(CS_MinerThreads);
OpenMinerThreads := value;
LeaveCriticalSection(CS_MinerThreads);
End;
Procedure DecreaseOMT();
Begin
EnterCriticalSection(CS_MinerThreads);
OpenMinerThreads := OpenMinerThreads-1;
LeaveCriticalSection(CS_MinerThreads);
End;
Function GetOMTValue():Integer;
Begin
EnterCriticalSection(CS_MinerThreads);
Result := OpenMinerThreads;
LeaveCriticalSection(CS_MinerThreads);
End;
INITIALIZATION
Assignfile(FileConfig, 'consominer2.cfg');
Assignfile(FileLog, 'log.txt');
Assignfile(FilePayments, 'payments.dat');
Assignfile(FileRAWPayments, 'payments.txt');
ArrHashLibs[0]:=65;ArrHashLibs[1]:=68;ArrHashLibs[2]:=69;ArrHashLibs[3]:=70;
InitCriticalSection(CS_Log);
InitCriticalSection(CS_ArrSources);
InitCriticalSection(CS_Solutions);
InitCriticalSection(CS_Interval);
InitCriticalSection(CS_MinerThreads);
SetLength(ArrSolutions,0);
SetLength(ArrLogLines,0);
FINALIZATION
DoneCriticalSection(CS_Log);
DoneCriticalSection(CS_ArrSources);
DoneCriticalSection(CS_Solutions);
DoneCriticalSection(CS_Interval);
DoneCriticalSection(CS_MinerThreads);
END. // END UNIT