diff --git a/masterpaskalform.pas b/masterpaskalform.pas index ffded3f..98265e3 100644 --- a/masterpaskalform.pas +++ b/masterpaskalform.pas @@ -580,7 +580,7 @@ TForm1 = class(TForm) OficialRelease = true; BetaRelease = false; VersionRequired = '0.4.2'; - BuildDate = 'March 2024'; + BuildDate = 'April 2024'; {Developer addresses} ADMINHash = 'N4PeJyqj8diSXnfhxSQdLpo8ddXTaGd'; AdminPubKey = 'BL17ZOMYGHMUIUpKQWM+3tXKbcXF0F+kd4QstrB0X7iWvWdOSrlJvTPLQufc1Rkxl6JpKKj/KSHpOEBK+6ukFK4='; @@ -637,6 +637,7 @@ TForm1 = class(TForm) WO_SendReport : boolean = false; WO_StopGUI : boolean = false; WO_BlockDB : boolean = false; + WO_PRestart : int64 = 0; RPCFilter : boolean = true; RPCWhitelist : string = '127.0.0.1,localhost'; RPCBanned : string = ''; @@ -1401,15 +1402,21 @@ constructor TThreadKeepConnect.Create(CreateSuspended : boolean); procedure TThreadKeepConnect.Execute; const - LastTrySlot : integer = 0; - LAstTryTime : int64 = 0; - Unables : integer = 0; + LastTrySlot : integer = 0; + LAstTryTime : int64 = 0; + Unables : integer = 0; + PRestartTime : int64 = 0; var TryThis : boolean = true; Loops : integer = 0; OutGoing : integer; Begin AddNewOpenThread('KeepConnect',UTCTime); + if WO_PRestart > 0 then + begin + PRestartTime := UTCTime + (WO_PRestart*600); + ToLog('Console','PRestart set at '+TimestampToDate(PRestartTime)); + end; while not terminated do begin UpdateOpenThread('KeepConnect',UTCTime); @@ -1425,7 +1432,13 @@ procedure TThreadKeepConnect.Execute; ConnectClient(NodesIndex(LastTrySlot).ip,NodesIndex(LastTrySlot).port); end; sleep(3000); + if PRestartTime > 0 then + begin + if ( (blockAge>120) and (blockAge<450) and (UTCTime>PRestartTime) ) then + ProcesslinesAdd('restart'); + end; end; + if EngineLastUpdate+10 < UTCTime then Parse_RestartNoso; CloseOpenThread('KeepConnect'); End; diff --git a/mpdisk.pas b/mpdisk.pas index 4fdb1fa..f5914b5 100644 --- a/mpdisk.pas +++ b/mpdisk.pas @@ -106,31 +106,38 @@ implementation GetGVTsFileData; OutText('✓ GVTs file ok',false,1); -if not FileExists(CFGFilename) then - begin - SaveCFGToFile(DefaultNosoCFG); + SetCFGFilename('NOSODATA'+DirectorySeparator+CFGFilename); + { + if not FileExists(CFGFilename) then + begin + SaveCFGToFile(DefaultNosoCFG); + GetCFGFromFile; + Defseeds := GetRepoFile('https://raw.githubusercontent.com/Noso-Project/NosoWallet/main/defseeds.nos'); + if DefSeeds = '' then Defseeds := GetRepoFile('https://api.nosocoin.com/nodes/seed'); + if defseeds <> '' then + begin + SetCFGData(Defseeds,1); + Tolog('console','Defaults seeds downloaded from trustable source'); + end + else ToLog('console','Unable to download default seeds. Please, use a fallback'); + end; GetCFGFromFile; - Defseeds := GetRepoFile('https://raw.githubusercontent.com/Noso-Project/NosoWallet/main/defseeds.nos'); - if DefSeeds = '' then Defseeds := GetRepoFile('https://api.nosocoin.com/nodes/seed'); - if defseeds <> '' then + } + OutText('✓ NosoCFG file ok',false,1); + + + if not SetWalletFilename('NOSODATA'+DirectorySeparator+'wallet.pkw') then S_AdvOpt := true; + { + if not FileExists (WalletFilename) then begin - SetCFGData(Defseeds,1); - Tolog('console','Defaults seeds downloaded from trustable source'); + CreateNewWallet; + S_AdvOpt := true; end - else ToLog('console','Unable to download default seeds. Please, use a fallback'); - end; -GetCFGFromFile; -OutText('✓ NosoCFG file ok',false,1); + else LoadWallet(WalletFilename); + } + OutText('✓ Wallet file ok',false,1); -if not FileExists (WalletFilename) then - begin - CreateNewWallet; - S_AdvOpt := true; - end -else LoadWallet(WalletFilename); -OutText('✓ Wallet file ok',false,1); - -FillNodeList; // Fills the hardcoded seed nodes list + FillNodeList; // Fills the hardcoded seed nodes list if not Fileexists(SummaryFileName) then CreateNewSummaryFile(FileExists(BlockDirectory+'0.blk')); CreateSumaryIndex(); @@ -248,6 +255,8 @@ implementation writeln(FileAdvOptions,'SendReport '+BoolToStr(WO_SendReport,true)); writeln(FileAdvOptions,'//Keep a blocks database'); writeln(FileAdvOptions,'BlocksDB '+BoolToStr(WO_BlockDB,true)); + writeln(FileAdvOptions,'//Restart periodically the node'); + writeln(FileAdvOptions,'PRestart '+IntToStr(WO_PRestart)); 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])); @@ -320,6 +329,8 @@ implementation if parameter(linea,0) ='PosWarning' then WO_PosWarning:=StrToIntDef(Parameter(linea,1),WO_PosWarning); 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) ='MultiSend' then WO_MultiSend:=StrToBool(Parameter(linea,1)); if parameter(linea,0) ='HideEmpty' then WO_HideEmpty:=StrToBool(Parameter(linea,1)); diff --git a/mpparser.pas b/mpparser.pas index 8243ed0..23d28bb 100644 --- a/mpparser.pas +++ b/mpparser.pas @@ -264,10 +264,10 @@ function GetOpData(textLine:string):String; 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',GetRepoFile('https://raw.githubusercontent.com/Noso-Project/NosoWallet/main/defseeds.nos')) +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(GetRepoFile('https://raw.githubusercontent.com/Noso-Project/NosoWallet/main/defseeds.nos'),1); + 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) @@ -802,7 +802,7 @@ function SendFunds(LineText:string;showOutput:boolean=true):string; end; Setlength(orderstring,length(orderstring)-2); OrderString := StringReplace(OrderString,'PSK','NSLORDER',[]); - //ToLog('console','Send to Node '+OrderString); + ToLog('console','Send to Node '+OrderString); result := SendOrderToNode(OrderString); //ToLog('console','Node result: '+result); OutgoingMsjsAdd(OrderString); diff --git a/nosonosocfg.pas b/nosonosocfg.pas index 401c078..09c0d88 100644 --- a/nosonosocfg.pas +++ b/nosonosocfg.pas @@ -30,7 +30,7 @@ interface Function IsSeedNode(IP:String):boolean; var - CFGFilename : string= 'NOSODATA'+DirectorySeparator+'nosocfg.psk'; + CFGFilename : string= 'nosocfg.psk'; CFGFile : Textfile; MyCFGHash : string = ''; CS_CFGFile : TRTLCriticalSection; @@ -40,7 +40,7 @@ interface LasTimeCFGRequest : int64 = 0; DefaultNosoCFG : String = // CFG parameters {0 Mainnet mode}'NORMAL '+ - {1 Seed nodes }'63.227.69.162;8080:20.199.50.27;8080:107.172.21.121;8080:107.172.214.53;8080:198.23.134.105;8080:107.173.210.55;8080:5.230.55.203;8080:141.11.192.215;8080:4.233.61.8;8080: '+ + {1 Seed nodes }'20.199.50.27;8080:107.173.210.55;8080:5.230.55.203;8080:141.11.192.215;8080:4.233.61.8;8080:84.247.143.153;8080:23.95.216.80;8080:64.69.43.225;8080:142.171.231.9;8080: '+ {2 NTP servers }'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:ntps1.pads.ufrj.br:utcnist2.colorado.edu:tick.usask.ca:ntp1.st.keio.ac.jp: '+ {3 DEPRECATED }'null: '+ {4 DEPRECATED }'null: '+ @@ -70,9 +70,27 @@ interface {$REGION File access} Procedure SetCFGFilename(Fname:String); +var + defseeds : string = ''; Begin CFGFilename := Fname; AssignFile(CFGFile, CFGFilename); + if not fileexists(CFGFilename) then + begin + SaveCFGToFile(DefaultNosoCFG); + GetCFGFromFile; + Defseeds := SendApiRequest('https://raw.githubusercontent.com/Noso-Project/NosoWallet/main/defseeds.nos'); + if defseeds <> '' then + begin + SetCFGData(Defseeds,1); + Tolog('console','Defaults seeds downloaded from trustable source'); + end + else + begin + ToLog('console','Unable to download default seeds. Please, use a fallback'); + end; + end; + GetCFGFromFile; SetCFGHash(); End; diff --git a/nosowallcon.pas b/nosowallcon.pas index fde834f..9c3d9c0 100644 --- a/nosowallcon.pas +++ b/nosowallcon.pas @@ -26,6 +26,7 @@ interface LastOP : int64; // tiempo de la ultima operacion en UnixTime. end; +Function SetWalletFileName(Fname:String):Boolean; Procedure ClearWalletArray(); function InsertToWallArr(LData:WalletData):boolean; Function GetWallArrIndex(Index:integer):WalletData; @@ -55,6 +56,19 @@ function CreateNewWallet():Boolean; IMPLEMENTATION +// Set the wallet filename; if not exists, returns false +Function SetWalletFileName(Fname:String):Boolean; +Begin + Result := true; + WalletFilename := Fname;//'NOSODATA'+DirectorySeparator+'wallet.pkw'; + if not FileExists(WalletFilename) then + begin + CreateNewWallet; + result := false; + end + else LoadWallet(WalletFilename); +End; + Procedure ClearWalletArray(); Begin EnterCriticalSection(CS_WalletArray); @@ -173,6 +187,7 @@ function InsertToWallArr(LData:WalletData):boolean; ThisData : WalletData; Begin Result := 0; + BeginPerformance('ImportAddressesFromBackup'); BakFiles := TStringList.Create; TRY FindAllFiles(BakFiles, BakFolder, '*.pkw', true); @@ -191,6 +206,7 @@ function InsertToWallArr(LData:WalletData):boolean; end; END; BakFiles.free; + EndPerformance('ImportAddressesFromBackup'); End; // Saves an address info to a specific file