Browse Source

Merge downstream

Herman Schoenfeld 7 years ago
parent
commit
4ae325d249
3 changed files with 244 additions and 69 deletions
  1. 1 1
      src/core.utils/UDataSources.pas
  2. 35 25
      src/gui/UFRMOperationExplorer.lfm
  3. 208 43
      src/gui/UFRMOperationExplorer.pas

+ 1 - 1
src/core.utils/UDataSources.pas

@@ -425,7 +425,7 @@ begin
     opr := CT_TOperationResume_NUL;
     opr := CT_TOperationResume_NUL;
     if (Node.Bank.Storage.LoadBlockChainBlock(blockOps, block)) then begin
     if (Node.Bank.Storage.LoadBlockChainBlock(blockOps, block)) then begin
       AContainer.Add( blockOps.GetMinerRewardPseudoOperation );
       AContainer.Add( blockOps.GetMinerRewardPseudoOperation );
-      if blockOps.Count = 0 then exit;
+     // if blockOps.Count = 0 then exit;
       for i := blockOps.Count - 1 downto 0 do begin    // reverse order
       for i := blockOps.Count - 1 downto 0 do begin    // reverse order
         if TPCOperation.OperationToOperationResume(block, blockOps.Operation[i], false, blockOps.Operation[i].SignerAccount, opr) then begin
         if TPCOperation.OperationToOperationResume(block, blockOps.Operation[i], false, blockOps.Operation[i].SignerAccount, opr) then begin
           opr.NOpInsideBlock := i;
           opr.NOpInsideBlock := i;

+ 35 - 25
src/gui/UFRMOperationExplorer.lfm

@@ -1,40 +1,27 @@
 object FRMOperationExplorer: TFRMOperationExplorer
 object FRMOperationExplorer: TFRMOperationExplorer
   Left = 190
   Left = 190
-  Height = 444
+  Height = 424
   Top = 287
   Top = 287
   Width = 864
   Width = 864
+  ActiveControl = ebFilterOperationsStartBlock
   Caption = 'Operations Explorer'
   Caption = 'Operations Explorer'
   ClientHeight = 424
   ClientHeight = 424
   ClientWidth = 864
   ClientWidth = 864
   Menu = OperationsExplorerMenu
   Menu = OperationsExplorerMenu
   OnCreate = FormCreate
   OnCreate = FormCreate
-  OnDestroy = FormDestroy
-  LCLVersion = '1.6.4.0'
-  object dgOperationsExplorer: TDrawGrid
-    Left = 0
-    Height = 383
-    Top = 41
-    Width = 864
-    Align = alClient
-    ExtendedSelect = False
-    TabOrder = 0
-    TitleFont.Color = clWindowText
-    TitleFont.Height = -11
-    TitleFont.Name = 'Tahoma'
-    OnClick = dgOperationsExplorerClick
-  end
+  Visible = False
   object Panel1: TPanel
   object Panel1: TPanel
     Left = 0
     Left = 0
-    Height = 41
+    Height = 56
     Top = 0
     Top = 0
     Width = 864
     Width = 864
     Align = alTop
     Align = alTop
     BevelOuter = bvNone
     BevelOuter = bvNone
-    ClientHeight = 41
+    ClientHeight = 56
     ClientWidth = 864
     ClientWidth = 864
-    TabOrder = 1
+    TabOrder = 0
     object Label2: TLabel
     object Label2: TLabel
-      Left = 11
+      Left = 16
       Height = 15
       Height = 15
       Top = 10
       Top = 10
       Width = 112
       Width = 112
@@ -43,22 +30,45 @@ object FRMOperationExplorer: TFRMOperationExplorer
     end
     end
   end
   end
   object ebFilterOperationsStartBlock: TEdit
   object ebFilterOperationsStartBlock: TEdit
-    Left = 125
+    Left = 16
     Height = 23
     Height = 23
-    Top = 7
+    Top = 32
     Width = 57
     Width = 57
     OnExit = ebFilterOperationsAccountExit
     OnExit = ebFilterOperationsAccountExit
     OnKeyPress = ebFilterOperationsAccountKeyPress
     OnKeyPress = ebFilterOperationsAccountKeyPress
