Browse Source

GUI fixed code for latest core updates

Pascal Coin 3 years ago
parent
commit
4a3b8bdc57

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

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

+ 4 - 0
src/gui-classic/UFRMPayloadDecoder.dfm

@@ -272,6 +272,10 @@ object FRMPayloadDecoder: TFRMPayloadDecoder
     object tsDecodeMethods: TTabSheet
       Caption = 'Decode methods'
       ImageIndex = 1
+      ExplicitLeft = 0
+      ExplicitTop = 0
+      ExplicitWidth = 0
+      ExplicitHeight = 0
       object lblPasswordsInfo: TLabel
         Left = 235
         Top = 143

+ 6 - 42
src/gui-classic/UFRMPayloadDecoder.pas

@@ -138,10 +138,7 @@ end;
 
 procedure TFRMPayloadDecoder.DoFind(Const OpHash : String);
 Var
-  r,md160 : TRawBytes;
-  pcops : TPCOperationsComp;
-  nBlock,nAccount,nN_Operation : Cardinal;
-  opbi : Integer;
+  r : TRawBytes;
   opr : TOperationResume;
   strings : TStrings;
   FRM : TFRMMemoText;
@@ -156,46 +153,13 @@ begin
     if (Length(r)=0) then begin
       raise Exception.Create('Value is not an hexadecimal string');
     end;
-    // Build 2.1.4 new decoder option: Check if OpHash is a posible double spend
-    If not TPCOperation.DecodeOperationHash(r,nBlock,nAccount,nN_Operation,md160) then begin
-      raise Exception.Create('Value is not a valid OPHASH because can''t extract Block/Account/N_Operation info');
-    end;
-    Case TNode.Node.FindNOperation(nBlock,nAccount,nN_Operation,opr) of
-      invalid_params : raise Exception.Create(Format('Not a valid OpHash searching at Block:%d Account:%d N_Operation:%d',[nBlock,nAccount,nN_Operation]));
-      blockchain_block_not_found : raise Exception.Create('Your blockchain file does not contain all blocks to find');
-      found : ;
+    case TNode.Node.FindOperation(r,opr) of
+      OpHash_invalid_params : raise Exception.Create(Format('Not a valid OpHash %s',[OpHash]));
+      OpHash_block_not_found : raise Exception.Create('Your blockchain file does not contain all blocks to find');
+      OpHash_found : ;
     else raise Exception.Create('ERROR DEV 20171120-6');
     end;
-    If (TPCOperation.EqualOperationHashes(opr.OperationHash,r)) Or
-       (TPCOperation.EqualOperationHashes(opr.OperationHash_OLD,r)) then begin
-      // Found!
-      OpResume := opr;
-    end else begin
-      // Not found!
-      strings := TStringList.Create;
-      try
-        strings.Add('Posible double spend detected!');
-        strings.Add(Format('OpHash: %s',[OpHash]));
-        strings.Add(Format('Decode OpHash info: Block:%d Account:%s N_Operation:%d',[nBlock,TAccountComp.AccountNumberToAccountTxtNumber(nAccount),nN_Operation]));
-        strings.Add('');
-        strings.Add('Real OpHash found in PascalCoin Blockchain:');
-        strings.Add(Format('OpHash: %s',[TCrypto.ToHexaString(opr.OperationHash)]));
-        strings.Add(Format('Decode OpHash info: Block:%d Account:%s N_Operation:%d',[opr.Block,TAccountComp.AccountNumberToAccountTxtNumber(opr.SignerAccount),opr.n_operation]));
-        If (opr.Block=0) then begin
-          strings.Add('* Note: This is a pending operation not included on Blockchain');
-        end;
-        OpResume := opr; // Do show operation resume!
-        FRM := TFRMMemoText.Create(Self);
-        try
-          FRM.InitData('Posible double spend detected',strings.Text);
-          FRM.ShowModal;
-        finally
-          FRM.Free;
-        end;
-      finally
-        strings.Free;
-      end;
-    end;
+    OpResume := opr;
   Except
     OpResume := CT_TOperationResume_NUL;
     try

