瀏覽代碼

TList to TList<T> - gui-classic

Use of TList<T> and some minor changes
PascalCoin 6 年之前
父節點
當前提交
f6f1444c77

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

@@ -29,7 +29,8 @@ uses
   {$ENDIF}
   {$ENDIF}
   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
   Menus, ActnList, UAccounts, UBlockChain, UNode, UCrypto, UBaseTypes,
   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
 type
@@ -660,7 +661,7 @@ procedure TFRMOperationsExplorer.UpdateSelectedOperationInfo;
 Var op : TPCOperation;
 Var op : TPCOperation;
   opht : TOperationsHashTree;
   opht : TOperationsHashTree;
   i : Integer;
   i : Integer;
-  l : TList;
+  l : TList<Cardinal>;
   aux : String;
   aux : String;
   raw : TRawBytes;
   raw : TRawBytes;
   ms : TMemoryStream;
   ms : TMemoryStream;
@@ -678,7 +679,7 @@ begin
     mOperationInfo.Lines.Add(Format('%s',[op.ToString]));
     mOperationInfo.Lines.Add(Format('%s',[op.ToString]));
     mOperationInfo.Lines.Add('');
     mOperationInfo.Lines.Add('');
     mOperationInfo.Lines.Add(Format('OpType:%d ClassName:%s',[op.OpType,op.ClassName]));
     mOperationInfo.Lines.Add(Format('OpType:%d ClassName:%s',[op.OpType,op.ClassName]));
-    l := TList.Create;
+    l := TList<Cardinal>.Create;
     Try
     Try
       op.AffectedAccounts(l); aux := '';
       op.AffectedAccounts(l); aux := '';
       For i:=0 to l.Count-1 do begin
       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,
   UNode, UGridUtils, UJSONFunctions, UAccounts, Menus, ImgList, UNetProtocol,
   UCrypto, Buttons, UPoolMining, URPC, UFRMAccountSelect, UConst,
   UCrypto, Buttons, UPoolMining, URPC, UFRMAccountSelect, UConst,
   UAccountKeyStorage, UBaseTypes, UPCDataTypes,
   UAccountKeyStorage, UBaseTypes, UPCDataTypes,
-  UFRMRPCCalls, UTxMultiOperation;
+  UFRMRPCCalls, UTxMultiOperation,
+  {$IFNDEF FPC}System.Generics.Collections{$ELSE}Generics.Collections{$ENDIF};
 
 
 Const
 Const
   CM_PC_WalletKeysChanged = WM_USER + 1;
   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');
 Const CT_BooleanToString : Array[Boolean] of String = ('False','True');
 Var i : integer;
 Var i : integer;
  NC : TNetConnection;
  NC : TNetConnection;
- l : TList;
+ l : TList<TNetConnection>;
  sClientApp, sLastConnTime : String;
  sClientApp, sLastConnTime : String;
  strings, sNSC, sRS, sDisc : TStrings;
  strings, sNSC, sRS, sDisc : TStrings;
  hh,nn,ss,ms : Word;
  hh,nn,ss,ms : Word;
@@ -984,7 +985,7 @@ var F : TFRMMemoText;
   sl : TStrings;
   sl : TStrings;
   ak : TAccountKey;
   ak : TAccountKey;
   nmin,nmax : Integer;
   nmin,nmax : Integer;
-  l : TList;
+  l : TList<Pointer>;
   Pacsd : PAccountKeyStorageData;
   Pacsd : PAccountKeyStorageData;
   acc : TAccount;
   acc : TAccount;
 begin
 begin
@@ -1630,7 +1631,7 @@ procedure TFRMWallet.OnNetBlackListUpdated(Sender: TObject);
 Const CT_TRUE_FALSE : Array[Boolean] Of AnsiString = ('FALSE','TRUE');
 Const CT_TRUE_FALSE : Array[Boolean] Of AnsiString = ('FALSE','TRUE');
 Var i,j,n : integer;
 Var i,j,n : integer;
  P : PNodeServerAddress;
  P : PNodeServerAddress;