-    TabOrder = 2
+    TabOrder = 1
+    TextHint = 'From'
   end
   end
   object ebFilterOperationsEndBlock: TEdit
   object ebFilterOperationsEndBlock: TEdit
-    Left = 185
+    Left = 104
     Height = 23
     Height = 23
-    Top = 7
+    Top = 32
     Width = 57
     Width = 57
     OnExit = ebFilterOperationsAccountExit
     OnExit = ebFilterOperationsAccountExit
     OnKeyPress = ebFilterOperationsAccountKeyPress
     OnKeyPress = ebFilterOperationsAccountKeyPress
+    TabOrder = 2
+    TextHint = 'To'
+  end
+  object grpOperationExplorer: TGroupBox
+    Left = 16
+    Height = 336
+    Top = 72
+    Width = 840
+    Anchors = [akTop, akLeft, akRight, akBottom]
+    Caption = 'All Operations'
+    ClientHeight = 316
+    ClientWidth = 836
     TabOrder = 3
     TabOrder = 3
+    object paGrid: TPanel
+      Left = 8
+      Height = 282
+      Top = 16
+      Width = 824
+      Anchors = [akTop, akLeft, akRight, akBottom]
+      BevelOuter = bvNone
+      Caption = 'Operation Panel'
+      TabOrder = 0
+    end
   end
   end
   object OperationsExplorerMenu: TMainMenu
   object OperationsExplorerMenu: TMainMenu
     left = 560
     left = 560

+ 208 - 43
src/gui/UFRMOperationExplorer.pas

@@ -17,35 +17,43 @@ interface
 {$I ..\config.inc}
 {$I ..\config.inc}
 
 
 uses
 uses
-    LCLIntf, LCLType, SysUtils, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, Grids, Menus, Classes,
-    UCommon.UI, UGridUtils, UConst;
+  LCLIntf, LCLType, SysUtils, Controls, Forms, Dialogs, ExtCtrls, StdCtrls, Grids, Menus, Classes,
+  UCommon.UI, UConst, UDataSources, UNode, UVisualGrid, UCellRenderers, UCommon.Data, UCoreUtils;
 
 
 type
 type
 
 
   { TFRMOperationExplorer }
   { TFRMOperationExplorer }
 
 
   TFRMOperationExplorer = class(TApplicationForm)
   TFRMOperationExplorer = class(TApplicationForm)
-    dgOperationsExplorer: TDrawGrid;
     ebFilterOperationsEndBlock: TEdit;
     ebFilterOperationsEndBlock: TEdit;
     ebFilterOperationsStartBlock: TEdit;
     ebFilterOperationsStartBlock: TEdit;
+    grpOperationExplorer: TGroupBox;
     Label2: TLabel;
     Label2: TLabel;
     OperationsExplorerMenu: TMainMenu;
     OperationsExplorerMenu: TMainMenu;
     miDecodePayload: TMenuItem;
     miDecodePayload: TMenuItem;
     miFindOperationByOpHash: TMenuItem;
     miFindOperationByOpHash: TMenuItem;
     miTools: TMenuItem;
     miTools: TMenuItem;
     Panel1: TPanel;
     Panel1: TPanel;
-    procedure dgOperationsExplorerClick(Sender: TObject);
+    paGrid: TPanel;
     procedure ebFilterOperationsAccountExit(Sender: TObject);
     procedure ebFilterOperationsAccountExit(Sender: TObject);
-    procedure ebFilterOperationsAccountKeyPress(Sender: TObject; var Key: Char);
+    procedure ebFilterOperationsAccountKeyPress(Sender: TObject; var Key: char);
     procedure FormCreate(Sender: TObject);
     procedure FormCreate(Sender: TObject);
-    procedure FormDestroy(Sender: TObject);
     procedure miDecodePayloadClick(Sender: TObject);
     procedure miDecodePayloadClick(Sender: TObject);
     procedure miFindOperationByOpHashClick(Sender: TObject);
     procedure miFindOperationByOpHashClick(Sender: TObject);
 
 