+ 34 - 3
src/gui-classic/UFRMWallet.dfm

@@ -377,12 +377,16 @@ object FRMWallet: TFRMWallet
     Top = 91
     Width = 865
     Height = 466
-    ActivePage = tsMyAccounts
+    ActivePage = tsMessages
     Align = alClient
     TabOrder = 2
     OnChange = PageControlChange
     object tsMyAccounts: TTabSheet
       Caption = 'Account Explorer'
+      ExplicitLeft = 0
+      ExplicitTop = 0
+      ExplicitWidth = 0
+      ExplicitHeight = 0
       object Splitter1: TSplitter
         Left = 400
         Top = 66
@@ -620,6 +624,10 @@ object FRMWallet: TFRMWallet
         TabOrder = 2
         object tsAccountOperations: TTabSheet
           Caption = 'Account Operations'
+          ExplicitLeft = 0
+          ExplicitTop = 0
+          ExplicitWidth = 0
+          ExplicitHeight = 0
           object dgAccountOperations: TDrawGrid
             Left = 0
             Top = 0
@@ -633,6 +641,10 @@ object FRMWallet: TFRMWallet
         object tsMultiSelectAccounts: TTabSheet
           Caption = 'Selected Accounts For Batch Operation'
           ImageIndex = 1
+          ExplicitLeft = 0
+          ExplicitTop = 0
+          ExplicitWidth = 0
+          ExplicitHeight = 0
           object dgSelectedAccounts: TDrawGrid
             Left = 41
             Top = 31
@@ -824,6 +836,10 @@ object FRMWallet: TFRMWallet
     object tsPendingOperations: TTabSheet
       Caption = 'Pending Operations'
       ImageIndex = 5
+      ExplicitLeft = 0
+      ExplicitTop = 0
+      ExplicitWidth = 0
+      ExplicitHeight = 0
       object dgPendingOperations: TDrawGrid
         Left = 0
         Top = 86
@@ -870,6 +886,10 @@ object FRMWallet: TFRMWallet
     object tsBlockChain: TTabSheet
       Caption = 'Block Explorer'
       ImageIndex = 1
+      ExplicitLeft = 0
+      ExplicitTop = 0
+      ExplicitWidth = 0
+      ExplicitHeight = 0
       object Panel2: TPanel
         Left = 0
         Top = 0
@@ -962,6 +982,10 @@ object FRMWallet: TFRMWallet
     object tsOperations: TTabSheet
       Caption = 'Operations Explorer'
       ImageIndex = 1
+      ExplicitLeft = 0
+      ExplicitTop = 0
+      ExplicitWidth = 0
+      ExplicitHeight = 0
       object Panel1: TPanel
         Left = 0
         Top = 0
@@ -1010,6 +1034,10 @@ object FRMWallet: TFRMWallet
     object tsLogs: TTabSheet
       Caption = 'Logs'
       ImageIndex = 2
+      ExplicitLeft = 0
+      ExplicitTop = 0
+      ExplicitWidth = 0
+      ExplicitHeight = 0
       object pnlTopLogs: TPanel
         Left = 0
         Top = 0
@@ -1041,6 +1069,10 @@ object FRMWallet: TFRMWallet
     object tsNodeStats: TTabSheet
       Caption = 'Node Stats'
       ImageIndex = 3
+      ExplicitLeft = 0
+      ExplicitTop = 0
+      ExplicitWidth = 0
+      ExplicitHeight = 0
       DesignSize = (
         857
         438)
@@ -1188,8 +1220,7 @@ object FRMWallet: TFRMWallet
         Font.Name = 'Tahoma'
         Font.Style = []
         Lines.Strings = (
-          'dsfa '#195#177'ldsaf '#195#177'lk dasf'
-          'dsfklda'#195#177'fs '#195#177'l')
+          '(messages)')
         ParentFont = False
         ReadOnly = True
         ScrollBars = ssBoth

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

