Skip to content
This repository has been archived by the owner on Sep 14, 2024. It is now read-only.

Commit

Permalink
nslblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
NosoDevTeam committed Jun 18, 2024
1 parent 94e88cc commit 033ad76
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lastrelease.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.2Da1 0.4.2Da1 x {LastOfficial} {LastBeta} {TestNet}
0.4.2Da2 0.4.2Da2 x {LastOfficial} {LastBeta} {TestNet}
32 changes: 26 additions & 6 deletions masterpaskalform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ TForm1 = class(TForm)
HideCommands : String = 'CLEAR SENDPOOLSOLUTION SENDPOOLSTEPS DELBOTS';
CustomValid : String = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@*+-_:';

MainnetVersion = '0.4.2';
MainnetVersion = '0.4.3';
{$IFDEF WINDOWS}
RestartFileName = 'launcher.bat';
updateextension = 'zip';
Expand All @@ -576,9 +576,9 @@ TForm1 = class(TForm)
RestartFileName = 'launcher.sh';
updateextension = 'tgz';
{$ENDIF}
NodeRelease = 'Da2';
OficialRelease = true;
BetaRelease = false;
NodeRelease = 'Aa1';
OficialRelease = False;
BetaRelease = True;
VersionRequired = '0.4.2';
BuildDate = 'April 2024';
{Developer addresses}
Expand Down Expand Up @@ -619,7 +619,7 @@ TForm1 = class(TForm)