- l : TList;
+ l : TList<Pointer>;
  strings : TStrings;
  strings : TStrings;
 begin
 begin
   l := TNetData.NetData.NodeServersAddresses.LockList;
   l := TNetData.NetData.NodeServersAddresses.LockList;
@@ -1673,7 +1674,7 @@ end;
 procedure TFRMWallet.OnNetNodeServersUpdated(Sender: TObject);
 procedure TFRMWallet.OnNetNodeServersUpdated(Sender: TObject);
 Var i : integer;
 Var i : integer;
  P : PNodeServerAddress;
  P : PNodeServerAddress;
- l : TList;
+ l : TList<Pointer>;
  strings : TStrings;
  strings : TStrings;
  s : String;
  s : String;
 begin
 begin
@@ -2054,7 +2055,7 @@ end;
 procedure TFRMWallet.UpdateAvailableConnections;
 procedure TFRMWallet.UpdateAvailableConnections;
 Var i : integer;
 Var i : integer;
  NC : TNetConnection;
  NC : TNetConnection;
- l : TList;
+ l : TList<TNetConnection>;
 begin
 begin
   if Not TNetData.NetData.NetConnections.TryLockList(100,l) then exit;
   if Not TNetData.NetData.NetConnections.TryLockList(100,l) then exit;
   try
   try
@@ -2085,15 +2086,12 @@ end;
 
 
 procedure TFRMWallet.UpdateBlockChainState;
 procedure TFRMWallet.UpdateBlockChainState;
 Var isMining : boolean;
 Var isMining : boolean;
-//  hr : Int64;
   i,mc : Integer;
   i,mc : Integer;
   s : String;
   s : String;
-  mtl : TList;
   f, favg : real;
   f, favg : real;
 begin
 begin
   UpdateNodeStatus;
   UpdateNodeStatus;
   mc := 0;
   mc := 0;
-//  hr := 0;
   if Assigned(FNode) then begin
   if Assigned(FNode) then begin
     if FNode.Bank.BlocksCount>0 then begin
     if FNode.Bank.BlocksCount>0 then begin
       lblCurrentBlock.Caption :=  Inttostr(FNode.Bank.BlocksCount)+' (0..'+Inttostr(FNode.Bank.BlocksCount-1)+')'; ;
       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}
 {$ELSE}
   LCLIntf, LCLType,
   LCLIntf, LCLType,
 {$ENDIF}
 {$ENDIF}
-  UCrypto, UAccounts, UFRMNewPrivateKeyType, UAES, UBaseTypes, UCommon, UGUIUtils;
+  UCrypto, UAccounts, UFRMNewPrivateKeyType, UBaseTypes, UPCEncryption,
+  UCommon, UGUIUtils;
 
 
 {$IFnDEF FPC}
 {$IFnDEF FPC}
   {$R *.dfm}
   {$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','Insert a password to export',pwd1) then begin
       if InputQueryPassword('Export private key','Repeat the password to export',pwd2) 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!');
         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;
         Clipboard.AsText := enc;
         Application.MessageBox(PChar('The password has been encrypted with your password and copied to the clipboard.'+
         Application.MessageBox(PChar('The password has been encrypted with your password and copied to the clipboard.'+
           #10+#10+
           #10+#10+
@@ -294,12 +295,14 @@ var s : String;
   end;
   end;
 
 
   function ParseEncryptedKey : boolean;
   function ParseEncryptedKey : boolean;
+  var LRawPassword : TRawBytes;
   begin
   begin
       Repeat
       Repeat
         s := '';
         s := '';
         desenc := Nil;
         desenc := Nil;
         if InputQueryPassword('Import private key','Enter the password:',s) then begin
         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
             if Length(desenc)>0 then begin
               EC := TECPrivateKey.ImportFromRaw(desenc);
               EC := TECPrivateKey.ImportFromRaw(desenc);
               ParseEncryptedKey := True;
               ParseEncryptedKey := True;

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

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