@@ -243,11 +243,11 @@ type
     Procedure InitMenuForTesting;
     {$IFDEF TESTNET}
     Procedure Test_RandomOperations(Sender: TObject);
+    Procedure Test_ConnectDisconnect(Sender: TObject);
+    {$ENDIF}
     {$IFDEF TESTING_NO_POW_CHECK}
     Procedure Test_CreateABlock(Sender: TObject);
     {$ENDIF}
-    Procedure Test_ConnectDisconnect(Sender: TObject);
-    {$ENDIF}
     Procedure Test_ShowPublicKeys(Sender: TObject);
     Procedure Test_ShowOperationsInMemory(Sender: TObject);
     Procedure Test_FindAccountsForPrivateBuyOrSwapToMe(Sender : TObject);
@@ -452,9 +452,9 @@ begin
     WalletKeys.SafeBox := FNode.Bank.SafeBox;
     // Check Database
     FNode.Bank.StorageClass := TFileStorage;
-    TFileStorage(FNode.Bank.Storage).DatabaseFolder := TNode.GetPascalCoinDataFolder+PathDelim+'Data';
-    TFileStorage(FNode.Bank.Storage).Initialize;
+    FNode.Bank.Storage.Initialize;
     // Init Grid
+
     FSelectedAccountsGrid.Node := FNode;
     FWalletKeys.OnChanged.Add( OnWalletChanged );
     FAccountsGrid.Node := FNode;
@@ -1421,6 +1421,9 @@ begin
   InitMacOSMenu;
   {$endif}
   PageControl.ActivePageIndex := 0;
+  {$IFDEF DEBUG}
+  System.ReportMemoryLeaksOnShutdown := True; // Delphi memory leaks testing
+  {$ENDIF}
 end;
 
 procedure TFRMWallet.ebHashRateBackBlocksKeyPress(Sender: TObject; var Key: char);
@@ -1663,12 +1666,12 @@ begin
     if PageControl.ActivePage=tsOperations then begin
       i := FOperationsExplorerGrid.DrawGrid.Row;
       if (i>0) and (i<=FOperationsExplorerGrid.OperationsResume.Count) then begin
-        opr := FOperationsExplorerGrid.OperationsResume.OperationResume[i-1];
+        opr := FOperationsExplorerGrid.OperationsResume.Items[i-1];
       end;
     end else if PageControl.ActivePage=tsPendingOperations then begin
       i := FPendingOperationsGrid.DrawGrid.Row;
       if (i>0) and (i<=FPendingOperationsGrid.OperationsResume.Count) then begin
-        opr := FPendingOperationsGrid.OperationsResume.OperationResume[i-1];
+        opr := FPendingOperationsGrid.OperationsResume.Items[i-1];
       end;
     end else if PageControl.ActivePage=tsMyAccounts then begin
       accn := FAccountsGrid.AccountNumber(dgAccounts.Row);
@@ -1677,7 +1680,7 @@ begin
       title := 'Account '+TAccountComp.AccountNumberToAccountTxtNumber(accn)+' info';
       i := FOperationsAccountGrid.DrawGrid.Row;
       if (i>0) and (i<=FOperationsAccountGrid.OperationsResume.Count) then begin
-        opr := FOperationsAccountGrid.OperationsResume.OperationResume[i-1];
+        opr := FOperationsAccountGrid.OperationsResume.Items[i-1];
       end;
     end;
     If (opr.valid) then begin

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

@@ -1065,7 +1065,7 @@ begin
         Finally
           list.Free;
         End;
-        ANode.GetStoredOperationsFromAccount(Self,AList,FOperationsGrid.AccountNumber,100,0,5000);
+        ANode.Bank.Storage.GetAccountOperations(FOperationsGrid.AccountNumber,-1,0,5000,0,AList);
       end;
     end;
   Finally
