Browse Source

Forced GUI update caused by abstractmem usage

PascalCoin 5 years ago
parent
commit
95ead7bd5f

+ 1 - 0
src/gui-classic/UFRMAccountSelect.pas

@@ -28,6 +28,7 @@ uses
 {$ELSE}
   LCLIntf, LCLType, LMessages,
 {$ENDIF}
+  UPCDataTypes,
   Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, UAccounts, Grids, StdCtrls, Buttons, ExtCtrls, UWallet, UNode,
   UGridUtils, UConst, UThread, UPCOrderedLists, UBaseTypes;

+ 2 - 2
src/gui-classic/UFRMOperation.pas

@@ -32,7 +32,7 @@ uses
   Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, StdCtrls, UNode, UWallet, UCrypto, Buttons, UBlockChain,
   UAccounts, UFRMAccountSelect, ActnList, ComCtrls, Types, UFRMMemoText,
-  UPCEncryption, UBaseTypes, UPCOrderedLists;
+  UPCEncryption, UBaseTypes, UPCDataTypes, UPCOrderedLists;
 
 Const
   CM_PC_WalletKeysChanged = WM_USER + 1;
@@ -192,7 +192,7 @@ implementation
 
 uses
   UConst, UOpTransaction, UFRMNewPrivateKeyType, UFRMWalletKeys, UFRMHashLock,
-  UCommon, UPCDataTypes, ULog, UGUIUtils;
+  UCommon, ULog, UGUIUtils;
 
 {$IFnDEF FPC}
   {$R *.dfm}

+ 1 - 1
src/gui-classic/UFRMOperationsExplorer.pas

@@ -132,7 +132,7 @@ Uses
 {$IFDEF TESTNET}
    UFRMRandomOperations,
 {$ENDIF}
-   UFRMRPCCalls, UFRMMemoText;
+   UPCDataTypes, UFRMRPCCalls, UFRMMemoText;
 
 
 { TFRMOperationsExplorer }

+ 2 - 0
src/gui-classic/UFRMRandomOperations.pas

@@ -129,6 +129,8 @@ implementation
   {$R *.lfm}
 {$ENDIF}
 
+uses UPCDataTypes;
+
 { TRandomGeneratorThread }
 
 procedure TRandomGeneratorThread.OnBankNewBlock(Sender: TObject);

+ 7 - 2
src/gui-classic/UFRMWallet.pas

@@ -34,7 +34,7 @@ uses
   ExtCtrls, ComCtrls, UWallet, StdCtrls, ULog, Grids, UAppParams, UBlockChain,
   UNode, UGridUtils, UJSONFunctions, UAccounts, Menus, ImgList, UNetProtocol,
   UCrypto, Buttons, UPoolMining, URPC, UFRMAccountSelect, UConst,
-  UAccountKeyStorage, UBaseTypes, UPCDataTypes,
+  UAccountKeyStorage, UBaseTypes, UPCDataTypes, UOrderedList,
   UFRMRPCCalls, UTxMultiOperation,
   {$IFNDEF FPC}System.Generics.Collections{$ELSE}Generics.Collections{$ENDIF};
 
@@ -338,6 +338,7 @@ Uses UFolderHelper,
   UPCTNetDataExtraMessages,
   UFRMDiagnosticTool,
   {$ENDIF}
+  UAbstractBTree,
   UFRMAbout, UFRMOperation, UFRMWalletKeys, UFRMPayloadDecoder, UFRMNodesIp, UFRMMemoText,
   USettings, UCommon, UPCOrderedLists;
 
@@ -393,6 +394,8 @@ begin
     ExtractFileDir(Application.ExeName)+PathDelim+CT_Hardcoded_RandomHash_Table_Filename,
     LRaw );
   {$ENDIF}
+  FLastTC := 0;
+  OnProgressNotify(Self,'Initializing databases',0,0);
   // Read Operations saved from disk
   TNode.Node.InitSafeboxAndOperations($FFFFFFFF,OnProgressNotify); // New Build 2.1.4 to load pending operations buffer
   TNode.Node.AutoDiscoverNodes(CT_Discover_IPs);