+  protected
+    procedure OnNodeBlocksChanged(Sender: TObject);
+    procedure OnNodeNewOperation(Sender: TObject);
+    procedure OnOperationSelected(Sender: TObject; constref ASelection: TVisualGridSelection);
   private
   private
     { private declarations }
     { private declarations }
-    FUpdating : boolean;
-    FOperationsExplorerGrid : TOperationsGrid;
+    FUpdating: boolean;
+    FBlockStart, FBlockEnd: int64;
+    FNodeNotifyEvents: TNodeNotifyEvents;
+    FOperationsGrid: TVisualGrid;
+    FOperationsDataSource: TOperationsDataSource;
+    procedure UpdateVisualGridUI();
+    procedure SetBlocks(AStart, AEnd: int64);
   public
   public
     { public declarations }
     { public declarations }
   end;
   end;
@@ -54,22 +62,22 @@ implementation
 
 
 {$r *.lfm}
 {$r *.lfm}
 
 
-uses UUserInterface, UFRMPayloadDecoder, UBlockChain;
+uses UUserInterface, UMemory, UFRMPayloadDecoder, UBlockChain, UWallet, Generics.Collections;
 
 
 procedure TFRMOperationExplorer.FormCreate(Sender: TObject);
 procedure TFRMOperationExplorer.FormCreate(Sender: TObject);
 begin
 begin
-  FOperationsExplorerGrid := TOperationsGrid.Create(Self);
-  FOperationsExplorerGrid.Node := TUserInterface.Node;
-  FOperationsExplorerGrid.DrawGrid := dgOperationsExplorer;
-  FOperationsExplorerGrid.AccountNumber := -1;
-  FOperationsExplorerGrid.PendingOperations := False;
-  FUpdating := false;
-end;
 
 
-procedure TFRMOperationExplorer.FormDestroy(Sender: TObject);
-begin
-  FOperationsExplorerGrid.Node := Nil;
-  // Note: grids themselves are collected with Self (TComponent dependency)
+  // event registrations
+  FNodeNotifyEvents := TNodeNotifyEvents.Create(self);
+  FNodeNotifyEvents.OnBlocksChanged := OnNodeBlocksChanged;
+  FNodeNotifyEvents.OnOperationsChanged := OnNodeNewOperation;
+
+  FUpdating := False;
+  FBlockStart := -1;
+  FBlockEnd := -1;
+
+  UpdateVisualGridUI();
+
 end;
 end;
 
 
 procedure TFRMOperationExplorer.miDecodePayloadClick(Sender: TObject);
 procedure TFRMOperationExplorer.miDecodePayloadClick(Sender: TObject);
@@ -79,41 +87,198 @@ end;
 
 
 procedure TFRMOperationExplorer.miFindOperationByOpHashClick(Sender: TObject);
 procedure TFRMOperationExplorer.miFindOperationByOpHashClick(Sender: TObject);
 var
 var
-  ophash : String;
+  ophash: string;
 begin
 begin
-  if Not InputQuery('Search operation by OpHash','Insert Operation Hash value (OpHash)',ophash)
-    then exit;
+  if not InputQuery('Search operation by OpHash', 'Insert Operation Hash value (OpHash)', ophash) then
+    Exit;
 
 
   TUserInterface.ShowOperationInfoDialog(Self, ophash);
   TUserInterface.ShowOperationInfoDialog(Self, ophash);
 end;
 end;
 
 
-procedure TFRMOperationExplorer.ebFilterOperationsAccountExit(Sender: TObject);
-Var bstart,bend : Int64;
+procedure TFRMOperationExplorer.OnNodeBlocksChanged(Sender: TObject);
 begin
 begin