var
Form1 : TForm1;
Customizationfee : int64 = InitialReward div ComisionCustom;
//Customizationfee : int64 = InitialReward div ComisionCustom;
{Options}
FileAdvOptions : textfile;
S_AdvOpt : boolean = false;
Expand All @@ -638,6 +638,7 @@ TForm1 = class(TForm)
WO_StopGUI : boolean = false;
WO_BlockDB : boolean = false;
WO_PRestart : int64 = 0;
WO_skipBlocks : boolean = false;
RPCFilter : boolean = true;
RPCWhitelist : string = '127.0.0.1,localhost';
RPCBanned : string = '';
Expand Down Expand Up @@ -2645,6 +2646,8 @@ procedure TForm1.IdTCPServer1Connect(AContext: TIdContext);
ContextData : TServerTipo;
ThisSlot : integer;
PeerUTC : int64;
BlockZipName: string = '';
BlockZipsize: int64;
Begin
GoAhead := true;
ContextData := TServerTipo.Create;
Expand Down Expand Up @@ -2720,6 +2723,23 @@ procedure TForm1.IdTCPServer1Connect(AContext: TIdContext);
MemStream.Free;
TryCloseServerConnection(AContext);
end
else if parameter(LLine,0) = 'NSLBLOCKS' then
begin
MemStream := TMemoryStream.Create;
BlockZipsize := GetBlocksAsStream(MemStream,StrToIntDef(parameter(LLine,1),-1),MyLastBlock);
If BlockZipsize > 0 then
begin
TRY
Acontext.Connection.IOHandler.WriteLn('BLOCKZIP '+inttoStr(BlockZipsize));
Acontext.connection.IOHandler.Write(MemStream,0,true);
EXCEPT on E:Exception do
begin
end;
END; {TRY}
end;
MemStream.Free;
TryCloseServerConnection(AContext);
end
else if parameter(LLine,0) = 'GETZIPSUMARY' then //
begin
MemStream := TMemoryStream.Create;
Expand Down Expand Up @@ -2833,7 +2853,7 @@ procedure TForm1.IdTCPServer1Exception(AContext: TIdContext;AException: Exceptio
Address := DireccionesPanel.Cells[0,DireccionesPanel.Row];
if not IsValidHashAddress(address) then info('Address already customized')
else if AddressAlreadyCustomized(address) then info('Address already customized')
else if GetAddressBalanceIndexed(Address)-GetAddressPendingPays(address)< Customizationfee then info('Insufficient funds')
else if GetAddressBalanceIndexed(Address)-GetAddressPendingPays(address)< GetCustFee(MyLastBlock) then info('Insufficient funds')
else
begin
DireccionesPanel.Enabled:=false;
Expand Down
1 change: 1 addition & 0 deletions mpblock.pas
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ implementation


Begin
if WO_skipBlocks then exit;
if GetCFGDataStr(0) = 'STOP' then
begin
ClearAllPending;
Expand Down
6 changes: 5 additions & 1 deletion mpdisk.pas
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ implementation
writeln(FileAdvOptions,'BlocksDB '+BoolToStr(WO_BlockDB,true));
writeln(FileAdvOptions,'//Restart periodically the node');
writeln(FileAdvOptions,'PRestart '+IntToStr(WO_PRestart));
writeln(FileAdvOptions,'//Skip new blocks creation');
writeln(FileAdvOptions,'SkipBlocks '+BoolToStr(WO_skipBlocks,true));

writeln(FileAdvOptions,'//Mainform coordinates. Do not manually change this values');
writeln(FileAdvOptions,Format('FormState %d %d %d %d %d',[Form1.Top,form1.Left,form1.Width,form1.Height,form1.WindowState]));
Expand Down Expand Up @@ -330,6 +332,8 @@ implementation
if parameter(linea,0) ='SendReport' then WO_SendReport:=StrToBool(Parameter(linea,1));
if parameter(linea,0) ='BlocksDB' then WO_BlockDB:=StrToBool(Parameter(linea,1));
if parameter(linea,0) ='PRestart' then WO_PRestart:=StrToIntDef(Parameter(linea,1),0);
if parameter(linea,0) ='SkipBlocks' then WO_skipBlocks:=StrToBool(Parameter(linea,1));



if parameter(linea,0) ='MultiSend' then WO_MultiSend:=StrToBool(Parameter(linea,1));
Expand Down Expand Up @@ -683,7 +687,7 @@ function UnZipUpdateFromRepo(Tver,TArch:String):boolean;
if ArrayOrders[cont].OrderType='SNDGVT' then
begin
Inc(GVTsTrfer);
SummaryPay(ArrayOrders[cont].sender,Customizationfee,BlockNumber);
SummaryPay(ArrayOrders[cont].sender,GetCustFee(BlockNumber),BlockNumber);
ChangeGVTOwner(StrToIntDef(ArrayOrders[cont].Reference,100),ArrayOrders[cont].sender,ArrayOrders[cont].Receiver);
end;
if ArrayOrders[cont].OrderType='TRFR' then
Expand Down
56 changes: 52 additions & 4 deletions mpparser.pas
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function ShowPrivKey(linea:String;ToConsole:boolean = false):String;
Procedure NewAddressFromKeys(inputline:string);
Procedure TestHashGeneration(inputline:string);
Procedure CompareHashes(inputline:string);
Procedure CreateMultiAddress(Inputline:String);

// CONSULTING
Procedure ListGVTs();
Expand Down Expand Up @@ -272,6 +273,7 @@ function GetOpData(textLine:string):String;
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)