@@ -1207,6 +1210,7 @@ begin
           TCrypto.ToHexaString(TAccountComp.AccountKey2RawString(acc.accountInfo.new_publicKey))]));
       end;
     end;
+    {$IFnDEF USE_ABSTRACTMEM}
     l := TAccountKeyStorage.KS.LockList;
     try
       sl.Add(Format('%d public keys in TAccountKeyStorage data',[l.count]));
@@ -1240,6 +1244,7 @@ begin
         ak.EC_OpenSSL_NID,
         TCrypto.ToHexaString(TAccountComp.AccountKey2RawString(ak)) ]));
     end;
+    {$ENDIF}
     F := TFRMMemoText.Create(Self);
     try
       F.InitData('Keys in safebox',sl.Text);
@@ -2558,7 +2563,7 @@ begin
     FLog.OnNewLog := Nil;
     if PageControl.ActivePage = tsLogs then PageControl.ActivePage := tsMyAccounts;
   end else FLog.OnNewLog := OnNewLog;
-  if FAppParams.ParamByName[CT_PARAM_SaveLogFiles].GetAsBoolean(false) then begin
+  if (FAppParams.ParamByName[CT_PARAM_SaveLogFiles].GetAsBoolean(false)) then begin
     if FAppParams.ParamByName[CT_PARAM_SaveDebugLogs].GetAsBoolean(false) then FLog.SaveTypes := CT_TLogTypes_ALL
     else FLog.SaveTypes := CT_TLogTypes_DEFAULT;
     FLog.FileName := TNode.GetPascalCoinDataFolder+PathDelim+'PascalCointWallet.log';

+ 6 - 2
src/gui-classic/UFRMWalletKeys.pas

@@ -96,7 +96,7 @@ uses
   LCLIntf, LCLType,
 {$ENDIF}
   UCrypto, UAccounts, UFRMNewPrivateKeyType, UBaseTypes, UPCEncryption,
-  UCommon, UGUIUtils;
+  UPCDataTypes, UCommon, UGUIUtils;
 
 {$IFnDEF FPC}
   {$R *.dfm}
@@ -580,6 +580,7 @@ procedure TFRMWalletKeys.UpdateWalletKeys;
 Var lasti,i,j : Integer;
   selected_wk,wk : TWalletKey;
   s : AnsiString;
+  Lanl : TAccountsNumbersList;
 begin
   GetSelectedWalletKeyAndIndex(wk,lasti);
   lbWalletKeys.Items.BeginUpdate;
@@ -608,7 +609,10 @@ begin
       if (WalletKeys is TWalletKeysExt) then begin
         j := TWalletKeysExt(WalletKeys).AccountsKeyList.IndexOfAccountKey(wk.AccountKey);
         if (j>=0) then begin
-          s := s+' ('+IntToStr(TWalletKeysExt(WalletKeys).AccountsKeyList.AccountKeyList[j].Count)+' Accounts)';
+          Lanl := TWalletKeysExt(WalletKeys).AccountsKeyList.AccountKeyList[j];
+          if Assigned(Lanl) then begin
+            s := s+' ('+IntToStr(Lanl.Count)+' Accounts)';
+          end else s := s+' (No Accounts)';
         end;
       end;
       if Not Assigned(wk.PrivateKey) then begin

+ 36 - 14
src/gui-classic/UGridUtils.pas

@@ -30,7 +30,7 @@ uses
 {$ELSE}
   LCLIntf, LCLType, LMessages,
 {$ENDIF}
-  Classes, Grids, UNode, UAccounts, UBlockChain, UAppParams, UThread,
+  Classes, Grids, UNode, UAccounts, UBlockChain, UAppParams, UThread, UPCDataTypes,
   UWallet, UCrypto, UPoolMining, URPC, UBaseTypes, UPCOrderedLists,
   {$IFNDEF FPC}System.Generics.Collections{$ELSE}Generics.Collections{$ENDIF};
 
@@ -289,8 +289,8 @@ uses
 
 procedure TAccountsGridUpdateThread.BCExecute;
 Var
-  l : TOrderedCardinalList;
-  i,j : Integer;
+  l : TAccountsNumbersList;
+  i,j, j_min, j_max : Integer;
   c  : Cardinal;
   LApplyfilter : Boolean;
   LAccount : TAccount;