-  If not FUpdating then
-  Try
-    FUpdating := True;// move to finally
-    bstart := StrToInt64Def(ebFilterOperationsStartBlock.Text,-1);
-    if bstart>=0 then ebFilterOperationsStartBlock.Text := Inttostr(bstart) else ebFilterOperationsStartBlock.Text := '';
-    bend := StrToInt64Def(ebFilterOperationsEndBlock.Text,-1);
-    if bend>=0 then ebFilterOperationsEndBlock.Text := Inttostr(bend) else ebFilterOperationsEndBlock.Text := '';
-      FOperationsExplorerGrid.SetBlocks(bstart,bend);
-  Finally
-
-
-    FUpdating := false;
-  End;
+  UpdateVisualGridUI(); //main
 end;
 end;
 
 
-procedure TFRMOperationExplorer.dgOperationsExplorerClick(Sender: TObject);
+procedure TFRMOperationExplorer.OnNodeNewOperation(Sender: TObject);
 begin
 begin
-  TUserInterface.ShowOperationInfoDialog(Self, FOperationsExplorerGrid.SelectedOperation);
+  UpdateVisualGridUI();
 end;
 end;
 
 
-procedure TFRMOperationExplorer.ebFilterOperationsAccountKeyPress(Sender: TObject; var Key: Char);
+procedure TFRMOperationExplorer.OnOperationSelected(Sender: TObject; constref ASelection: TVisualGridSelection);
+var
+  LRow: longint;
+  LOperationResumeList: TList<TOperationResume>;
+  LGC: TDisposables;
 begin
 begin
-  if key=#13 then  ebFilterOperationsAccountExit(Nil);
+  LOperationResumeList := LGC.AddObject(TList<TOperationResume>.Create) as TList<TOperationResume>;
+  LRow := ASelection.Row;
+  if (LRow >= 0) and (LRow < FOperationsGrid.RowCount) then
+  begin
+    FOperationsDataSource.FetchAll(LOperationResumeList);
+    TUserInterface.ShowOperationInfoDialog(self, LOperationResumeList[LRow]);
+    FOperationsGrid.ClearSelection;
+  end;
 end;
 end;
 
 
