Przeglądaj źródła

TList to TList<T> - gui-classic

Use of TList<T> and some minor changes
PascalCoin 6 lat temu
rodzic
commit
f6f1444c77

+ 4 - 3
src/gui-classic/UFRMOperationsExplorer.pas

@@ -29,7 +29,8 @@ uses
   {$ENDIF}
   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
   Menus, ActnList, UAccounts, UBlockChain, UNode, UCrypto, UBaseTypes,
-  UFileStorage, UWallet, UConst, UTxMultiOperation, UOpTransaction, URPC, UJSONFunctions;
+  UFileStorage, UWallet, UConst, UTxMultiOperation, UOpTransaction, URPC,
+  {$IFNDEF FPC}System.Generics.Collections{$ELSE}Generics.Collections{$ENDIF}, UJSONFunctions;
 
 
 type
@@ -660,7 +661,7 @@ procedure TFRMOperationsExplorer.UpdateSelectedOperationInfo;
 Var op : TPCOperation;
   opht : TOperationsHashTree;
   i : Integer;
-  l : TList;
+  l : TList<Cardinal>;
   aux : String;
   raw : TRawBytes;
   ms : TMemoryStream;
@@ -678,7 +679,7 @@ begin
     mOperationInfo.Lines.Add(Format('%s',[op.ToString]));
     mOperationInfo.Lines.Add('');
     mOperationInfo.Lines.Add(Format('OpType:%d ClassName:%s',[op.OpType,op.ClassName]));
-    l := TList.Create;
+    l := TList<Cardinal>.Create;
     Try
       op.AffectedAccounts(l); aux := '';
       For i:=0 to l.Count-1 do begin

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

@@ -35,7 +35,8 @@ uses
   UNode, UGridUtils, UJSONFunctions, UAccounts, Menus, ImgList, UNetProtocol,
   UCrypto, Buttons, UPoolMining, URPC, UFRMAccountSelect, UConst,
   UAccountKeyStorage, UBaseTypes, UPCDataTypes,
-  UFRMRPCCalls, UTxMultiOperation;
+  UFRMRPCCalls, UTxMultiOperation,
+  {$IFNDEF FPC}System.Generics.Collections{$ELSE}Generics.Collections{$ENDIF};
 
 Const
   CM_PC_WalletKeysChanged = WM_USER + 1;
@@ -578,7 +579,7 @@ procedure TFRMWallet.CM_NetConnectionUpdated(var Msg: TMessage);
 Const CT_BooleanToString : Array[Boolean] of String = ('False','True');
 Var i : integer;
  NC : TNetConnection;
- l : TList;
+ l : TList<TNetConnection>;
  sClientApp, sLastConnTime : String;
  strings, sNSC, sRS, sDisc : TStrings;
  hh,nn,ss,ms : Word;
@@ -984,7 +985,7 @@ var F : TFRMMemoText;
   sl : TStrings;
   ak : TAccountKey;
   nmin,nmax : Integer;
-  l : TList;
+  l : TList<Pointer>;
   Pacsd : PAccountKeyStorageData;
   acc : TAccount;
 begin
@@ -1630,7 +1631,7 @@ procedure TFRMWallet.OnNetBlackListUpdated(Sender: TObject);
 Const CT_TRUE_FALSE : Array[Boolean] Of AnsiString = ('FALSE','TRUE');
 Var i,j,n : integer;
  P : PNodeServerAddress;
- l : TList;
+ l : TList<Pointer>;
  strings : TStrings;
 begin
   l := TNetData.NetData.NodeServersAddresses.LockList;
@@ -1673,7 +1674,7 @@ end;
 procedure TFRMWallet.OnNetNodeServersUpdated(Sender: TObject);
 Var i : integer;
  P : PNodeServerAddress;
- l : TList;
+ l : TList<Pointer>;
  strings : TStrings;
  s : String;
 begin
@@ -2054,7 +2055,7 @@ end;
 procedure TFRMWallet.UpdateAvailableConnections;
 Var i : integer;
  NC : TNetConnection;
- l : TList;
+ l : TList<TNetConnection>;
 begin
   if Not TNetData.NetData.NetConnections.TryLockList(100,l) then exit;
   try
@@ -2085,15 +2086,12 @@ end;
 
 procedure TFRMWallet.UpdateBlockChainState;
 Var isMining : boolean;
-//  hr : Int64;
   i,mc : Integer;
   s : String;
-  mtl : TList;
   f, favg : real;
 begin
   UpdateNodeStatus;
   mc := 0;
-//  hr := 0;
   if Assigned(FNode) then begin
     if FNode.Bank.BlocksCount>0 then begin
       lblCurrentBlock.Caption :=  Inttostr(FNode.Bank.BlocksCount)+' (0..'+Inttostr(FNode.Bank.BlocksCount-1)+')'; ;

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

