This repository has been archived by the owner on Sep 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
mpparser.pas
1989 lines (1867 loc) · 67.4 KB
/
mpparser.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
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit mpParser;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, MasterPaskalForm, mpGUI, mpRed, mpDisk, nosotime, mpblock, mpcoin,
dialogs, fileutil, forms, idglobal, strutils, mpRPC, DateUtils, Clipbrd,translation,
idContext, math, MPSysCheck, nosodebug, nosogeneral, nosocrypto, nosounit,
nosoconsensus, nosopsos,nosowallcon, nosoheaders, nosoblock, nosonosocfg,nosonetwork,
nosogvts,nosomasternodes;
procedure ProcessLinesAdd(const ALine: String);
procedure OutgoingMsjsAdd(const ALine: String);
function OutgoingMsjsGet(): String;
Procedure ProcesarLineas();
function GetOpData(textLine:string):String;
Procedure ParseCommandLine(LineText:string);
procedure NuevaDireccion(linetext:string);
Procedure ShowNodes();
Procedure ShowBots();
Procedure ShowUser_Options();
function GetWalletBalance(): Int64;
Procedure ConnectTo(LineText:string);
Procedure AutoServerON();
Procedure AutoServerOFF();
Procedure ShowWallet();
Procedure ImportarWallet(LineText:string);
Procedure ExportarWallet(LineText:string);
Procedure ShowBlchHead(number:integer);
Function SetDefaultAddress(linetext:string):boolean;
Procedure ParseShowBlockInfo(LineText:string);
Procedure ShowBlockInfo(numberblock:integer);
Procedure CustomizeAddress(linetext:string);
Procedure Parse_SendFunds(LineText:string);
function SendFunds(LineText:string;showOutput:boolean=true):string;
Procedure Parse_SendGVT(LineText:string);
Function SendGVT(LineText:string;showOutput:boolean=true):string;
Procedure ShowHalvings();
Procedure SetServerPort(LineText:string);
Procedure TestParser(LineText:String);
//Procedure DeleteBots(LineText:String);
Procedure Parse_RestartNoso();
Procedure GetOwnerHash(LineText:string);
Procedure CheckOwnerHash(LineText:string);
function AvailableUpdates():string;
Procedure RunUpdate(linea:string);
Procedure RunGetBeta(linea:string);
Procedure SendAdminMessage(linetext:string);
//Procedure RequestSumary();
Procedure ShowOrderDetails(LineText:string);
Procedure ExportAddress(LineText:string);
Procedure ShowAddressInfo(LineText:string);
Procedure ShowAddressHistory(LineText:string);
Procedure ShowTotalFees();
function ShowPrivKey(linea:String;ToConsole:boolean = false):String;
Procedure TestNetwork(LineText:string);
Procedure ShowPendingTrxs();
Procedure WebWallet();
Procedure ExportKeys(linea:string);
Procedure NewAddressFromKeys(inputline:string);
Procedure TestHashGeneration(inputline:string);
Procedure CompareHashes(inputline:string);
Procedure CreateMultiAddress(Inputline:String);
// CONSULTING
Procedure ListGVTs();
// 0.2.1 DEBUG
Procedure ShowBlockPos(LineText:string);
Procedure ShowBlockMNs(LineText:string);
Procedure showgmts(LineText:string);
Procedure ShowSystemInfo(Linetext:string);
Procedure ShowMNsChecks();
// EXCHANGE
Procedure PostOffer(LineText:String);
Procedure DebugTest2(linetext:string);
Procedure OrdInfo(linetext:string);
Procedure totallocked();
Procedure ShowSumary();
// CONSENSUS
Procedure ShowConsensus();
Procedure ShowConsensusStats();
// PSOs testing functions
Procedure TestNewPSO(Dataline:String);
Procedure GetPSOs();
Procedure ShowGVTInfo();
Procedure ClearPSOs();
Procedure ShowMNsLocked();
// Specific Tests
Procedure Test_Headers();
implementation
uses
mpProtocol;
// **************************
// *** CRITICIAL SECTIONS ***
// **************************
// Adds a line to ProcessLines thread safe
Procedure ProcessLinesAdd(const ALine: String);
Begin
EnterCriticalSection(CSProcessLines);
TRY
ProcessLines.Add(ALine);
EXCEPT ON E:Exception do
ToLog('exceps',FormatDateTime('dd mm YYYY HH:MM:SS.zzz', Now)+' -> '+'Error on PROCESSLINESADD: '+E.Message);
END; {TRY}
LeaveCriticalSection(CSProcessLines);
End;
// Adds a line to OutgoingMsjs thread safe
procedure OutgoingMsjsAdd(const ALine: String);
Begin
EnterCriticalSection(CSOutgoingMsjs);
TRY
OutgoingMsjs.Add(ALine);
EXCEPT ON E:Exception do
ToLog('exceps',FormatDateTime('dd mm YYYY HH:MM:SS.zzz', Now)+' -> '+'Error on OutgoingMsjsAdd: '+E.Message);
END{Try};
LeaveCriticalSection(CSOutgoingMsjs);
End;
// Gets a line from OutgoingMsjs thread safe
function OutgoingMsjsGet(): String;
var
Linea : String;
Begin
Linea := '';
EnterCriticalSection(CSOutgoingMsjs);
TRY
Linea := OutgoingMsjs[0];
OutgoingMsjs.Delete(0);
EXCEPT ON E:Exception do
ToLog('exceps',FormatDateTime('dd mm YYYY HH:MM:SS.zzz', Now)+' -> '+'Error extracting outgoing line: '+E.Message);
END{Try};
LeaveCriticalSection(CSOutgoingMsjs);
result := linea;
End;
// Procesa las lineas de la linea de comandos
Procedure ProcesarLineas();
Begin
While ProcessLines.Count > 0 do
begin
ParseCommandLine(ProcessLines[0]);
if ProcessLines.Count>0 then
begin
EnterCriticalSection(CSProcessLines);
try
ProcessLines.Delete(0);
Except on E:Exception do
begin
ShowMessage ('Your wallet just exploded and we will close it for your security'+slinebreak+
'Error deleting line 0 from ProcessLines');
halt(0);
end;
end;
LeaveCriticalSection(CSProcessLines);
end;
end;
End;
// Elimina el encabezado de una linea de protocolo
function GetOpData(textLine:string):String;
var
CharPos : integer;
Begin
charpos := pos('$',textline);
result := copy(textline,charpos,length(textline));
End;
Procedure ParseCommandLine(LineText:string);
var
Command : String;
Counter : integer;
LItem : TSummaryData;
begin
Command :=Parameter(Linetext,0);
if not AnsiContainsStr(HideCommands,Uppercase(command)) then ToLog('Console','>> '+Linetext);
if UpperCase(Command) = 'VER' then ToLog('console',MainnetVersion+NodeRelease)
else if UpperCase(Command) = 'SERVERON' then StartServer()
else if UpperCase(Command) = 'SERVEROFF' then StopServer()
else if UpperCase(Command) = 'FORCESERVER' then ForceServer()
else if UpperCase(Command) = 'NODES' then ShowNodes()
else if UpperCase(Command) = 'BOTS' then ShowBots()
{else if UpperCase(Command) = 'CONNECT' then ConnectToServers()}
else if UpperCase(Command) = 'DISCONNECT' then CerrarClientes()
else if UpperCase(Command) = 'OFFSET' then ToLog('console','Server: '+NosoT_LastServer+SLINEBREAK+
'Time offset seconds: '+IntToStr(NosoT_TimeOffset)+slinebreak+'Last update : '+TimeSinceStamp(NosoT_LastUpdate))
else if UpperCase(Command) = 'NEWADDRESS' then NuevaDireccion(linetext)
else if UpperCase(Command) = 'USEROPTIONS' then ShowUser_Options()
else if UpperCase(Command) = 'BALANCE' then ToLog('console',Int2Curr(GetWalletBalance)+' '+CoinSimbol)
else if UpperCase(Command) = 'CONNECTTO' then ConnectTo(Linetext)
else if UpperCase(Command) = 'AUTOSERVERON' then AutoServerON()
else if UpperCase(Command) = 'AUTOSERVEROFF' then AutoServerOFF()
else if UpperCase(Command) = 'SHOWWALLET' then ShowWallet()
else if UpperCase(Command) = 'IMPWALLET' then ImportarWallet(LineText)
else if UpperCase(Command) = 'EXPWALLET' then ExportarWallet(LineText)
else if UpperCase(Command) = 'RESUMEN' then ShowBlchHead(StrToIntDef(Parameter(Linetext,1),MyLastBlock))
else if UpperCase(Command) = 'SETDEFAULT' then SetDefaultAddress(LineText)
else if UpperCase(Command) = 'LBINFO' then ShowBlockInfo(MyLastBlock)
else if UpperCase(Command) = 'TIMESTAMP' then ToLog('console',UTCTimeStr)
else if UpperCase(Command) = 'UNDOBLOCK' then UndoneLastBlock() // to be removed
else if UpperCase(Command) = 'CUSTOMIZE' then CustomizeAddress(LineText)
else if UpperCase(Command) = 'SENDTO' then Parse_SendFunds(LineText)
else if UpperCase(Command) = 'SENDGVT' then Parse_SendGVT(LineText)
else if UpperCase(Command) = 'HALVING' then ShowHalvings()
else if UpperCase(Command) = 'SETPORT' then SetServerPort(LineText)
else if UpperCase(Command) = 'SHA256' then ToLog('console',HashSha256String(Parameter(LineText,1)))
else if UpperCase(Command) = 'MD5' then ToLog('console',HashMD5String(Parameter(LineText,1)))
else if UpperCase(Command) = 'MD160' then ToLog('console',HashMD160String(Parameter(LineText,1)))
else if UpperCase(Command) = 'CLEAR' then form1.Memoconsola.Lines.clear
else if UpperCase(Command) = 'TP' then TestParser(LineText)
else if UpperCase(Command) = 'BLOCK' then ParseShowBlockInfo(LineText)
else if UpperCase(Command) = 'TESTNET' then TestNetwork(LineText)
else if UpperCase(Command) = 'RESTART' then Parse_RestartNoso()
else if UpperCase(Command) = 'OSVERSION' then ToLog('console',OsVersion)
else if UpperCase(Command) = 'DIRECTIVE' then SendAdminMessage(linetext)
else if UpperCase(Command) = 'MYHASH' then ToLog('console',HashMD5File('noso.exe'))
else if UpperCase(Command) = 'STATUS' then ToLog('console',GetCurrentStatus(1))
else if UpperCase(Command) = 'GETCERT' then GetOwnerHash(LineText)
else if UpperCase(Command) = 'CHECKCERT' then CheckOwnerHash(LineText)
else if UpperCase(Command) = 'UPDATE' then RunUpdate(LineText)
else if UpperCase(Command) = 'GETBETA' then RunGetBeta(LineText)
else if UpperCase(Command) = 'RESTOREBLOCKCHAIN' then RestoreBlockChain()
else if UpperCase(Command) = 'RESTORESUMARY' then RestoreSumary(StrToIntDef(Parameter(LineText,1),0))
//else if UpperCase(Command) = 'REQSUM' then RequestSumary()
else if UpperCase(Command) = 'SAVEADV' then CreateADV(true)
else if UpperCase(Command) = 'ORDER' then ShowOrderDetails(LineText)
else if UpperCase(Command) = 'ORDERSOURCES' then ToLog('console',GetOrderSources(Parameter(LineText,1)))
else if UpperCase(Command) = 'EXPORTADDRESS' then ExportAddress(LineText)
else if UpperCase(Command) = 'ADDRESS' then ShowAddressInfo(LineText)
else if UpperCase(Command) = 'HISTORY' then ShowAddressHistory(LineText)
else if UpperCase(Command) = 'TOTALFEES' then ShowTotalFees()
else if UpperCase(Command) = 'SUPPLY' then ToLog('console','Current supply: '+Int2Curr(GetSupply(MyLastBlock)))
else if UpperCase(Command) = 'GMTS' then showgmts(LineText)
else if UpperCase(Command) = 'SHOWKEYS' then ShowPrivKey(LineText, true)
else if UpperCase(Command) = 'SHOWPENDING' then ShowPendingTrxs()
else if UpperCase(Command) = 'WEBWAL' then WebWallet()
else if UpperCase(Command) = 'EXPKEYS' then ExportKeys(LineText)
else if UpperCase(Command) = 'CHECKUPDATES' then ToLog('console',GetLastRelease)
else if UpperCase(Command) = 'ZIPSUMARY' then ZipSumary()
else if UpperCase(Command) = 'GETPOS' then ToLog('console', GetPoSPercentage(StrToIntdef(Parameter(linetext,1),Mylastblock)).ToString )
else if UpperCase(Command) = 'GETMNS' then ToLog('console', GetMNsPercentage(StrToIntdef(Parameter(linetext,1),Mylastblock),GetCFGDataStr(0)).ToString )
else if UpperCase(Command) = 'CLOSESTARTON' then WO_CloseStart := true
else if UpperCase(Command) = 'CLOSESTARTOFF' then WO_CloseStart := false
else if UpperCase(Command) = 'TT' then DebugTest2(LineText)
else if UpperCase(Command) = 'BASE58SUM' then ToLog('console',BMB58resumen(parameter(linetext,1)))
else if UpperCase(Command) = 'PENDING' then ToLog('console',PendingRawInfo)
else if UpperCase(Command) = 'HEADSIZE' then ToLog('console',GetHeadersHeigth.ToString)
else if UpperCase(Command) = 'NEWFROMKEYS' then NewAddressFromKeys(LineText)
else if UpperCase(Command) = 'TESTHASH' then TestHashGeneration(LineText)
else if UpperCase(Command) = 'COMPARE' then CompareHashes(LineText)
else if UpperCase(Command) = 'GETREPOSEEDS' then ToLog('console',SendApiRequest('https://raw.githubusercontent.com/Noso-Project/NosoWallet/main/defseeds.nos'))
else if UpperCase(Command) = 'FORCEREPOSEEDS' then
begin
SetCFGData(SendApiRequest('https://raw.githubusercontent.com/Noso-Project/NosoWallet/main/defseeds.nos'),1);
end
else if UpperCase(Command) = 'SENDREPORT' then SEndFileViaTCP(ResumeLogFilename,'REPORT','debuglogs.nosocoin.com:18081',18081)
else if UpperCase(Command) = 'GETDBLB' then ToLog('console',GetDBLastBlock.ToString)
else if UpperCase(Command) = 'ORDINFO' then OrdInfo(LineText)
else if UpperCase(Command) = 'GETMULTI' then CreateMultiAddress(LineText)
else if UpperCase(Command) = 'DELBOTS' then DeleteBots
// New system
else if UpperCase(Command) = 'SUMARY' then ShowSumary()
else if UpperCase(Command) = 'REBUILDSUM' then RebuildSummary()
// CONSULTING
else if UpperCase(Command) = 'LISTGVT' then ListGVTs()
else if UpperCase(Command) = 'GVTINFO' then ShowGVTInfo()
else if UpperCase(Command) = 'SYSTEM' then ShowSystemInfo(Linetext)
else if UpperCase(Command) = 'NOSOCFG' then ToLog('console',GetCFGDataStr)
else if UpperCase(Command) = 'FUNDS' then ToLog('console','Project funds '+lineEnding+
'NpryectdevepmentfundsGE: '+Int2curr(GetAddressAvailable('NpryectdevepmentfundsGE'))+lineEnding+
'NPrjectPrtcRandmJacptE5: '+Int2curr(GetAddressAvailable('NPrjectPrtcRandmJacptE5')))
else if UpperCase(Command) = 'SUMINDEXSIZE' then ToLog('console',IntToStr(SumIndexLength))
else if UpperCase(Command) = 'MNSCHECKS' then ShowMNsChecks()
else if UpperCase(Command) = 'TESTHEAD' then Test_Headers()
// 0.2.1 DEBUG
else if UpperCase(Command) = 'BLOCKPOS' then ShowBlockPos(LineText)
else if UpperCase(Command) = 'BLOCKMNS' then ShowBlockMNs(LineText)
else if UpperCase(Command) = 'MYIP' then ToLog('console',GetMiIP)
else if UpperCase(Command) = 'SETMODE' then SetCFGData(parameter(linetext,1),0)
else if UpperCase(Command) = 'ADDNODE' then AddCFGData(parameter(linetext,1),1)
else if UpperCase(Command) = 'DELNODE' then RemoveCFGData(parameter(linetext,1),1)
else if UpperCase(Command) = 'ADDPOOL' then AddCFGData(parameter(linetext,1),3)
else if UpperCase(Command) = 'DELPOOL' then RemoveCFGData(parameter(linetext,1),3)
else if UpperCase(Command) = 'RESTORECFG' then RestoreCFGData()
else if UpperCase(Command) = 'ADDNOSOPAY' then AddCFGData(parameter(linetext,1),6)
else if UpperCase(Command) = 'DELNOSOPAY' then RemoveCFGData(parameter(linetext,1),6)
else if UpperCase(Command) = 'ISALLSYNCED' then ToLog('console',IsAllsynced.ToString)
else if UpperCase(Command) = 'FREEZED' then Totallocked()
else if UpperCase(Command) = 'CLEARCFG' then ClearCFGData(parameter(linetext,1))
else if UpperCase(Command) = 'ADDFROMPUB' then ToLog('console',GetAddressFromPublicKey(parameter(linetext,1)))
// 0.4.0
else if UpperCase(Command) = 'CONSENSUS' then ShowConsensus()
else if UpperCase(Command) = 'VALIDATE' then ToLog('console',BoolToStr(VerifyAddressOnDisk(parameter(linetext,1)),true))
// P2P
else if UpperCase(Command) = 'PEERS' then ToLog('console','Server list: '+IntToStr(form1.ClientsCount)+'/'+IntToStr(GetIncomingConnections))
// RPC
else if UpperCase(Command) = 'SETRPCPORT' then SetRPCPort(LineText)
else if UpperCase(Command) = 'RPCON' then SetRPCOn()
else if UpperCase(Command) = 'RPCOFF' then SetRPCOff()
// PSO
else if UpperCase(Command) = 'NEWPSO' then TestNewPSO(parameter(linetext,1))
else if UpperCase(Command) = 'LISTPSOS' then GetPSOs()
else if UpperCase(Command) = 'CLEARPSOS' then CLEARPSOS()
else if UpperCase(Command) = 'SHOWPSOS' then ShowMNsLocked()
else if UpperCase(Command) = 'CONSTATS' then ShowConsensusStats()
//EXCHANGE
else if UpperCase(Command) = 'POST' then PostOffer(LineText)
else ToLog('console','Unknown command: '+Command); // Unknow command
end;
// Add a new address generation to the crypto thread
procedure NuevaDireccion(linetext:string);
var
cantidad : integer;
cont : integer;
Begin
AddCRiptoOp(1,'','');
sleep(1);
End;
// muestra los nodos
Procedure ShowNodes();
var
contador : integer = 0;
Begin
for contador := 0 to NodesListLen - 1 do
ToLog('console',IntToStr(contador)+'- '+NodesIndex(contador).ip+':'+NodesIndex(contador).port);
End;
// muestra los Bots
Procedure ShowBots();
var
contador : integer = 0;
Begin
for contador := 0 to length(BotsList) - 1 do
ToLog('console',IntToStr(contador)+'- '+BotsList[contador].ip);
ToLog('console',IntToStr(length(BotsList))+' bots registered.'); // bots registered
End;
// Muestras las opciones del usuario
Procedure ShowUser_Options();
Begin
ToLog('console','Language : '+WO_Language);
ToLog('console','Server Port : '+LocalMN_Port);
ToLog('console','Wallet : '+WalletFilename);
ToLog('console','AutoServer : '+BoolToStr(WO_AutoServer,true));
End;
// Returns the total balance on the wallet
function GetWalletBalance(): Int64;
var
counter : integer = 0;
Total : Int64 = 0;
Begin
for counter := 0 to LenWallArr-1 do
begin
Total := Total+GetAddressBalanceIndexed(GetWallArrIndex(counter).Hash);
end;
result := Total-MontoOutgoing;
End;
// Conecta a un server especificado
Procedure ConnectTo(LineText:string);
var
Ip, Port : String;
Begin
Ip := Parameter(Linetext, 1);
Port := Parameter(Linetext, 2);
if StrToIntDef(Port,-1) = -1 then Port := '8080';
ConnectClient(ip,port);
End;
Procedure AutoServerON();
Begin
WO_autoserver := true;
S_AdvOpt := true;
ToLog('console','AutoServer option is now '+'ACTIVE'); //autoserver //active
End;
Procedure AutoServerOFF();
Begin
WO_autoserver := false;
S_AdvOpt := true;
ToLog('console','AutoServer option is now '+'INACTIVE'); //autoserver //inactive
End;
// Shows all the addresses on the wallet
Procedure ShowWallet();
var
contador : integer = 0;
Begin
for contador := 0 to LenWallArr-1 do
begin
ToLog('console',GetWallArrIndex(contador).Hash);
end;
ToLog('console',IntToStr(LenWallArr)+' addresses.');
ToLog('console',Int2Curr(GetWalletBalance)+' '+CoinSimbol);
End;
Procedure ExportarWallet(LineText:string);
var
destino : string = '';
Begin
destino := Parameter(linetext,1);
destino := StringReplace(destino,'*',' ',[rfReplaceAll, rfIgnoreCase]);
if fileexists(destino+'.pkw') then
begin
ToLog('console','Error: Can not overwrite existing wallets');
exit;
end;
if copyfile(WalletFilename,destino+'.pkw',[]) then
begin
ToLog('console','Wallet saved as '+destino+'.pkw');
end
else
begin
ToLog('console','Failed');
end;
End;
Procedure ImportarWallet(LineText:string);
var
Cartera : string = '';
CarteraFile : file of WalletData;
DatoLeido : Walletdata;
Contador : integer = 0;
Nuevos: integer = 0;
Begin
Cartera := Parameter(linetext,1);
Cartera := StringReplace(Cartera,'*',' ',[rfReplaceAll, rfIgnoreCase]);
if not FileExists(cartera) then
begin
ToLog('console','Specified wallet file do not exists.');//Specified wallet file do not exists.
exit;
end;
assignfile(CarteraFile,Cartera);
try
reset(CarteraFile);
seek(CarteraFile,0);
Read(CarteraFile,DatoLeido);
if not IsValidHashAddress(DatoLeido.Hash) then
begin
closefile(CarteraFile);
ToLog('console','The file is not a valid wallet');
exit;
end;
for contador := 0 to filesize(CarteraFile)-1 do
begin
seek(CarteraFile,contador);
Read(CarteraFile,DatoLeido);
if ((WallAddIndex(DatoLeido.Hash) < 0) and (IsValidHashAddress(DatoLeido.Hash))) then
begin
InsertToWallArr(DatoLeido);
Nuevos := nuevos+1;
end;
end;
closefile(CarteraFile);
except on E:Exception do
ToLog('console','The file is not a valid wallet'); //'The file is not a valid wallet'
end;
if nuevos > 0 then
begin
OutText('Addresses imported: '+IntToStr(nuevos),false,2); //'Addresses imported: '
UpdateWalletFromSumario;
end
else ToLog('console','No new addreses found.'); //'No new addreses found.'
End;
Procedure ShowBlchHead(number:integer);
var
Dato: ResumenData;
Found : boolean = false;
StartBlock : integer = 0;
counter : integer = 100000;
Errors : integer = 0;
ProperlyClosed : boolean = false;
Begin
StartBlock := number - 10;
If StartBlock < 0 then StartBlock := 0;
TRY
assignfile(FileResumen,ResumenFilename);
reset(FileResumen);
REPEAT
Seek(FileResumen,StartBlock);
read(fileresumen, dato);
ToLog('console',IntToStr(dato.block)+' '+copy(dato.blockhash,1,5)+' '+copy(dato.SumHash,1,5));
if dato.blockhash='MISS' then Inc(Errors);
if dato.sumhash='MISS' then Inc(Errors);
Inc(StartBlock);
UNTIL eof(fileresumen);
closefile(FileResumen);
ProperlyClosed := true;
ToLog('Console','Errors : '+Errors.ToString);
EXCEPT ON E:Exception do
ToLog('console','Error: '+E.Message)
END;{TRY}
If not ProperlyClosed then closefile(FileResumen);
End;
// Cambiar la primera direccion de la wallet
Function SetDefaultAddress(linetext:string):boolean;
var
Address : string;
Index : integer;
OldData, NewData: walletData;
Begin
result := false;
Address := Parameter(linetext,1);
index := WallAddIndex(Address);
if ((index < 0) or (index > LenWallArr-1)) then
OutText('Invalid address.',false,2) //'Invalid address number.'
else if index = 0 then
OutText('Address is already the default.',false,2) //'Address 0 is already the default.'
else
begin
if ChangeWallArrPos(0,index) then
begin
S_Wallet := true;
U_DirPanel := true;
result := true;
end;
end;
End;
Procedure ParseShowBlockInfo(LineText:string);
var
blnumber : integer;
Begin
blnumber := StrToIntDef(Parameter(linetext,1),-1);
if (blnumber < 0) or (blnumber>MylastBlock) then
outtext('Invalid block number')
else ShowBlockInfo(blnumber);
End;
Procedure ShowBlockInfo(numberblock:integer);
var
Header : BlockHeaderData;
LOrders : TBlockOrdersArray;
LPOSes : BlockArraysPos;
PosReward : int64;
PosCount : integer;
Counter : integer;
Begin
if fileexists(BlockDirectory+IntToStr(numberblock)+'.blk') then
begin
Header := LoadBlockDataHeader(numberblock);
ToLog('console','Block info: '+IntToStr(numberblock));
ToLog('console','Hash : '+HashMD5File(BlockDirectory+IntToStr(numberblock)+'.blk'));
ToLog('console','Number: '+IntToStr(Header.Number));
ToLog('console','Time start: '+IntToStr(Header.TimeStart)+' ('+TimestampToDate(Header.TimeStart)+')');
ToLog('console','Time end: '+IntToStr(Header.TimeEnd)+' ('+TimestampToDate(Header.TimeEnd)+')');
ToLog('console','Time total: '+IntToStr(Header.TimeTotal));
ToLog('console','L20 average: '+IntToStr(Header.TimeLast20));
ToLog('console','Transactions: '+IntToStr(Header.TrxTotales));
ToLog('console','Difficult: '+IntToStr(Header.Difficult));
ToLog('console','Target: '+Header.TargetHash);
ToLog('console','Solution: '+Header.Solution);
ToLog('console','Last Hash: '+Header.LastBlockHash);
ToLog('console','Next Diff: '+IntToStr(Header.NxtBlkDiff));
ToLog('console','Miner: '+Header.AccountMiner);
ToLog('console','Fees: '+IntToStr(Header.MinerFee));
ToLog('console','Reward: '+IntToStr(Header.Reward));
LOrders := GetBlockTrxs(numberblock);
if length(LOrders)>0 then
begin
ToLog('console','TRANSACTIONS');
For Counter := 0 to length(LOrders)-1 do
begin
ToLog('console',Format('%-8s %-35s -> %-35s : %s',[LOrders[counter].OrderType,LOrders[counter].sender,LOrders[counter].Receiver,int2curr(LOrders[counter].AmmountTrf)]));
end;
end;
if numberblock>PoSBlockStart then
begin
LPoSes := GetBlockPoSes(numberblock);
PosReward := StrToInt64Def(LPoSes[length(LPoSes)-1].address,0);
SetLength(LPoSes,length(LPoSes)-1);
PosCount := length(LPoSes);
ToLog('console',Format('PoS Reward: %s / Addresses: %d / Total: %s',[int2curr(PosReward),PosCount,int2curr(PosReward*PosCount)]));
end;
if numberblock>MNBlockStart then
begin
LPoSes := GetBlockMNs(numberblock);
PosReward := StrToInt64Def(LPoSes[length(LPoSes)-1].address,0);
SetLength(LPoSes,length(LPoSes)-1);
PosCount := length(LPoSes);
ToLog('console',Format('MNs Reward: %s / Addresses: %d / Total: %s',[int2curr(PosReward),PosCount,int2curr(PosReward*PosCount)]));
end;
end
else
ToLog('console','Block file do not exists: '+numberblock.ToString);
End;
Procedure CustomizeAddress(linetext:string);
var
address, AddAlias, TrfrHash, OrderHash, CurrTime : String;
cont : integer;
procesar : boolean = true;
Begin
address := Parameter(linetext,1);
AddAlias := Parameter(linetext,2);
if WallAddIndex(address)<0 then
begin
ToLog('console','Invalid address'); //'Invalid address'
procesar := false;
end;
if GetWallArrIndex(WallAddIndex(address)).Custom <> '' then
begin
ToLog('console','Address already have a custom alias'); //'Address already have a custom alias'
procesar := false;
end;
if ( (length(AddAlias)<5) or (length(AddAlias)>40) ) then
begin
OutText('Alias must have between 5 and 40 chars',false,2); //'Alias must have between 5 and 40 chars'
procesar := false;
end;
if IsValidHashAddress(addalias) then
begin
ToLog('console','Alias can not be a valid address'); //'Alias can not be a valid address'
procesar := false;
end;
if GetWallArrIndex(WallAddIndex(address)).Balance < GetCustFee(MyLastBlock) then
begin
ToLog('console','Insufficient balance'); //'Insufficient balance'
procesar := false;
end;
if AddressAlreadyCustomized(Address) then
begin
ToLog('console','Address already have a custom alias'); //'Address already have a custom alias'
procesar := false;
end;
if AliasAlreadyExists(addalias) then
begin
ToLog('console','Alias already exists');
procesar := false;
end;
for cont := 1 to length(addalias) do
begin
if pos(addalias[cont],CustomValid)=0 then
begin
ToLog('console','Invalid character in alias: '+addalias[cont]);
info('Invalid character in alias: '+addalias[cont]);
procesar := false;
end;
end;
if procesar then
begin
CurrTime := UTCTimeStr;
TrfrHash := GetTransferHash(CurrTime+Address+addalias);
OrderHash := GetOrderHash('1'+currtime+TrfrHash);
AddCriptoOp(2,'Customize this '+address+' '+addalias+'$'+GetWallArrIndex(WallAddIndex(address)).PrivateKey,
ProtocolLine(9)+ // CUSTOM
OrderHash+' '+ // OrderID
'1'+' '+ // OrderLines
'CUSTOM'+' '+ // OrderType
CurrTime+' '+ // Timestamp
'null'+' '+ // reference
'1'+' '+ // Trxline
GetWallArrIndex(WallAddIndex(address)).PublicKey+' '+ // sender
GetWallArrIndex(WallAddIndex(address)).Hash+' '+ // address
AddAlias+' '+ // receiver
IntToStr(GetCustFee(MyLastBlock))+' '+ // Amountfee
'0'+' '+ // amount trfr
'[[RESULT]] '+
TrfrHash); // trfrhash
end;
End;
// Incluye una solicitud de envio de fondos a la cola de transacciones cripto
Procedure Parse_SendFunds(LineText:string);
Begin
AddCriptoOp(3,linetext,'');
End;
// Ejecuta una orden de transferencia
function SendFunds(LineText:string;showOutput:boolean=true):string;
var
Destination, amount, reference : string;
monto, comision : int64;
montoToShow, comisionToShow : int64;
contador : integer;
Restante : int64;
ArrayTrfrs : Array of Torderdata;
currtime : string;
TrxLinea : integer = 0;
OrderHashString : String;
OrderString : string;
AliasIndex : integer;
Procesar : boolean = true;
ResultOrderID : String = '';
CoinsAvailable : int64;
DestinationRecord : TSummaryData;
SendersString : string = '';
Begin
result := '';
BeginPerformance('SendFunds');
Destination := Parameter(Linetext,1);
amount := Parameter(Linetext,2);
reference := Parameter(Linetext,3);
if ((Destination='') or (amount='')) then
begin
if showOutput then ToLog('console','Invalid parameters.'); //'Invalid parameters.'
Procesar := false;
end;
if not IsValidHashAddress(Destination) then
begin
AliasIndex:=GetIndexPosition(Destination,DestinationRecord,true);
if AliasIndex<0 then
begin
if showOutput then ToLog('console','Invalid destination.'); //'Invalid destination.'
Procesar := false;
end
else Destination := DestinationRecord.Hash;
end;
monto := StrToInt64Def(amount,-1);
if reference = '' then reference := 'null';
if monto<=10 then
begin
if showOutput then ToLog('console','Invalid ammount.'); //'Invalid ammount.'
Procesar := false;
end;
if procesar then
begin
Comision := GetMinimumFee(Monto);
montoToShow := Monto;
comisionToShow := Comision;
Restante := monto+comision;
if WO_Multisend then CoinsAvailable := GetAddressBalanceIndexed(GetWallArrIndex(0).Hash)-GetAddressPendingPays(GetWallArrIndex(0).Hash)
else CoinsAvailable := GetWalletBalance;
if Restante > CoinsAvailable then
begin
if showOutput then ToLog('console','Insufficient funds. Needed: '+Int2curr(Monto+comision));//'Insufficient funds. Needed: '
Procesar := false;
end;
end;
// empezar proceso
if procesar then
begin
currtime := UTCTimeStr;
Setlength(ArrayTrfrs,0);
Contador := form1.DireccionesPAnel.Row-1;
OrderHashString := currtime;
while monto > 0 do
begin
BeginPerformance('SendFundsVerify');
if AnsiContainsstr(SendersString,GetWallArrIndex(contador).Hash) then
begin
ToLog('console','Duplicated address on order');
Exit;
end;
SendersString := SendersString+GetWallArrIndex(contador).Hash;
if GetAddressBalanceIndexed(GetWallArrIndex(contador).Hash)-GetAddressPendingPays(GetWallArrIndex(contador).Hash) > 0 then
begin
trxLinea := TrxLinea+1;
Setlength(ArrayTrfrs,length(arraytrfrs)+1);
ArrayTrfrs[length(arraytrfrs)-1]:= SendFundsFromAddress(GetWallArrIndex(contador).Hash,
Destination,monto, comision, reference, CurrTime,TrxLinea);
comision := comision-ArrayTrfrs[length(arraytrfrs)-1].AmmountFee;
monto := monto-ArrayTrfrs[length(arraytrfrs)-1].AmmountTrf;
OrderHashString := OrderHashString+ArrayTrfrs[length(arraytrfrs)-1].TrfrID;
end;
Inc(contador);
if contador>=LenWallArr then contador := 0;
EndPerformance('SendFundsVerify');
end;
for contador := 0 to length(ArrayTrfrs)-1 do
begin
ArrayTrfrs[contador].OrderID:=GetOrderHash(IntToStr(trxLinea)+OrderHashString);
ArrayTrfrs[contador].OrderLines:=trxLinea;
end;
ResultOrderID := GetOrderHash(IntToStr(trxLinea)+OrderHashString);
if showOutput then ToLog('console','Send to: '+Destination+slinebreak+
'Send '+Int2Curr(montoToShow)+' fee '+Int2Curr(comisionToShow)+slinebreak+
'Order ID: '+ResultOrderID);
result := ResultOrderID;
OrderString := GetPTCEcn+'ORDER '+IntToStr(trxLinea)+' $';
for contador := 0 to length(ArrayTrfrs)-1 do
begin
OrderString := orderstring+GetStringfromOrder(ArrayTrfrs[contador])+' $';
end;
Setlength(orderstring,length(orderstring)-2);
OrderString := StringReplace(OrderString,'PSK','NSLORDER',[]);
ToLog('console','Send to Node '+OrderString);
result := SendOrderToNode(OrderString);
//ToLog('console','Node result: '+result);
OutgoingMsjsAdd(OrderString);
EndPerformance('SendFunds');
end // End procesar
else
begin
if showOutput then ToLog('console','Syntax: sendto {destination} {ammount} {reference}');
end;
End;
// Process a GVT sending
Procedure Parse_SendGVT(LineText:string);
Begin
AddCriptoOp(6,linetext,'');
End;
Function SendGVT(LineText:string;showOutput:boolean=true):string;
var
GVTNumber : integer;
GVTOwner : string;
Destination : string = '';
AliasIndex : integer;
Procesar : boolean = true;
OrderTime : string = '';
TrfrHash : string = '';
OrderHash : string = '';
ResultStr : string = '';
Signature : string = '';
GVTNumStr : string = '';
StrTosign : String = '';
DestinationRecord : TSummaryData;
Begin
result := '';
BeginPerformance('SendGVT');
GVTNumber:= StrToIntDef(Parameter(Linetext,1),-1);
Destination := Parameter(Linetext,2);
if ( (GVTnumber<0) or (GVTnumber>length(ArrGVTs)-1) ) then
begin
if showOutput then ToLog('console','Invalid GVT number');
exit;
end;
GVTNumStr := ArrGVTs[GVTnumber].number;
GVTOwner := ArrGVTs[GVTnumber].owner;
If WallAddIndex(GVTOwner)<0 then
begin
if showOutput then ToLog('console','You do not own that GVT');
exit;
end;
if GetAddressAvailable(GVTOwner)<GetCustFee(MyLastBlock) then
begin
if showOutput then ToLog('console','Inssuficient funds');
exit;
end;
if not IsValidHashAddress(Destination) then
begin
AliasIndex:=GetIndexPosition(Destination,DestinationRecord,true);
if AliasIndex<0 then
begin
if showOutput then ToLog('console','Invalid destination.'); //'Invalid destination.'
Exit;
end
else Destination := DestinationRecord.Hash;
end;
if GVTOwner=Destination then
begin
if showOutput then ToLog('console','Can not transfer GVT to same address');
exit;
end;
OrderTime := UTCTimeStr;
TrfrHash := GetTransferHash(OrderTime+GVTOwner+Destination);
OrderHash := GetOrderHash('1'+OrderTime+TrfrHash);
StrTosign := 'Transfer GVT '+GVTNumStr+' '+Destination+OrderTime;
Signature := GetStringSigned(StrTosign,GetWallArrIndex(WallAddIndex(GVTOwner)).PrivateKey);
ResultStr := ProtocolLine(21)+ // sndGVT
OrderHash+' '+ // OrderID
'1'+' '+ // OrderLines
'SNDGVT'+' '+ // OrderType
OrderTime+' '+ // Timestamp
GVTNumStr+' '+ // reference
'1'+' '+ // Trxline
GetWallArrIndex(WallAddIndex(GVTOwner)).PublicKey+' '+ // sender
GetWallArrIndex(WallAddIndex(GVTOwner)).Hash+' '+ // address
Destination+' '+ // receiver
IntToStr(GetCustFee(MyLastBlock))+' '+ // Amountfee
'0'+' '+ // amount trfr
Signature+' '+
TrfrHash; // trfrhash
OutgoingMsjsAdd(ResultStr);
if showoutput then
begin
ToLog('console','GVT '+GVTNumStr+' transfered from '+GetWallArrIndex(WallAddIndex(GVTOwner)).Hash+' to '+Destination);
ToLog('console','Order: '+OrderHash);
//ToLog('console',StrToSign);
end;
EndPerformance('SendGVT');
End;
// Muestra la escala de halvings
Procedure ShowHalvings();
var
contador : integer;
texto : string;
block1, block2 : integer;
reward : int64;
MarketCap : int64 = 0;
Begin
for contador := 0 to HalvingSteps do
begin
block1 := BlockHalvingInterval*(contador);
if block1 = 0 then block1 := 1;
block2 := (BlockHalvingInterval*(contador+1))-1;
reward := InitialReward div (2**contador);
MarketCap := marketcap+(reward*BlockHalvingInterval);
Texto := Format('From block %7d until %7d : %11s',[block1,block2,Int2curr(reward)]);
//Texto :='From block '+IntToStr(block1)+' until '+IntToStr(block2)+': '+Int2curr(reward); //'From block '+' until '
ToLog('console',Texto);
end;
ToLog('console','And then '+int2curr(0)); //'And then '
MarketCap := MarketCap+PremineAmount-InitialReward; // descuenta una recompensa inicial x bloque 0
ToLog('console','Final supply: '+int2curr(MarketCap)); //'Final supply: '
End;
// cambia el puerto de escucha
Procedure SetServerPort(LineText:string);
var
NewPort:string = '';
Begin
ToLog('console','Deprecated');
Exit;
NewPort := parameter(linetext,1);
if ((StrToIntDef(NewPort,0) < 1) or (StrToIntDef(NewPort,0)>65535)) then
begin
ToLog('console','Invalid Port');
end
else
begin
LocalMN_Port := NewPort;
OutText('New listening port: '+NewPort,false,2);
end;
End;
// prueba la lectura de parametros de la linea de comandos
Procedure TestParser(LineText:String);
var
contador : integer = 1;
continuar : boolean;
parametro : string;
Begin
ToLog('console',Parameter(linetext,0));
continuar := true;
repeat
begin
parametro := Parameter(linetext,contador);
if parametro = '' then continuar := false
else
begin
ToLog('console',inttostr(contador)+' '+parametro);
contador := contador+1;
end;
end;
until not continuar
End;
// Delete bots from server
{
Procedure DeleteBots(LineText:String);
Begin
SetLength(BotsList,0);
LastBotClear := UTCTimeStr;
End;
}
Procedure Parse_RestartNoso();
Begin
RestartNosoAfterQuit := true;
CloseeAppSafely();
End;
Procedure GetOwnerHash(LineText:string);
var
Direccion, Pubkey, privkey, currtime, Certificate : string;
AddIndex : integer;
Begin
direccion := parameter(linetext,1);
AddIndex := WallAddIndex(direccion);