-end.
+procedure TFRMOperationExplorer.UpdateVisualGridUI();
+var
+  LNode: TNode;
+  LStart, LEnd: int64;
+begin
+  LNode := TUserInterface.Node;
+  if FBlockEnd < 0 then
+  begin
+    if LNode.Bank.BlocksCount > 0 then
+      LEnd := LNode.Bank.BlocksCount - 1
+    else
+      LEnd := 0;
+  end
+  else
+    LEnd := FBlockEnd;
+  if FBlockStart < 0 then
+  begin
+    if (LEnd > 300) then
+      LStart := LEnd - 300
+    else
+      LStart := 0;
+  end
+  else
+    LStart := FBlockStart;
+  if LStart < 0 then
+    LStart := 0;
+  if LEnd >= LNode.Bank.BlocksCount then
+    LEnd := LNode.Bank.BlocksCount;
+  // fields
+  FOperationsDataSource := TOperationsDataSource.Create(Self);
+
+  FOperationsDataSource.StartBlock := LStart;
+  FOperationsDataSource.EndBlock := LEnd;
 
 
+  FOperationsGrid := TVisualGrid.Create(Self);
+  FOperationsGrid.SortMode := smMultiColumn;
+  FOperationsGrid.FetchDataInThread := True;
+  FOperationsGrid.AutoPageSize := True;
+  FOperationsGrid.DeselectionType := dtDefault;
+  FOperationsGrid.SelectionType := stRow;
+  FOperationsGrid.Options := [vgoColAutoFill, vgoColSizing, vgoSortDirectionAllowNone, vgoAutoHidePaging, vgoAutoHideSearchPanel];
+  with FOperationsGrid.AddColumn('Time') do
+  begin
+    SortBinding := 'UnixTime';
+    DisplayBinding := 'UnixTime';
+    Renderer := TCellRenderers.OperationTime;
+    Width := 130;
+    Filters := SORTABLE_NUMERIC_FILTER;
+  end;
+  with FOperationsGrid.AddColumn('Block') do
+  begin
+    Binding := 'BlockLocation';
+    SortBinding := 'BlockLocationSortable';
+    AutoWidth := True;
+    Filters := SORTABLE_TEXT_FILTER;
+  end;
+  with FOperationsGrid.AddColumn('Account') do
+  begin
+    Binding := 'AccountNumber';
+    DisplayBinding := 'Account';
+    Width := 100;
+    Filters := SORTABLE_NUMERIC_FILTER;
+  end;
+  with FOperationsGrid.AddColumn('Type') do
+  begin
+    Sanitizer := TCellRenderers.OperationTypeSanitizer;
+    Width := 150;
+    Filters := SORTABLE_NUMERIC_FILTER;
+  end;
+  with FOperationsGrid.AddColumn('Amount') do
+  begin
+    Binding := 'AmountDecimal';
+    SortBinding := 'Amount';
+    DisplayBinding := 'Amount';
+    Width := 150;
+    HeaderAlignment := taRightJustify;
+    Renderer := TCellRenderers.PASC_CheckPendingBalance;
+    Filters := SORTABLE_NUMERIC_FILTER;
+  end;
+  with FOperationsGrid.AddColumn('Fee') do
+  begin
+    Binding := 'FeeDecimal';
+    SortBinding := 'Fee';
+    DisplayBinding := 'Fee';
+    AutoWidth := True;
+    HeaderAlignment := taRightJustify;
+    DataAlignment := taRightJustify;
+    Renderer := TCellRenderers.PASC_CheckPendingBalance;
+    Filters := SORTABLE_NUMERIC_FILTER;
+  end;
+  with FOperationsGrid.AddColumn('Balance') do
+  begin
+    Binding := 'BalanceDecimal';
+    SortBinding := 'Balance';
+    DisplayBinding := 'Balance';
+    Width := 100;
+    HeaderAlignment := taRightJustify;
+    DataAlignment := taRightJustify;
+    Renderer := TCellRenderers.PASC_CheckPendingBalance;
+    Filters := SORTABLE_NUMERIC_FILTER;
+  end;
+  with FOperationsGrid.AddColumn('Payload') do
+  begin
+    AutoWidth := True;
+    Renderer := TCellRenderers.Payload;
+    Filters := SORTABLE_TEXT_FILTER;
+  end;
+
+  FOperationsGrid.OnSelection := OnOperationSelected;
+  FOperationsGrid.Caption.Alignment := taCenter;
+  FOperationsGrid.Caption.Text := 'All Operations';
+  FOperationsGrid.Caption.Visible := True;
+
+  // Add datasources to grid
+  FOperationsGrid.DataSource := FOperationsDataSource;
+
+  // Add grid to panels
+  paGrid.AddControlDockCenter(FOperationsGrid);
+end;
+
+procedure TFRMOperationExplorer.SetBlocks(AStart, AEnd: int64);
+begin
+  if (AStart = FBlockStart) and (AEnd = FBlockEnd) then
+    Exit;
+  FBlockStart := AStart;
+  FBlockEnd := AEnd;
+  if (FBlockEnd > 0) and (FBlockStart > FBlockEnd) then
+    FBlockStart := -1;
+  UpdateVisualGridUI();
+end;
+
+procedure TFRMOperationExplorer.ebFilterOperationsAccountExit(Sender: TObject);
+var
+  LStart, LEnd: int64;
+begin
+  if not FUpdating then
+    try
+      FUpdating := True;// move to finally
+      LStart := StrToInt64Def(ebFilterOperationsStartBlock.Text, -1);
+      if LStart >= 0 then
+        ebFilterOperationsStartBlock.Text := IntToStr(LStart)
+      else
+        ebFilterOperationsStartBlock.Text := '';
+      LEnd := StrToInt64Def(ebFilterOperationsEndBlock.Text, -1);
+      if LEnd >= 0 then
+        ebFilterOperationsEndBlock.Text := IntToStr(LEnd)
+      else
+        ebFilterOperationsEndBlock.Text := '';
+      SetBlocks(LStart, LEnd);
+    finally
+      FUpdating := False;
+    end;
+end;
+
+procedure TFRMOperationExplorer.ebFilterOperationsAccountKeyPress(Sender: TObject; var Key: char);
+begin
+  if Key = #13 then
+    ebFilterOperationsAccountExit(nil);
+end;
+
+end.