// New system
Expand Down Expand Up @@ -647,7 +649,7 @@ function GetWalletBalance(): Int64;
ToLog('console','Alias can not be a valid address'); //'Alias can not be a valid address'
procesar := false;
end;
if GetWallArrIndex(WallAddIndex(address)).Balance < Customizationfee then
if GetWallArrIndex(WallAddIndex(address)).Balance < GetCustFee(MyLastBlock) then
begin
ToLog('console','Insufficient balance'); //'Insufficient balance'
procesar := false;
Expand Down Expand Up @@ -687,7 +689,7 @@ function GetWalletBalance(): Int64;
GetWallArrIndex(WallAddIndex(address)).PublicKey+' '+ // sender
GetWallArrIndex(WallAddIndex(address)).Hash+' '+ // address
AddAlias+' '+ // receiver
IntToStr(Customizationfee)+' '+ // Amountfee
IntToStr(GetCustFee(MyLastBlock))+' '+ // Amountfee
'0'+' '+ // amount trfr
'[[RESULT]] '+
TrfrHash); // trfrhash
Expand Down Expand Up @@ -852,7 +854,7 @@ function SendFunds(LineText:string;showOutput:boolean=true):string;
if showOutput then ToLog('console','You do not own that GVT');
exit;
end;
if GetAddressAvailable(GVTOwner)<Customizationfee then
if GetAddressAvailable(GVTOwner)<GetCustFee(MyLastBlock) then
begin
if showOutput then ToLog('console','Inssuficient funds');
exit;
Expand Down Expand Up @@ -887,7 +889,7 @@ function SendFunds(LineText:string;showOutput:boolean=true):string;
GetWallArrIndex(WallAddIndex(GVTOwner)).PublicKey+' '+ // sender
GetWallArrIndex(WallAddIndex(GVTOwner)).Hash+' '+ // address
Destination+' '+ // receiver
IntToStr(Customizationfee)+' '+ // Amountfee
IntToStr(GetCustFee(MyLastBlock))+' '+ // Amountfee
'0'+' '+ // amount trfr
Signature+' '+
TrfrHash; // trfrhash
Expand Down Expand Up @@ -1819,6 +1821,52 @@ function ShowPrivKey(linea:String;ToConsole:boolean = false):String;

End;

// Creates a multiaddress
// Example: >getmulti 2,3 Nxxx,Nxxxx,Nxxxx
Procedure CreateMultiAddress(Inputline:String);
var
source : string = '';
FullSource : string = '';
AddType : string;
NewAdd : String;
AddsNeeded : integer;
AddsTotal : integer;
ErrorMsg : string = '';
NewAddress : WalletData;
Begin
AddType := parameter(Inputline,1);
AddType := StringReplace(AddType,',',' ',[rfReplaceAll, rfIgnoreCase]);
AddsNeeded := StrToIntDef(Parameter(AddType,0),-1);
AddsTotal := StrToIntDef(Parameter(AddType,1),-1);
if Addtype = '' then ErrorMsg := 'getmulti needed,total list,of,addresses';
if ( (AddsTotal<2) or (AddsTotal>7) ) then ErrorMsg := 'Wrong number of total addresses';
if ( (AddsNeeded <1) or (AddsNeeded>=AddsTotal) ) then ErrorMsg := 'Wrong number of needed addresses';
if ErrorMsg <> '' then
begin
ToLog('Console',ErrorMsg);
Exit;
end;
source := parameter(Inputline,2);
if not GetMultiSource(Source,AddsTotal,FullSource) then
begin
ToLog('Console','Error: '+FullSource);
Exit;
end;
AddType := StringReplace(AddType,' ',',',[rfReplaceAll, rfIgnoreCase]);
NewAdd := GetAddressFromPublicKey(AddType+':'+FullSource,AddTypeMulti);
if IsValidHashAddress(NewAdd) then
begin
ToLog('Console','New multiAddress: '+NewAdd);
NewAddress := Default(WalletData);
NewAddress.Hash:= NewAdd;
NewAddress.PublicKey:=AddType+':'+FullSource;
InsertToWallArr(NewAddress);
S_Wallet := true;
U_DirPanel := true;
end
else ToLog('Console','Something went wrong...');
End;

// PSOs testing functions