@@ -1182,7 +1182,7 @@ begin
     DrawGrid.Canvas.FillRect(Rect);
     InflateRect(Rect,-2,-1);
     if (ARow<=FOperationsResume.Count) then begin
-      opr := FOperationsResume.OperationResume[ARow-1];
+      opr := FOperationsResume.Items[ARow-1];
       If (opr.AffectedAccount=opr.SignerAccount) then begin
       end else begin
         if (gdSelected in State) or (gdFocused in State) then begin
@@ -1370,7 +1370,7 @@ begin
     Result := CT_TOperationResume_NUL;
     exit;
   end;
-  Result := FOperationsResume.OperationResume[FDrawGrid.Row-1];
+  Result := FOperationsResume.Items[FDrawGrid.Row-1];
 end;
 
 procedure TOperationsGrid.ShowModalDecoder(WalletKeys: TWalletKeys; AppParams : TAppParams);
@@ -1380,7 +1380,7 @@ Var i : Integer;
 begin
   if Not Assigned(FDrawGrid) then exit;
   if (FDrawGrid.Row<=0) Or (FDrawGrid.Row>FOperationsResume.Count) then exit;
-  opr := FOperationsResume.OperationResume[FDrawGrid.Row-1];
+  opr := FOperationsResume.Items[FDrawGrid.Row-1];
   FRM := TFRMPayloadDecoder.Create(FDrawGrid.Owner);
   try
     FRM.Init(opr,WalletKeys,AppParams);
@@ -1464,17 +1464,16 @@ begin
 end;
 
 procedure TBlockChainGridUpdateThread.DoUpdateBlockChainGrid(ANode: TNode; var AList: TList<TBlockChainData>; ABlockStart, ABlockEnd : Int64);
-Var opc : TPCOperationsComp;
+Var //opc : TPCOperationsComp;
   bcd : TBlockChainData;
   opb : TOperationBlock;
   bn : TBigNum;
 begin
-  opc := TPCOperationsComp.Create(Nil);
-  try
-    opc.bank := ANode.Bank;
     while (ABlockStart<=ABlockEnd) and (Not Terminated) do begin
       bcd := CT_TBlockChainData_NUL;
-      opb := ANode.Bank.SafeBox.GetBlockInfo(ABlockEnd);
+      if Not ANode.Bank.Storage.GetBlockInformation(ABlockEnd,opb,bcd.OperationsCount,bcd.Volume) then begin
+        opb := ANode.Bank.SafeBox.GetBlockInfo(ABlockEnd);
+      end;
       bcd.Block:=opb.block;
       bcd.Timestamp := opb.timestamp;
       bcd.BlockProtocolVersion := opb.protocol_version;
@@ -1500,10 +1499,6 @@ begin
       bcd.PoW := opb.proof_of_work;
       bcd.SafeBoxHash := opb.initial_safe_box_hash;
       if (Not Terminated) then begin
-        If (ANode.Bank.LoadOperations(opc,ABlockEnd)) then begin
-          bcd.OperationsCount := opc.Count;
-          bcd.Volume := opc.OperationsHashTree.TotalAmount + opc.OperationsHashTree.TotalFee;
-        end;
         bcd.TimeAverage200:=ANode.Bank.GetTargetSecondsAverage(bcd.Block,200);
         bcd.TimeAverage150:=ANode.Bank.GetTargetSecondsAverage(bcd.Block,150);
         bcd.TimeAverage100:=ANode.Bank.GetTargetSecondsAverage(bcd.Block,100);
@@ -1516,9 +1511,6 @@ begin
         if (ABlockEnd>0) then dec(ABlockEnd) else Break;
       end;
     end;
-  finally
-    opc.Free;
-  end;
 end;
 
 { TBlockChainGrid }