@@ -95,7 +95,8 @@ uses
 {$ELSE}
   LCLIntf, LCLType,
 {$ENDIF}
-  UCrypto, UAccounts, UFRMNewPrivateKeyType, UAES, UBaseTypes, UCommon, UGUIUtils;
+  UCrypto, UAccounts, UFRMNewPrivateKeyType, UBaseTypes, UPCEncryption,
+  UCommon, UGUIUtils;
 
 {$IFnDEF FPC}
   {$R *.dfm}
@@ -170,7 +171,7 @@ begin
     if InputQueryPassword('Export private key','Insert a password to export',pwd1) then begin
       if InputQueryPassword('Export private key','Repeat the password to export',pwd2) then begin
         if pwd1<>pwd2 then raise Exception.Create('Passwords does not match!');
-        enc := TCrypto.ToHexaString( TAESComp.EVP_Encrypt_AES256( wk.PrivateKey.ExportToRaw,TEncoding.ANSI.GetBytes(pwd1)) );
+        enc := TPCEncryption.DoPascalCoinAESEncrypt(wk.PrivateKey.ExportToRaw,TEncoding.ANSI.GetBytes(pwd1)).ToHexaString;
         Clipboard.AsText := enc;
         Application.MessageBox(PChar('The password has been encrypted with your password and copied to the clipboard.'+
           #10+#10+
@@ -294,12 +295,14 @@ var s : String;
   end;
 
   function ParseEncryptedKey : boolean;
+  var LRawPassword : TRawBytes;
   begin
       Repeat
         s := '';
         desenc := Nil;
         if InputQueryPassword('Import private key','Enter the password:',s) then begin
-          If (TAESComp.EVP_Decrypt_AES256(enc,s,desenc)) then begin
+          LRawPassword.FromString(s);
+          if TPCEncryption.DoPascalCoinAESDecrypt(enc,LRawPassword,desenc) then begin
             if Length(desenc)>0 then begin
               EC := TECPrivateKey.ImportFromRaw(desenc);
               ParseEncryptedKey := True;

+ 8 - 8
src/gui-classic/UGridUtils.pas

@@ -31,7 +31,8 @@ uses
   LCLIntf, LCLType, LMessages,
 {$ENDIF}
   Classes, Grids, UNode, UAccounts, UBlockChain, UAppParams,
-  UWallet, UCrypto, UPoolMining, URPC, UBaseTypes, UPCOrderedLists;
+  UWallet, UCrypto, UPoolMining, URPC, UBaseTypes, UPCOrderedLists,
+  {$IFNDEF FPC}System.Generics.Collections{$ELSE}Generics.Collections{$ENDIF};
 
 Type
   // TAccountsGrid implements a visual integration of TDrawGrid
@@ -781,17 +782,16 @@ begin
 end;
 
 procedure TOperationsGrid.OnNodeNewOperation(Sender: TObject);
-Var //Op : TPCOperation;
-  l : TList;
+Var l : TList<Cardinal>;
 begin
   Try
     if (AccountNumber<0) then begin
       If (FPendingOperations) then UpdateAccountOperations;
     end else begin
-      l := TList.Create;
+      l := TList<Cardinal>.Create;
       Try
         If Node.Operations.OperationsHashTree.GetOperationsAffectingAccount(AccountNumber,l)>0 then begin
-          if l.IndexOf(TObject(PtrInt(AccountNumber)))>=0 then UpdateAccountOperations;
+          if l.IndexOf(AccountNumber)>=0 then UpdateAccountOperations;
         end;
       Finally
         l.Free;
@@ -897,7 +897,7 @@ begin
 end;
 
 procedure TOperationsGrid.UpdateAccountOperations;
-Var list : TList;
+Var list : TList<Cardinal>;
   i,j : Integer;
   OPR : TOperationResume;
   Op : TPCOperation;
@@ -965,11 +965,11 @@ begin
         end;
 
       end else begin
-        list := TList.Create;
+        list := TList<Cardinal>.Create;
         Try
           Node.Operations.OperationsHashTree.GetOperationsAffectingAccount(AccountNumber,list);
           for i := list.Count - 1 downto 0 do begin
-            Op := Node.Operations.OperationsHashTree.GetOperation(PtrInt(list[i]));
+            Op := Node.Operations.OperationsHashTree.GetOperation((list[i]));
             If TPCOperation.OperationToOperationResume(0,Op,False,AccountNumber,OPR) then begin
               OPR.NOpInsideBlock := i;
               OPR.Block := Node.Operations.OperationBlock.block;