Procedure TestNewPSO(Dataline:String);
Expand Down
4 changes: 2 additions & 2 deletions mpprotocol.pas
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ function CreateZipBlockfile(firstblock:integer):string;
Address := GetAddressFromPublicKey(OrderInfo.sender);
if address <> OrderInfo.Address then ErrorCode := 1;
// La direccion no dispone de fondos
if GetAddressBalanceIndexed(Address)-GetAddressPendingPays(Address) < Customizationfee then ErrorCode:=2;
if GetAddressBalanceIndexed(Address)-GetAddressPendingPays(Address) < GetCustFee(MyLastBlock) then ErrorCode:=2;
if TranxAlreadyPending(OrderInfo.TrfrID ) then ErrorCode:=3;
if OrderInfo.TimeStamp < LastBlockData.TimeStart then ErrorCode:=4;
if TrxExistsInLastBlock(OrderInfo.TrfrID) then ErrorCode:=5;
Expand Down Expand Up @@ -892,7 +892,7 @@ function ValidateTrfr(order:Torderdata;Origen:String):integer;
Address := GetAddressFromPublicKey(OrderInfo.sender);
if address <> OrderInfo.Address then ErrorCode := 1;
// La direccion no dispone de fondos
if GetAddressBalanceIndexed(Address)-GetAddressPendingPays(Address) < Customizationfee then ErrorCode:=2;
if GetAddressBalanceIndexed(Address)-GetAddressPendingPays(Address) < GetCustFee(MyLastBlock) then ErrorCode:=2;
if TranxAlreadyPending(OrderInfo.TrfrID ) then ErrorCode:=3;
if OrderInfo.TimeStamp < LastBlockData.TimeStart then ErrorCode:=4;
if TrxExistsInLastBlock(OrderInfo.TrfrID) then ErrorCode:=5;
Expand Down
47 changes: 46 additions & 1 deletion nosoblock.pas
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
INTERFACE

uses
Classes, SysUtils, FileUtil, NosoDebug, NosoUnit, Nosocrypto,nosogeneral;
Classes, SysUtils, FileUtil, Zipper,
NosoDebug, NosoUnit, Nosocrypto,nosogeneral;

Type
TDBRecord = record
Expand Down Expand Up @@ -57,6 +58,7 @@ function GetBlockTrxs(BlockNumber:integer):TBlockOrdersArray;
function LoadBlockDataHeader(BlockNumber:integer):BlockHeaderData;

Function SaveStreamAsZipBlocks(Const LStream:TMemoryStream):boolean;
function GetBlocksAsStream(out LMs:TMemoryStream;firstblock, CurrentLastblock:integer):Int64;

var
BlockDirectory : string = 'NOSODATA'+DirectorySeparator+'BLOCKS'+DirectorySeparator;
Expand Down Expand Up @@ -421,6 +423,49 @@ function LoadBlockDataHeader(BlockNumber:integer):BlockHeaderData;
END{Try};
End;

// Creates the zip block file
function GetBlocksAsStream(out LMs:TMemoryStream;firstblock, CurrentLastblock:integer):Int64;
var
MyZipFile: TZipper;
ZipFileName:String;
LastBlock : integer;
contador : integer;
filename, archivename: String;
Begin
result := 0;
LastBlock := FirstBlock + 100; if LastBlock>CurrentLastblock then LastBlock := CurrentLastblock;
MyZipFile := TZipper.Create;
ZipFileName := BlockDirectory+'Blocks_'+IntToStr(FirstBlock)+'_'+IntToStr(LastBlock)+'.zip';
MyZipFile.FileName := ZipFileName;
TRY
for contador := FirstBlock to LastBlock do
begin
filename := BlockDirectory+IntToStr(contador)+'.blk';
{$IFDEF WINDOWS}
archivename:= StringReplace(filename,'\','/',[rfReplaceAll]);
{$ENDIF}
{$IFDEF UNIX}
archivename:= filename;
{$ENDIF}
MyZipFile.Entries.AddFileEntry(filename, archivename);
end;
MyZipFile.ZipAllFiles;
//result := ZipFileName;
EXCEPT ON E:Exception do
begin
ToLog('exceps',FormatDateTime('dd mm YYYY HH:MM:SS.zzz', Now)+' -> '+'Error zipping block files: '+E.Message);
end;
END;
MyZipFile.Free;
TRY
LMs.LoadFromFile(ZipFileName);
result:= LMs.Size;
LMs.Position:=0;
EXCEPT ON E:Exception do
END{Try};
Trydeletefile(ZipFileName);
End;

{$ENDREGION Blocks Files management}

INITIALIZATION
Expand Down
Loading

0 comments on commit 033ad76

Please sign in to comment.