@@ -307,26 +307,44 @@ begin
         while (Not Terminated) and (i<FAccountsGridFilter.OrderedAccountsKeyList.Count)
           and ((FAccountsGridFilter.indexAccountsKeyList<0) or (FAccountsGridFilter.indexAccountsKeyList=i)) do begin
 
+          j_min := 0;
+
+          while (j_min>=0) do begin
+
           LNode.bank.SafeBox.StartThreadSafe;
           FAccountsGridFilter.OrderedAccountsKeyList.Lock; // Protection v4
           Try
             l := FAccountsGridFilter.OrderedAccountsKeyList.AccountKeyList[i];
-            for j := 0 to l.Count - 1 do begin
-              LAccount := LNode.Bank.SafeBox.Account(l.Get(j));
-              if LApplyfilter then begin
-                if (LAccount.balance>=FAccountsGridFilter.MinBalance) And ((FAccountsGridFilter.MaxBalance<0) Or (LAccount.balance<=FAccountsGridFilter.MaxBalance)) then begin
+            if Assigned(l) then begin
+
+              j_max := (j_min + 500);
+              if j_max>=l.Count then j_max := l.Count-1;
+
+              for j := j_min to j_max do begin
+                LAccount := LNode.Bank.SafeBox.Account(l.Get(j));
+                if LApplyfilter then begin
+                  if (LAccount.balance>=FAccountsGridFilter.MinBalance) And ((FAccountsGridFilter.MaxBalance<0) Or (LAccount.balance<=FAccountsGridFilter.MaxBalance)) then begin
+                    FProcessedList.Add(LAccount.account);
+                    FBalance := FBalance + LAccount.balance;
+                  end;
+                end else begin
                   FProcessedList.Add(LAccount.account);
                   FBalance := FBalance + LAccount.balance;
                 end;
-              end else begin
-                FProcessedList.Add(LAccount.account);
-                FBalance := FBalance + LAccount.balance;
+                if Terminated then Exit;
+              end;
+              j_min := j_max+1;
+              if (j_max>=(l.Count-1)) then begin
+                j_min := -1;
+                break;
               end;
-              if Terminated then Exit;
             end;
           finally
             FAccountsGridFilter.OrderedAccountsKeyList.Unlock;
             LNode.Bank.SafeBox.EndThreadSave;
+          end;
+            if j_max>=0 then Sleep(0);
+
           end;
           inc(i);
         end;
@@ -342,10 +360,10 @@ begin
         end;
       end;
   Finally
-    FisProcessing := False;
     if Not Terminated then begin
       Synchronize(SynchronizedOnTerminated);
     end;
+    FisProcessing := False;
   End;
 end;
 
@@ -377,6 +395,7 @@ begin
     finally
       FAccountsGrid.UnlockAccountsList;
     end;
+    FisProcessing := False;
     if Assigned(FAccountsGrid.FOnAccountsGridUpdatedData) then  FAccountsGrid.FOnAccountsGridUpdatedData(FAccountsGrid);
   end;
 end;
@@ -860,7 +879,10 @@ begin
   LTmp := FAccountsGridUpdateThread;
   FAccountsGridUpdateThread := Nil;
   if Assigned(Ltmp) then begin
-    if Not AWaitUntilTerminated then LTmp.FreeOnTerminate := True;
+    if Not LTmp.IsProcessing then AWaitUntilTerminated := True;
+    if Not AWaitUntilTerminated then begin
+      LTmp.FreeOnTerminate := True;
+    end;
     LTmp.Terminate;
     if AWaitUntilTerminated then begin
       LTmp.WaitFor;
@@ -896,10 +918,10 @@ end;
 procedure TAccountsGrid.UpdateData;
 begin
   UpdateAccountsBalance;
+  TerminateAccountGridUpdateThread(False);
   if Assigned(Node) then begin
     case FAccountsGridDatasource of
       acds_NodeFiltered: begin
-        TerminateAccountGridUpdateThread(False);
         FAccountsBalance := 0;
         FAccountsGridUpdateThread := TAccountsGridUpdateThread.Create(Self,AccountsGridFilter);
       end;