diff --git a/Noso.lpi b/Noso.lpi
index 2f67253..83b0a72 100644
--- a/Noso.lpi
+++ b/Noso.lpi
@@ -199,7 +199,7 @@
-
+
@@ -318,6 +318,11 @@
+
+
+
+
+
diff --git a/Noso.lpr b/Noso.lpr
index 2e2b557..ab692fa 100644
--- a/Noso.lpr
+++ b/Noso.lpr
@@ -10,7 +10,7 @@
Forms, MasterPaskalForm, mpGUI, mpdisk, mpParser, mpRed, mpProtocol, mpBlock,
mpCoin, mpsignerutils, mpRPC, translation, indylaz, sysutils, LCLTranslator,
mpMN, mpsyscheck, NosoTime, nosodebug, nosogeneral, nosocrypto, nosounit,
- nosoconsensus, nosopsos, nosowallcon, NosoHeaders, NosoNosoCFG;
+ nosoconsensus, nosopsos, nosowallcon, NosoHeaders, NosoNosoCFG, NosoBlock;
{$R *.res}
var
diff --git a/lastrelease.txt b/lastrelease.txt
index cb3f391..c35dbf3 100644
--- a/lastrelease.txt
+++ b/lastrelease.txt
@@ -1 +1 @@
-0.4.2Ca4 0.4.2Ca5 x {LastOfficial} {LastBeta} {TestNet}
\ No newline at end of file
+0.4.2Ca4 0.4.2Ca6 x {LastOfficial} {LastBeta} {TestNet}
\ No newline at end of file
diff --git a/masterpaskalform.lfm b/masterpaskalform.lfm
index 8c610ec..82ba800 100644
--- a/masterpaskalform.lfm
+++ b/masterpaskalform.lfm
@@ -876,9 +876,9 @@ object Form1: TForm1
Height = 460
Top = 0
Width = 632
- ActivePage = TabNodeOptions
+ ActivePage = Tab_Options_RPC
Align = alClient
- TabIndex = 1
+ TabIndex = 2
TabOrder = 0
object TabOpt_Wallet: TTabSheet
Caption = 'Wallet'
diff --git a/masterpaskalform.pas b/masterpaskalform.pas
index c382648..db7becb 100644
--- a/masterpaskalform.pas
+++ b/masterpaskalform.pas
@@ -11,7 +11,7 @@ interface
strutils, math, IdHTTPServer, IdCustomHTTPServer,
IdHTTP, fpJSON, Types, DefaultTranslator, LCLTranslator, translation, nosodebug,
IdComponent,nosogeneral,nosocrypto, nosounit, nosoconsensus, nosopsos, NosoWallCon,
- nosoheaders;
+ nosoheaders, nosoblock;
type
@@ -138,6 +138,7 @@ TUpdateLogs = class(TThread)
PSOHash : string[32];
end;
+ {
BlockHeaderData = Packed Record
Number : Int64;
TimeStart : Int64;
@@ -154,6 +155,7 @@ TUpdateLogs = class(TThread)
MinerFee : Int64;
Reward : Int64;
end;
+ }
NetworkData = Packed Record
Value : String[64]; // el valor almacenado
@@ -576,7 +578,7 @@ TForm1 = class(TForm)
RestartFileName = 'launcher.sh';
updateextension = 'tgz';
{$ENDIF}
- SubVersion = 'Ca5';
+ SubVersion = 'Ca6';
OficialRelease = false;
BetaRelease = true;
VersionRequired = '0.4.2Ba7';
@@ -846,7 +848,7 @@ TForm1 = class(TForm)
BotDataFilename : string= 'NOSODATA'+DirectorySeparator+'botdata.psk';
//WalletFilename : string= 'NOSODATA'+DirectorySeparator+'wallet.pkw';
- BlockDirectory : string= 'NOSODATA'+DirectorySeparator+'BLOCKS'+DirectorySeparator;
+ //BlockDirectory : string= 'NOSODATA'+DirectorySeparator+'BLOCKS'+DirectorySeparator;
MarksDirectory : string= 'NOSODATA'+DirectorySeparator+'SUMMARKS'+DirectorySeparator;
GVTMarksDirectory : string= 'NOSODATA'+DirectorySeparator+'SUMMARKS'+DirectorySeparator+'GVTS'+DirectorySeparator;
UpdatesDirectory : string= 'NOSODATA'+DirectorySeparator+'UPDATES'+DirectorySeparator;
@@ -1444,41 +1446,13 @@ constructor TThreadIndexer.Create(CreateSuspended : boolean);
end;
procedure TThreadIndexer.Execute;
-var
- resultorder : TOrderGroup;
- ArrTrxs : TBlockOrdersArray;
- Counter : integer;
- NewRec : TOrdIndex;
- IsCompleted : boolean = false;
Begin
AddNewOpenThread('Indexer',UTCTime);
- MyLastOrdIndex := GetMyLastUpdatedBlock-1008;
- if MyLastOrdIndex < 0 then MyLastOrdIndex := 0;
- ToLog('console',format('Indexer starts at block %d',[MyLastOrdIndex]));
while not terminated do
begin
- if MyLastOrdIndex < MyLAstBlock then
- begin
- NewRec := Default(TOrdIndex);
- NewRec.block:=MyLastOrdIndex;
- ArrTrxs := GetBlockTrxs(MyLastOrdIndex);
- if length(ArrTrxs)>0 then
- begin
- for counter := 0 to high(ArrTrxs) do
- begin
- NewRec.orders:=NewRec.orders+ArrTrxs[counter].OrderID+',';
- end;
-
- end;
- Insert(NewRec,ArrayOrdIndex,Length(ArrayOrdIndex));
- Inc(MyLastOrdIndex);
- if ( (MyLastOrdIndex = MyLastBlock) and (IsCompleted = false) ) then
- begin
- ToLog('console',format('OrderIDs index updated at block %d',[MyLastOrdIndex]));
- IsCompleted := true;
- end;
- end;
- sleep(10);
+ if GetMyLastUpdatedBlock > GetDBLastBlock then
+ UpdateBlockDatabase;
+ sleep(1000);
end;
CloseOpenThread('Indexer');
End;
@@ -1648,7 +1622,7 @@ procedure TForm1.FormShow(sender: TObject);
Halt();
end;
MixTxtFiles([DeepDebLogFilename,ConsoleLogFilename,EventLogFilename,ExceptLogFilename,NodeFTPLogFilename,PerformanceFIlename],ResumeLogFilename,true);
-InitDeepDeb(DeepDebLogFilename,'Starting DeepDebug session');
+InitDeepDeb(DeepDebLogFilename,format('( %s - %s )',[ProgramVersion+subversion, OSVersion]));
NosoDebug_UsePerformance := true;
UpdateLogsThread := TUpdateLogs.Create(true);
UpdateLogsThread.FreeOnTerminate:=true;
@@ -1663,10 +1637,14 @@ procedure TForm1.FormShow(sender: TObject);
VerifyFiles();
if ( (not fileExists(ClosedAppFilename)) and (WO_Sendreport) ) then
begin
- // Send the report file here
- OutText('Bug report sent to developers',false,1); //✓ GUI initialized
+ if SEndFileViaTCP(ResumeLogFilename,'REPORT','141.11.192.215',18081) then
+ begin
+ OutText('✓ Bug report sent to developers',false,1);
+ TryDeleteFile(ClosedAppFilename);
+ end
+ else OutText('✓ Error sending report to developers',false,1);
end;
-TryDeleteFile(ClosedAppFilename);
+
InicializarGUI();
//InitTime();
GetTimeOffset(PArameter(GetNosoCFGString,2));
@@ -2269,13 +2247,6 @@ function TForm1.ClientsCount : Integer ;
end;
End;
-Function SendFileToClient(Message:String;filename:string):Boolean;
-var
- MyStream : TMemoryStream;
-Begin
-
-end;
-
// Node server gets a line
procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
var
diff --git a/mpblock.pas b/mpblock.pas
index 98fbcaf..db8e7aa 100644
--- a/mpblock.pas
+++ b/mpblock.pas
@@ -7,7 +7,7 @@ interface
uses
Classes, SysUtils,MasterPaskalForm, fileutil, mpcoin, dialogs, math,
nosotime, mpMN, nosodebug,nosogeneral,nosocrypto, nosounit, strutils,
- nosopsos,nosowallcon,nosoheaders;
+ nosopsos,nosowallcon,nosoheaders, nosoblock;
Procedure CrearBloqueCero();
Procedure BuildNewBlock(Numero,TimeStamp: Int64; TargetHash, Minero, Solucion:String);
diff --git a/mpcoin.pas b/mpcoin.pas
index c875b73..fa3173b 100644
--- a/mpcoin.pas
+++ b/mpcoin.pas
@@ -6,7 +6,7 @@ interface
uses
Classes, SysUtils,MasterPaskalForm,mpgui,Clipbrd, strutils, nosodebug,nosogeneral,
- nosocrypto, nosounit,nosotime,nosopsos,nosowallcon;
+ nosocrypto, nosounit,nosotime,nosopsos,nosowallcon, nosoblock;
function GetAddressAvailable(address:string):int64;
function GetAddressPendingPays(Address:string):int64;
diff --git a/mpdisk.pas b/mpdisk.pas
index f6f131c..aaf549d 100644
--- a/mpdisk.pas
+++ b/mpdisk.pas
@@ -9,7 +9,7 @@ interface
lclintf, controls, mpBlock, Zipper, mpcoin, mpMn, nosodebug,
{$IFDEF WINDOWS}Win32Proc, {$ENDIF}
translation, strutils,nosogeneral, nosocrypto, nosounit, nosoconsensus, nosopsos,
- nosowallcon, nosoheaders, nosonosocfg;
+ nosowallcon, nosoheaders, nosonosocfg, nosoblock;
Function FileStructure():integer;
Procedure VerifyFiles();
@@ -91,6 +91,8 @@ implementation
if not CreateDir(GVTMarksDirectory) then Inc(Result);
if not directoryexists(RPCBakDirectory) then
if not CreateDir(RPCBakDirectory) then Inc(Result);
+ if not directoryexists(BlockDirectory+DBDirectory) then
+ if not CreateDir(BlockDirectory+DBDirectory) then Inc(Result);
End;
// Complete file verification
@@ -146,6 +148,10 @@ implementation
if not Fileexists(ResumenFilename) then CreateHeadersFile();
OutText('✓ Headers file ok',false,1);
+if not FileExists(BlockDirectory+DBDirectory+DataBaseFilename) then CreateDBFile;
+OutText('✓ Database file ok. Creating index',false,1);
+CreateOrderIDIndex;
+
if not FileExists(BlockDirectory+'0.blk') then CrearBloqueCero();
MyLastBlock := GetMyLastUpdatedBlock;
OutText('✓ My last block verified: '+MyLastBlock.ToString,false,1);
diff --git a/mpgui.pas b/mpgui.pas
index 4465bd9..22cc169 100644
--- a/mpgui.pas
+++ b/mpgui.pas
@@ -7,7 +7,7 @@ interface
uses
Classes, SysUtils, MasterPaskalForm, nosotime, graphics, strutils, forms, controls, grids,stdctrls,
ExtCtrls, buttons, editbtn , menus, Clipbrd, IdContext, LCLTranslator, nosodebug, nosogeneral,
- nosocrypto, nosoconsensus,nosounit, nosopsos, nosowallcon;
+ nosocrypto, nosoconsensus,nosounit, nosopsos, nosowallcon,nosoblock;
type
TFormInicio = class(Tform)
@@ -409,7 +409,7 @@ procedure TFormSlots.GridMSlotsPrepareCanvas(sender: TObject; aCol, aRow: Intege
form1.DataPanel.Cells[3,0]:= format('[%d - %d] %s / %s',[GEtPSOHeaders.MNsLock,GetPSOHeaders.count,Copy(PSOFileHash,0,5),GetConsensus(20)]);
form1.DataPanel.Cells[3,1]:= Format('[%s] %s Noso',[BlockAge.ToString,Copy(Int2curr(GetBlockReward(Mylastblock+1)),0,5)]);
form1.DataPanel.Cells[3,2]:= GEtOutgoingconnections.ToString+'/'+GetClientReadThreads.ToString;
- form1.DataPanel.Cells[3,3]:= Format('%d (%d)',[MyLastOrdIndex,length(ArrayOrdIndex)]);
+ form1.DataPanel.Cells[3,3]:= Format('%d (%d)',[GetDBLastBlock,GetDBRecords]);
form1.DataPanel.Cells[3,4]:= format('%s / %s',[Copy(HashMd5String(GetNosoCFGString),0,5),GetConsensus(19)]);
form1.DataPanel.Cells[3,5]:= format('%s / %s',[Copy(MyGVTsHash,0,5),GetConsensus(18)]);
form1.DataPanel.Cells[3,6]:= format('%s / %s',[Copy(MyMNsHash,0,5),GetConsensus(8)]);
diff --git a/mpparser.pas b/mpparser.pas
index 26f0bd0..90fc1ee 100644
--- a/mpparser.pas
+++ b/mpparser.pas
@@ -8,7 +8,7 @@ interface
Classes, SysUtils, MasterPaskalForm, mpGUI, mpRed, mpDisk, nosotime, mpblock, mpcoin,
dialogs, fileutil, forms, idglobal, strutils, mpRPC, DateUtils, Clipbrd,translation,
idContext, math, mpMN, MPSysCheck, nosodebug, nosogeneral, nosocrypto, nosounit,
- nosoconsensus, nosopsos,nosowallcon, nosoheaders;
+ nosoconsensus, nosopsos,nosowallcon, nosoheaders, nosoblock;
procedure ProcessLinesAdd(const ALine: String);
procedure OutgoingMsjsAdd(const ALine: String);
@@ -275,6 +275,10 @@ function GetOpData(textLine:string):String;
begin
SetCFGData(GetRepoFile('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)
+
+
// New system
diff --git a/mpprotocol.pas b/mpprotocol.pas
index 965214d..31751ca 100644
--- a/mpprotocol.pas
+++ b/mpprotocol.pas
@@ -7,7 +7,7 @@ interface
uses
Classes, SysUtils, mpRed, MasterPaskalForm, mpParser, StrUtils, mpDisk, nosotime, mpBlock,
Zipper, mpcoin, mpMn, nosodebug, nosogeneral, nosocrypto, nosounit,nosoconsensus,nosopsos,
- nosoheaders, NosoNosoCFG;
+ nosoheaders, NosoNosoCFG, nosoblock;
function GetPTCEcn():String;
Function GetOrderFromString(textLine:String):TOrderData;
diff --git a/mpred.pas b/mpred.pas
index 828d231..9ecd37b 100644
--- a/mpred.pas
+++ b/mpred.pas
@@ -9,7 +9,7 @@ interface
mpBlock, fileutil, graphics, dialogs, strutils, mpcoin, fphttpclient,
opensslsockets,translation, IdHTTP, IdComponent, IdSSLOpenSSL, mpmn, IdTCPClient,
nosodebug,nosogeneral, nosocrypto, nosounit, nosoconsensus, nosopsos,nosowallcon,
- nosoheaders;
+ nosoheaders, nosoblock;
function GetSlotFromIP(Ip:String):int64;
function GetSlotFromContext(Context:TidContext):int64;
@@ -250,7 +250,7 @@ procedure StartServer();
U_DataPanel := true;
except
on E : Exception do
- ToLog('events',TimeToStr(now)+'Unable to start Server'); //Unable to start Server
+ ToLog('events',TimeToStr(now)+'Unable to start Server: '+e.Message); //Unable to start Server
end;
end;
End;
diff --git a/mprpc.pas b/mprpc.pas
index 2c734f7..1d955dc 100644
--- a/mprpc.pas
+++ b/mprpc.pas
@@ -38,6 +38,7 @@ function RPC_Masternodes(NosoPParams:string):string;
function RPC_Blockmns(NosoPParams:string):string;
Function RPC_WalletBalance(NosoPParams:string):string;
function RPC_NewAddress(NosoPParams:string):string;
+function RPC_NewAddressFull(NosoPParams:string):string;
Function RPC_ValidateAddress(NosoPParams:string):string;
Function RPC_SetDefault(NosoPParams:string):string;
Function RPC_GVTInfo(NosoPParams:string):string;
@@ -381,6 +382,12 @@ function ObjectFromString(MyString:string): string;
resultado.Add('count',StrToIntDef(parameter(mystring,2),-1));
resultado.Add('nodes',parameter(mystring,3));
end
+else if objecttype = 'newaddressfull' then
+ begin
+ resultado.Add('hash',parameter(mystring,1));
+ resultado.Add('public',parameter(mystring,2));
+ resultado.Add('private',parameter(mystring,3));
+ end
else if objecttype = 'newaddress' then
begin
//resultado.Add('valid',StrToBool(parameter(mystring,1)));
@@ -468,6 +475,7 @@ function ParseRPCJSON(jsonreceived:string):string;
else if method = 'getmasternodes' then result := GetJSONResponse(RPC_Masternodes(NosoPParams),jsonid)
else if method = 'getwalletbalance' then result := GetJSONResponse(RPC_WalletBalance(NosoPParams),jsonid)
else if method = 'getnewaddress' then result := GetJSONResponse(RPC_NewAddress(NosoPParams),jsonid)
+ else if method = 'getnewaddressfull' then result := GetJSONResponse(RPC_NewAddressFull(NosoPParams),jsonid)
else if method = 'islocaladdress' then result := GetJSONResponse(RPC_ValidateAddress(NosoPParams),jsonid)
else if method = 'setdefault' then result := GetJSONResponse(RPC_SetDefault(NosoPParams),jsonid)
else if method = 'getgvtinfo' then result := GetJSONResponse(RPC_GVTInfo(NosoPParams),jsonid)
@@ -800,7 +808,6 @@ function RPC_NewAddress(NosoPParams:string):string;
Begin
TotalNumber := StrToIntDef(NosoPParams,1);
if TotalNumber > 100 then TotalNumber := 100;
-//ToLog('console','TotalNewAddresses: '+IntToStr(TotalNumber));
result := 'newaddress'#127'true'#127+IntToStr(TotalNumber)+#127;
for counter := 1 to totalnumber do
begin
@@ -815,7 +822,25 @@ function RPC_NewAddress(NosoPParams:string):string;
trim(result);
S_Wallet := true;
U_DirPanel := true;
-//ToLog('console',result);
+End;
+
+function RPC_NewAddressFull(NosoPParams:string):string;
+var
+ counter : integer;
+ NewAddress : WalletData;
+ PubKey,PriKey : string;
+Begin
+ result := 'newaddressfull'#127;
+ NewAddress := Default(WalletData);
+ NewAddress.Hash:=GenerateNewAddress(PubKey,PriKey);
+ NewAddress.PublicKey:=pubkey;
+ NewAddress.PrivateKey:=PriKey;
+ InsertToWallArr(NewAddress);
+ if RPCSaveNew then SaveAddresstoFile(RPCBakDirectory+NewAddress.Hash+'.pkw',NewAddress);
+ Result := result+NewAddress.Hash+#127+NewAddress.PublicKey+#127+NewAddress.PrivateKey;
+ trim(result);
+ S_Wallet := true;
+ U_DirPanel := true;
End;
Function RPC_ValidateAddress(NosoPParams:string):string;
diff --git a/nosoblock.pas b/nosoblock.pas
new file mode 100644
index 0000000..3a3a3da
--- /dev/null
+++ b/nosoblock.pas
@@ -0,0 +1,304 @@
+unit NosoBlock;
+
+{
+NosoNosoCFG 1.1
+Febraury 5, 2024
+All block related controls
+}
+
+{$mode ObjFPC}{$H+}
+
+INTERFACE
+
+uses
+ Classes, SysUtils, FileUtil, NosoDebug, NosoUnit, Nosocrypto;
+
+Type
+ TDBRecord = record
+ block : integer;
+ orderID : integer;
+ Source : integer;
+ Target : integer;
+ end;
+
+ BlockHeaderData = Packed Record
+ Number : Int64;
+ TimeStart : Int64;
+ TimeEnd : Int64;
+ TimeTotal : integer;
+ TimeLast20 : integer;
+ TrxTotales : integer;
+ Difficult : integer;
+ TargetHash : String[32];
+ Solution : String[200]; // 180 necessary
+ LastBlockHash : String[32];
+ NxtBlkDiff : integer;
+ AccountMiner : String[40];
+ MinerFee : Int64;
+ Reward : Int64;
+ end;
+
+Procedure CreateDBFile();
+Function GetDBRecords():Integer;
+Function AddRecordToDBFile(block,order,source,target:integer):boolean;
+Function GetDBLastBlock():Integer;
+Function UpdateBlockDatabase():Boolean;
+Function CreateOrderIDIndex():Boolean;
+
+function GetMyLastUpdatedBlock():int64;
+function GetBlockTrxs(BlockNumber:integer):TBlockOrdersArray;
+
+
+var
+ BlockDirectory : string = 'NOSODATA'+DirectorySeparator+'BLOCKS'+DirectorySeparator;
+ DBDirectory : string = 'DB'+DirectorySeparator;
+ DataBaseFilename : string = 'blocks_db.nos';
+ DBFile : file of TDBRecord;
+ CSDBFile : TRTLCriticalSection;
+ OrderIDIndex : Array of TindexRecord;
+
+IMPLEMENTATION
+
+{$REGION blocks database}
+
+Procedure CreateDBFile();
+Begin
+ TRY
+ Rewrite(DBFile);
+ Closefile(DBFile);
+ EXCEPT ON E:EXCEPTION do
+ begin
+ TodeepDeb('NosoBlock,CreateDBFile,'+E.Message);
+ end;
+ END;
+End;
+
+Function GetDBRecords():Integer;
+var
+ opened : boolean = false;
+ Closed : boolean = false;
+Begin
+ Result := 0;
+ EnterCriticalSection(CSDBFile);
+ TRY
+ Reset(DBFile);
+ opened := true;
+ Result := Filesize(DBFile);
+ Closefile(DBFile);
+ Closed := true;
+ EXCEPT ON E:EXCEPTION do
+ begin
+ end;
+ END;
+ if ( (opened) and (not closed) ) then Closefile(DBfile);
+ LeaveCriticalSection(CSDBFile);
+End;
+
+Function AddRecordToDBFile(block,order,source,target:integer):boolean;
+var
+ NewData : TDBRecord;
+ opened : boolean = false;
+ Closed : boolean = false;
+Begin
+ Result := true;
+ NewData := Default(TDBRecord);
+ NewData.block:=Block;
+ NewData.orderID:=order;
+ NewData.Source:=source;
+ NewData.Target:=target;
+ EnterCriticalSection(CSDBFile);
+ TRY
+ Reset(DBFile);
+ opened := true;
+ Seek(DBFile,Filesize(DBFile));
+ Write(DBFile,NewData);
+ Closefile(DBFile);
+ Closed := true;
+ EXCEPT ON E:EXCEPTION do
+ begin
+ Result := false;
+ end;
+ END;
+ if ( (opened) and (not closed) ) then Closefile(DBfile);
+ LeaveCriticalSection(CSDBFile);
+End;
+
+Function GetDBLastBlock():Integer;
+var
+ NewData : TDBRecord;
+ opened : boolean = false;
+ Closed : boolean = false;
+Begin
+ Result := -1;
+ EnterCriticalSection(CSDBFile);
+ TRY
+ Reset(DBFile);
+ opened := true;
+ if Filesize(DBFile)>0 then
+ begin
+ Seek(DBFile,Filesize(DBFile)-1);
+ Read(DBFile,NewData);
+ Result := NewData.Block;
+ end;
+ Closefile(DBFile);
+ Closed := true;
+ EXCEPT ON E:EXCEPTION do
+ begin
+
+ end;
+ END;
+ if ( (opened) and (not closed) ) then Closefile(DBfile);
+ LeaveCriticalSection(CSDBFile);
+End;
+
+Function DBIndex(Text:string):integer;
+var
+ SubStr : string;
+Begin
+ Text := Hashmd5String(Text);
+ Text := B16toB58(Text);
+ SubStr := copy(Text,2,6);
+ result := StrToInt64(b58toB10(SubStr)) mod 100000;
+End;
+
+Function UpdateBlockDatabase():Boolean;
+var
+ LastUpdated : integer;
+ UntilBlock : integer;
+ counter, counter2 : integer;
+ ArrayOrders : TBlockOrdersArray;
+ ThisOrder : TOrderData;
+Begin
+ LastUpdated := GetDBLastBlock;
+ UntilBlock := LastUpdated+1000;
+ if untilblock > GetMyLastUpdatedBlock then untilblock := GetMyLastUpdatedBlock;
+ for counter := LastUpdated+1 to untilblock do
+ begin
+ ArrayOrders := Default(TBlockOrdersArray);
+ ArrayOrders := GetBlockTrxs(counter);
+ for counter2 := 0 to length(ArrayOrders)-1 do
+ begin
+ ThisOrder := ArrayOrders[counter2];
+ if ThisOrder.OrderType<> '' then
+ begin
+ AddRecordToDBFile(Counter,DBIndex(ThisOrder.OrderID),DBIndex(ThisOrder.Address),DBIndex(ThisOrder.Receiver));
+ end;
+ end;
+ end;
+End;
+
+Function CreateOrderIDIndex():Boolean;
+var
+ ThisData : TDBRecord;
+Begin
+ beginperformance('CreateOrderIDIndex');
+ SetLength(OrderIDIndex,0,0);
+ SetLength(OrderIDIndex,100000);
+ TRY
+ Reset(DBFile);
+ While not eof(DBFile) do
+ begin
+ ThisData := Default(TDBRecord);
+ Read(DBFile,ThisData);
+ Insert(ThisData.block,OrderIDIndex[ThisData.orderID],length(OrderIDIndex[ThisData.orderID]));
+ end;
+ EXCEPT ON E:EXCEPTION do
+ begin
+
+ end;
+ END;
+ endperformance('CreateOrderIDIndex');
+End;
+
+Function GetOrderFromDB(OrderID:String; out OrderInfo:TOrderData):boolean;
+var
+ IndexValue : integer;
+ Counter, counter2 : integer;
+ ArrayOrders : TBlockOrdersArray;
+Begin
+ Result := False;
+ IndexValue := DBIndex(OrderID);
+ if length(OrderIDIndex[IndexValue]) > 0 then
+ begin
+ for counter := 0 to length(OrderIDIndex[IndexValue])-1 do
+ begin
+ ArrayOrders := Default(TBlockOrdersArray);
+ ArrayOrders := GetBlockTrxs(OrderIDIndex[IndexValue][counter]);
+ end;
+ end;
+
+End;
+
+{$ENDREGION blocks database}
+
+{$REGION Blocks Information}
+
+// Returns the last downloaded block
+function GetMyLastUpdatedBlock():int64;
+Var
+ BlockFiles : TStringList;
+ contador : int64 = 0;
+ LastBlock : int64 = 0;
+ OnlyNumbers : String;
+ IgnoredChars : integer;
+Begin
+ IgNoredChars := Length(BlockDirectory)+1;
+ BlockFiles := TStringList.Create;
+ TRY
+ FindAllFiles(BlockFiles, BlockDirectory, '*.blk', true);
+ while contador < BlockFiles.Count do
+ begin
+ OnlyNumbers := copy(BlockFiles[contador], IgNoredChars, length(BlockFiles[contador])-(ignoredchars+3));
+ if StrToInt64Def(OnlyNumbers,0) > Lastblock then
+ LastBlock := StrToInt64Def(OnlyNumbers,0);
+ Inc(contador);
+ end;
+ Result := LastBlock;
+ EXCEPT on E:Exception do
+ ToLog('events',TimeToStr(now)+'Error getting my last updated block');
+ END; {TRY}
+ BlockFiles.Free;
+End;
+
+// Return the array containing orders in the specified block
+function GetBlockTrxs(BlockNumber:integer):TBlockOrdersArray;
+var
+ ArrTrxs : TBlockOrdersArray;
+ MemStr: TMemoryStream;
+ Header : BlockHeaderData;
+ ArchData : String;
+ counter : integer;
+ TotalTrxs, totalposes : integer;
+ posreward : int64;
+Begin
+ Setlength(ArrTrxs,0);
+ ArchData := BlockDirectory+IntToStr(BlockNumber)+'.blk';
+ MemStr := TMemoryStream.Create;
+ TRY
+ MemStr.LoadFromFile(ArchData);
+ MemStr.Position := 0;
+ MemStr.Read(Header, SizeOf(Header));
+ TotalTrxs := header.TrxTotales;
+ SetLength(ArrTrxs,TotalTrxs);
+ For Counter := 0 to TotalTrxs-1 do
+ MemStr.Read(ArrTrxs[Counter],Sizeof(ArrTrxs[Counter])); // read each record
+ Except on E: Exception do
+ begin
+ ToDeepDeb('Nosoblock,GetBlockTrxs,'+E.Message);
+ end;
+ END;
+ MemStr.Free;
+ Result := ArrTrxs;
+End;
+
+{$ENDREGION Blocks Information}
+
+INITIALIZATION
+Assignfile(DBFile,BlockDirectory+DBDirectory+DataBaseFilename);
+InitCriticalSection(CSDBFile);
+
+FINALIZATION
+DoneCriticalSection(CSDBFile);
+
+END.
+
diff --git a/nosodebug.pas b/nosodebug.pas
index 2757b9b..c3cf1cf 100644
--- a/nosodebug.pas
+++ b/nosodebug.pas
@@ -395,7 +395,7 @@ TCoreManager = record
if InitializeLogFile(LFileName,SysInfo) then
begin
DeepDebFilename := LFileName;
- ToDeepDeb(SysInfo);
+ //ToDeepDeb(SysInfo);
end;
End;
diff --git a/nosogeneral.pas b/nosogeneral.pas
index 1d18100..767bec2 100644
--- a/nosogeneral.pas
+++ b/nosogeneral.pas
@@ -47,6 +47,7 @@ function SaveTextToDisk(const aFileName: TFileName; const aText: String): Boolea
function TryCopyFile(Source, destination:string):boolean;
function TryDeleteFile(filename:string):boolean;
Function MixTxtFiles(ListFiles : array of string;Destination:String;DeleteSources:boolean=true):boolean ;
+Function SendFileViaTCP(filename,message,host:String;Port:integer):Boolean;
IMPLEMENTATION
@@ -440,6 +441,35 @@ function TryDeleteFile(filename:string):boolean;
Result := true;
End;
+Function SendFileViaTCP(filename,message,host:String;Port:integer):Boolean;
+var
+ Client : TidTCPClient;
+ MyStream : TMemoryStream;
+Begin
+ Result := true;
+ if not fileExists(filename) then exit(false);
+ MyStream := TMemoryStream.Create;
+ MyStream.LoadFromFile(filename);
+ Client := TidTCPClient.Create(nil);
+ Client.Host:=host;
+ Client.Port:=Port;
+ Client.ConnectTimeout:= 1000;
+ Client.ReadTimeout:=1000;
+ TRY
+ Client.Connect;
+ Client.IOHandler.WriteLn(message);
+ Client.IOHandler.Write(MyStream,0,true);
+ EXCEPT on E:Exception do
+ begin
+ Result := false;
+ ToDeepDeb('NosoGeneral,SendFile,'+E.Message);
+ end;
+ END;{Try}
+ if client.Connected then Client.Disconnect();
+ client.Free;
+ MyStream.Free;
+End;
+
{$ENDREGION}