Browse Source

Changes to addapt both Delphi / Lazarus compilable

PascalCoin 7 years ago
parent
commit
a85315fd7d

+ 3 - 3
src/core/UAccountKeyStorage.pas

@@ -7,7 +7,7 @@ unit UAccountKeyStorage;
 interface
 interface
 
 
 uses
 uses
-  Classes, SysUtils, UAccounts, UThread, UCommon;
+  Classes, SysUtils, UAccounts, UThread, UBaseTypes;
 
 
 type
 type
   TAccountKeyStorateData = record
   TAccountKeyStorateData = record
@@ -55,9 +55,9 @@ begin
     I := (L + H) shr 1;
     I := (L + H) shr 1;
     C := Integer(PAccountKeyStorageData(list[i])^.ptrAccountKey^.EC_OpenSSL_NID) - Integer(accountKey.EC_OpenSSL_NID);
     C := Integer(PAccountKeyStorageData(list[i])^.ptrAccountKey^.EC_OpenSSL_NID) - Integer(accountKey.EC_OpenSSL_NID);
     if C=0 then begin
     if C=0 then begin
-      C := BinStrComp(PAccountKeyStorageData(list[i])^.ptrAccountKey^.x,accountKey.x);
+      C := TBaseType.BinStrComp(PAccountKeyStorageData(list[i])^.ptrAccountKey^.x,accountKey.x);
       if C=0 then begin
       if C=0 then begin
-        C := BinStrComp(PAccountKeyStorageData(list[i])^.ptrAccountKey^.y,accountKey.y);
+        C := TBaseType.BinStrComp(PAccountKeyStorageData(list[i])^.ptrAccountKey^.y,accountKey.y);
       end;
       end;
     end;
     end;
     if C < 0 then L := I + 1 else
     if C < 0 then L := I + 1 else

+ 25 - 2
src/core/UConst.pas

@@ -105,8 +105,6 @@ Const
   // NetProtocol_Available MUST BE always >= NetProtocol_version
   // NetProtocol_Available MUST BE always >= NetProtocol_version
   CT_NetProtocol_Available: Word = $0006;  // Remember, >= NetProtocol_version !!!
   CT_NetProtocol_Available: Word = $0006;  // Remember, >= NetProtocol_version !!!
 
 
-  CT_V2_AccountStart = CT_Protocol_Upgrade_v2_MinBlock div CT_AccountsPerBlock;
-
   CT_MaxAccountOperationsPerBlockWithoutFee = 1;
   CT_MaxAccountOperationsPerBlockWithoutFee = 1;
 
 
   CT_SafeBoxBankVersion : Word = 3; // Protocol 2 upgraded safebox version from 2 to 3
   CT_SafeBoxBankVersion : Word = 3; // Protocol 2 upgraded safebox version from 2 to 3
@@ -127,6 +125,7 @@ Const
 
 
   CT_PseudoOpSubtype_Miner                = 1;
   CT_PseudoOpSubtype_Miner                = 1;
   CT_PseudoOpSubtype_Developer            = 2;
   CT_PseudoOpSubtype_Developer            = 2;
+
   CT_OpSubtype_TransactionSender          = 11;
   CT_OpSubtype_TransactionSender          = 11;
   CT_OpSubtype_TransactionReceiver        = 12;
   CT_OpSubtype_TransactionReceiver        = 12;
   CT_OpSubtype_BuyTransactionBuyer        = 13;
   CT_OpSubtype_BuyTransactionBuyer        = 13;
@@ -152,6 +151,30 @@ Const
   CT_MAX_0_fee_operations_per_block_by_miner = {$IFDEF PRODUCTION}2000{$ELSE}{$IFDEF TESTNET}2{$ELSE}{$ENDIF}{$ENDIF};
   CT_MAX_0_fee_operations_per_block_by_miner = {$IFDEF PRODUCTION}2000{$ELSE}{$IFDEF TESTNET}2{$ELSE}{$ENDIF}{$ENDIF};
   CT_MAX_Operations_per_block_by_miner =  {$IFDEF PRODUCTION}10000{$ELSE}{$IFDEF TESTNET}50{$ELSE}{$ENDIF}{$ENDIF};
   CT_MAX_Operations_per_block_by_miner =  {$IFDEF PRODUCTION}10000{$ELSE}{$IFDEF TESTNET}50{$ELSE}{$ENDIF}{$ENDIF};
 
 
+  // App Params
+  CT_PARAM_GridAccountsStream = 'GridAccountsStreamV2';
+  CT_PARAM_GridAccountsPos = 'GridAccountsPos';
+  CT_PARAM_DefaultFee = 'DefaultFee';
+  CT_PARAM_InternetServerPort = 'InternetServerPort';
+  {$IFDEF TESTNET}CT_PARAM_AutomaticMineWhenConnectedToNodes = 'AutomaticMineWhenConnectedToNodes';{$ENDIF}
+  CT_PARAM_MinerPrivateKeyType = 'MinerPrivateKeyType';
+  CT_PARAM_MinerPrivateKeySelectedPublicKey = 'MinerPrivateKeySelectedPublicKey';
+  CT_PARAM_SaveLogFiles = 'SaveLogFiles';
+  CT_PARAM_SaveDebugLogs = 'SaveDebugLogs';
+  CT_PARAM_ShowLogs = 'ShowLogs';
+  CT_PARAM_MinerName = 'MinerName';
+  CT_PARAM_FirstTime = 'FirstTime';
+  CT_PARAM_ShowModalMessages = 'ShowModalMessages';
+  {$IFDEF TESTNET}CT_PARAM_MaxCPUs = 'MaxCPUs'; {$ENDIF} //deprecated
+  CT_PARAM_PeerCache = 'PeerCache';
+  CT_PARAM_TryToConnectOnlyWithThisFixedServers = 'TryToConnectOnlyWithFixedServers';
+  CT_PARAM_JSONRPCMinerServerPort = 'JSONRPCMinerServerPort';
+  CT_PARAM_JSONRPCMinerServerActive = 'JSONRPCMinerServerActive';
+  CT_PARAM_JSONRPCEnabled = 'JSONRPCEnabled';
+  CT_PARAM_JSONRPCAllowedIPs = 'JSONRPCAllowedIPs';
+
+
+
 implementation
 implementation
 
 
 end.
 end.

+ 17 - 28
src/core/UCrypto.pas

@@ -39,7 +39,6 @@ Type
      EC_OpenSSL_NID : Word;
      EC_OpenSSL_NID : Word;
      x: TRawBytes;
      x: TRawBytes;
      y: TRawBytes;
      y: TRawBytes;
-     class operator = (const a,b : TECDSA_Public) : boolean;
   end;
   end;
   PECDSA_Public = ^TECDSA_Public;
   PECDSA_Public = ^TECDSA_Public;
 
 
@@ -70,21 +69,21 @@ Type
   private
   private
   public
   public
     class function IsHexString(const AHexString: AnsiString) : boolean;
     class function IsHexString(const AHexString: AnsiString) : boolean;
-    Class function ToHexaString(const raw : TRawBytes) : AnsiString;
-    Class function HexaToRaw(const HexaString : AnsiString) : TRawBytes;
-    Class function DoSha256(p : PAnsiChar; plength : Cardinal) : TRawBytes; overload;
-    Class function DoSha256(const TheMessage : AnsiString) : TRawBytes; overload;
-    Class procedure DoSha256(const TheMessage : AnsiString; var ResultSha256 : TRawBytes);  overload;
-    Class procedure DoDoubleSha256(p : PAnsiChar; plength : Cardinal; Var ResultSha256 : TRawBytes); overload;
-    Class function DoRipeMD160_HEXASTRING(const TheMessage : AnsiString) : TRawBytes; overload;
-    Class function DoRipeMD160AsRaw(p : PAnsiChar; plength : Cardinal) : TRawBytes; overload;
-    Class function DoRipeMD160AsRaw(const TheMessage : AnsiString) : TRawBytes; overload;
-    Class function PrivateKey2Hexa(Key : PEC_KEY) : AnsiString;
-    Class function ECDSASign(Key : PEC_KEY; const digest : AnsiString) : TECDSA_SIG;
-    Class function ECDSAVerify(EC_OpenSSL_NID : Word; PubKey : EC_POINT; const digest : AnsiString; Signature : TECDSA_SIG) : Boolean; overload;
-    Class function ECDSAVerify(PubKey : TECDSA_Public; const digest : AnsiString; Signature : TECDSA_SIG) : Boolean; overload;
-    Class procedure InitCrypto;
-    Class function IsHumanReadable(Const ReadableText : TRawBytes) : Boolean;
+    class function ToHexaString(const raw : TRawBytes) : AnsiString;
+    class function HexaToRaw(const HexaString : AnsiString) : TRawBytes;
+    class function DoSha256(p : PAnsiChar; plength : Cardinal) : TRawBytes; overload;
+    class function DoSha256(const TheMessage : AnsiString) : TRawBytes; overload;
+    class procedure DoSha256(const TheMessage : AnsiString; var ResultSha256 : TRawBytes);  overload;
+    class procedure DoDoubleSha256(p : PAnsiChar; plength : Cardinal; Var ResultSha256 : TRawBytes); overload;
+    class function DoRipeMD160_HEXASTRING(const TheMessage : AnsiString) : TRawBytes; overload;
+    class function DoRipeMD160AsRaw(p : PAnsiChar; plength : Cardinal) : TRawBytes; overload;
+    class function DoRipeMD160AsRaw(const TheMessage : AnsiString) : TRawBytes; overload;
+    class function PrivateKey2Hexa(Key : PEC_KEY) : AnsiString;
+    class function ECDSASign(Key : PEC_KEY; const digest : AnsiString) : TECDSA_SIG;
+    class function ECDSAVerify(EC_OpenSSL_NID : Word; PubKey : EC_POINT; const digest : AnsiString; Signature : TECDSA_SIG) : Boolean; overload;
+    class function ECDSAVerify(PubKey : TECDSA_Public; const digest : AnsiString; Signature : TECDSA_SIG) : Boolean; overload;
+    class procedure InitCrypto;
+    class function IsHumanReadable(Const ReadableText : TRawBytes) : Boolean;
   End;
   End;
 
 
   TBigNum = Class
   TBigNum = Class
@@ -133,7 +132,7 @@ Const
 implementation
 implementation
 
 
 uses
 uses
-  UAES, ULog, UConst, UAccounts, UCommon;
+  ULog, UConst, UAccounts;
 
 
 Var _initialized : Boolean = false;
 Var _initialized : Boolean = false;
 
 
@@ -145,16 +144,6 @@ Begin
   end;
   end;
 End;
 End;
 
 
-{ TECDSA_Public }
-
-class operator TECDSA_Public.= (const a,b : TECDSA_Public) : boolean;
-begin
-  Result :=
-    (a.EC_OpenSSL_NID = b.EC_OpenSSL_NID) AND
-    (BinStrComp(a.x, b.x) = 0) AND
-    (BinStrComp(a.y, b.y) = 0);
-end;
-
 { TECPrivateKey }
 { TECPrivateKey }
 
 
 constructor TECPrivateKey.Create;
 constructor TECPrivateKey.Create;
@@ -570,7 +559,7 @@ var
   i : Integer;
   i : Integer;
 begin
 begin
   Result := true;
   Result := true;
-  for i := Low(AHexString) to High(AHexString) do
+  for i := 0 to length(AHexString) do
     if (NOT (AHexString[i] in ['0'..'9'])) AND
     if (NOT (AHexString[i] in ['0'..'9'])) AND
        (NOT (AHexString[i] in ['a'..'f'])) AND
        (NOT (AHexString[i] in ['a'..'f'])) AND
        (NOT (AHexString[i] in ['A'..'F'])) then begin
        (NOT (AHexString[i] in ['A'..'F'])) then begin

+ 13 - 8
src/core/UDataSources.pas

@@ -112,7 +112,7 @@ end;
 
 
 procedure TUserAccountsDataSource.FetchAll(const AContainer : TList<TAccount>);
 procedure TUserAccountsDataSource.FetchAll(const AContainer : TList<TAccount>);
 var
 var
-  i, keyIndex : integer;
+  i : integer;
   acc : TAccount;
   acc : TAccount;
   safeBox : TPCSafeBox;
   safeBox : TPCSafeBox;
   keys : TOrderedAccountKeysList;
   keys : TOrderedAccountKeysList;
@@ -129,7 +129,7 @@ begin
    // load user accounts
    // load user accounts
    for i := 0 to safeBox.AccountsCount - 1 do begin
    for i := 0 to safeBox.AccountsCount - 1 do begin
      acc := safeBox.Account(i);
      acc := safeBox.Account(i);
-     if keys.Find(acc.accountInfo.accountKey, keyIndex) then begin
+     if keys.IndexOfAccountKey(acc.accountInfo.accountKey)>=0 then begin
        AContainer.Add(acc);
        AContainer.Add(acc);
        FLastOverview.TotalPASC := FLastOverview.TotalPASC + acc.Balance;
        FLastOverview.TotalPASC := FLastOverview.TotalPASC + acc.Balance;
        inc(FLastOverview.TotalPASA);
        inc(FLastOverview.TotalPASA);
@@ -151,7 +151,8 @@ begin
    else if AColumnName = 'Balance' then
    else if AColumnName = 'Balance' then
      Result := TAccountComp.FormatMoneyDecimal(AItem.Balance)
      Result := TAccountComp.FormatMoneyDecimal(AItem.Balance)
    else if AColumnName = 'Key' then begin
    else if AColumnName = 'Key' then begin
-     if TWallet.Keys.AccountsKeyList.Find(AItem.accountInfo.accountKey, index) then
+     index := TWallet.Keys.AccountsKeyList.IndexOfAccountKey(AItem.accountInfo.accountKey);
+     if index>=0 then
         Result := TWallet.Keys[index].Name
         Result := TWallet.Keys[index].Name
      else
      else
          Result := TAccountComp.AccountPublicKeyExport(AItem.accountInfo.accountKey);
          Result := TAccountComp.AccountPublicKeyExport(AItem.accountInfo.accountKey);
@@ -174,10 +175,12 @@ begin
   ATableRow.Account := TAccountComp.AccountNumberToAccountTxtNumber(AItem.account);
   ATableRow.Account := TAccountComp.AccountNumberToAccountTxtNumber(AItem.account);
   ATableRow.Name := Variant(AItem.name);
   ATableRow.Name := Variant(AItem.name);
   ATableRow.Balance := TAccountComp.FormatMoney(AItem.balance);
   ATableRow.Balance := TAccountComp.FormatMoney(AItem.balance);
- if TWallet.Keys.AccountsKeyList.Find(AItem.accountInfo.accountKey, index) then
+  index := TWallet.Keys.AccountsKeyList.IndexOfAccountKey(AItem.accountInfo.accountKey);
+  if index>=0 then begin
     ATableRow.Key := TDataSourceTool.AccountKeyShortText(TWallet.Keys[index].Name)
     ATableRow.Key := TDataSourceTool.AccountKeyShortText(TWallet.Keys[index].Name)
- else
+  end else begin
     ATableRow.Key := TDataSourceTool.AccountKeyShortText(TAccountComp.AccountPublicKeyExport(AItem.accountInfo.accountKey));
     ATableRow.Key := TDataSourceTool.AccountKeyShortText(TAccountComp.AccountPublicKeyExport(AItem.accountInfo.accountKey));
+  end;
   ATableRow.AccType := Word(AItem.account_type);
   ATableRow.AccType := Word(AItem.account_type);
   ATableRow.State := Cardinal(AItem.accountInfo.state);
   ATableRow.State := Cardinal(AItem.accountInfo.state);
   ATableRow.Price := TAccountComp.FormatMoney(Aitem.accountInfo.price);
   ATableRow.Price := TAccountComp.FormatMoney(Aitem.accountInfo.price);
@@ -203,7 +206,8 @@ end;
 
 
 function TOperationsDataSourceBase.GetTimeSpan : TTimeSpan;
 function TOperationsDataSourceBase.GetTimeSpan : TTimeSpan;
 begin
 begin
-  Result := TPCOperationsComp.ConvertBlockCountToTimeSpan(FEnd - FStart + 1);
+  Result := TTimeSpan.FromSeconds( CT_NewLineSecondsAvg * (FEnd - FStart + 1) );
+  //XXXXXXXXXX TTimeSpan use not available at TPCOperationsComp  Result := TPCOperationsComp.ConvertBlockCountToTimeSpan(FEnd - FStart + 1);
 end;
 end;
 
 
 procedure TOperationsDataSourceBase.SetTimeSpan(const ASpan : TTimeSpan);
 procedure TOperationsDataSourceBase.SetTimeSpan(const ASpan : TTimeSpan);
@@ -213,7 +217,8 @@ begin
  node := TNode.Node;
  node := TNode.Node;
  if Not Assigned(Node) then exit;
  if Not Assigned(Node) then exit;
  FEnd := node.Bank.BlocksCount - 1;
  FEnd := node.Bank.BlocksCount - 1;
- FStart := ClipValue(FEnd - (TPCOperationsComp.ConvertTimeSpanToBlockCount(ASpan) + 1), 0, FEnd);
+ FStart := ClipValue(FEnd - (Round( ASpan.TotalSeconds / CT_NewLineSecondsAvg ) + 1), 0, FEnd);
+ //XXXXXXXXXX TTimeSpan use not available at TPCOperationsComp  FStart := ClipValue(FEnd - (TPCOperationsComp.ConvertTimeSpanToBlockCount(ASpan) + 1), 0, FEnd);
 end;
 end;
 
 
 function TOperationsDataSourceBase.GetItemDisposePolicy : TItemDisposePolicy;
 function TOperationsDataSourceBase.GetItemDisposePolicy : TItemDisposePolicy;
@@ -444,7 +449,7 @@ begin
   for block := FEnd downto FStart do begin  /// iterate blocks correctly
   for block := FEnd downto FStart do begin  /// iterate blocks correctly
     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.GetMinerRewardPsuedoOperation );
+      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], blockOps.Operation[i].SignerAccount, opr) then begin
         if TPCOperation.OperationToOperationResume(block, blockOps.Operation[i], blockOps.Operation[i].SignerAccount, opr) then begin

+ 1 - 1
src/core/UServerApp.pas

@@ -19,7 +19,7 @@ uses
   Messages,
   Messages,
   {$ENDIF}
   {$ENDIF}
   SyncObjs,
   SyncObjs,
-  UOpenSSL, UCrypto, UNode, UFileStorage, UFolderHelper, UWallet, UConst, ULog, UNetProtocol,
+  UOpenSSL, UCrypto, UNode, UFileStorage, UFolderHelper, UWalletKeys, UConst, ULog, UNetProtocol,
   URPC;
   URPC;
 
 
 type
 type

+ 10 - 5
src/core/USettings.pas

@@ -1,6 +1,8 @@
 unit USettings;
 unit USettings;
 
 
-{$mode delphi}
+{$IFDEF FPC}
+  {$mode delphi}
+{$ENDIF}
 
 
 { Copyright (c) 2018 by Herman Schoenfeld
 { Copyright (c) 2018 by Herman Schoenfeld
 
 
@@ -17,7 +19,7 @@ unit USettings;
 interface
 interface
 
 
 uses
 uses
-  UAppParams, UCommon;
+  UAppParams, UBaseTypes;
 
 
 const
 const
   // App Params
   // App Params
@@ -52,8 +54,8 @@ type
 
 
   TSettings = class
   TSettings = class
     private
     private
-      FOnChanged : TNotifyManyEvent; static;
-      FAppParams : TAppParams; static;
+      class var FOnChanged : TNotifyEventToMany;
+      class var FAppParams : TAppParams;
       class function GetInternetServerPort : Integer; static;
       class function GetInternetServerPort : Integer; static;
       class procedure SetInternetServerPort(AInt:Integer); static;
       class procedure SetInternetServerPort(AInt:Integer); static;
       class function GetRpcPortEnabled : boolean; static;
       class function GetRpcPortEnabled : boolean; static;
@@ -91,7 +93,7 @@ type
     public
     public
       class procedure Load;
       class procedure Load;
       class procedure Save;
       class procedure Save;
-      class property OnChanged : TNotifyManyEvent read FOnChanged write FOnChanged;
+      class property OnChanged : TNotifyEventToMany read FOnChanged;
       class property InternetServerPort : Integer read GetInternetServerPort write SetInternetServerPort;
       class property InternetServerPort : Integer read GetInternetServerPort write SetInternetServerPort;
       class property RpcPortEnabled : boolean read GetRpcPortEnabled write SetRpcPortEnabled;
       class property RpcPortEnabled : boolean read GetRpcPortEnabled write SetRpcPortEnabled;
       class property RpcAllowedIPs : string read GetRpcAllowedIPs write SetRpcAllowedIPs;
       class property RpcAllowedIPs : string read GetRpcAllowedIPs write SetRpcAllowedIPs;
@@ -335,10 +337,13 @@ end;
 
 
 initialization
 initialization
   TSettings.FAppParams := nil;
   TSettings.FAppParams := nil;
+  TSettings.FOnChanged := TNotifyEventToMany.Create;
 
 
 finalization
 finalization
   if Assigned(TSettings.FAppParams) then
   if Assigned(TSettings.FAppParams) then
     FreeAndNil(TSettings.FAppParams);
     FreeAndNil(TSettings.FAppParams);
+  if Assigned(TSettings.FOnChanged) then
+    FreeAndNil(TSettings.FOnChanged);
 
 
 end.
 end.
 
 

+ 0 - 1
src/core/UTCPIP.pas

@@ -146,7 +146,6 @@ type
   private
   private
     FNetTcpIpServerServer : TNetTcpIpServer;
     FNetTcpIpServerServer : TNetTcpIpServer;
     FServerSocket: TTCPBlockSocket;
     FServerSocket: TTCPBlockSocket;
-    FTcpIpSocketsThread : TPCThreadList;
   protected
   protected
     procedure BCExecute; override;
     procedure BCExecute; override;
   public
   public

+ 1 - 0
src/core/UTime.pas

@@ -42,6 +42,7 @@ function UnixTimeToLocalElapsedTime(USec : Longint) : AnsiString;
 Function DateTimeElapsedTime(dtDate : TDateTime) : AnsiString;
 Function DateTimeElapsedTime(dtDate : TDateTime) : AnsiString;
 
 
 Function UnixTimeToLocalStr(UnixTime : Longint) : AnsiString;
 Function UnixTimeToLocalStr(UnixTime : Longint) : AnsiString;
+
 implementation
 implementation
 
 
 {$IFDEF FPC}
 {$IFDEF FPC}

+ 30 - 30
src/core/UWallet.pas

@@ -20,7 +20,7 @@ unit UWallet;
 interface
 interface
 
 
 uses
 uses
-  Classes, USettings, UBlockChain, UAccounts, UCrypto, UCommon;
+  Classes, USettings, UBlockChain, UAccounts, UCrypto, UBaseTypes;
 
 
 Type
 Type
   TWalletKey = Record
   TWalletKey = Record
@@ -41,7 +41,7 @@ Type
     FIsValidPassword: Boolean;
     FIsValidPassword: Boolean;
     FWalletFileName: AnsiString;
     FWalletFileName: AnsiString;
     FIsReadingStream : Boolean;
     FIsReadingStream : Boolean;
-    FOnChanged: TNotifyManyEvent;
+    FOnChanged: TNotifyEventToMany;
     function GetHasPassword : boolean;
     function GetHasPassword : boolean;
     function GetKey(index: Integer): TWalletKey;
     function GetKey(index: Integer): TWalletKey;
     procedure SetWalletPassword(const Value: AnsiString);
     procedure SetWalletPassword(const Value: AnsiString);
@@ -64,7 +64,7 @@ Type
     Procedure Clear; virtual;
     Procedure Clear; virtual;
     Function Count : Integer;
     Function Count : Integer;
     Property WalletFileName : AnsiString read FWalletFileName write SetWalletFileName;
     Property WalletFileName : AnsiString read FWalletFileName write SetWalletFileName;
-    Property OnChanged : TNotifyManyEvent read FOnChanged write FOnChanged;
+    Property OnChanged : TNotifyEventToMany read FOnChanged;
     Procedure SetName(index : Integer; Const newName : AnsiString);
     Procedure SetName(index : Integer; Const newName : AnsiString);
     Function LockWallet : Boolean;
     Function LockWallet : Boolean;
   End;
   End;
@@ -95,7 +95,7 @@ Type
 
 
   TWallet = class
   TWallet = class
     private
     private
-      FKeys : TWalletKeysExt; static;
+      class var FKeys : TWalletKeysExt;
       class function GetKeys : TWalletKeysExt; static;
       class function GetKeys : TWalletKeysExt; static;
       class function GetMiningKey : TAccountKey; static;
       class function GetMiningKey : TAccountKey; static;
       class procedure CheckLoaded;
       class procedure CheckLoaded;
@@ -106,17 +106,17 @@ Type
       class procedure Load;
       class procedure Load;
       class function HasKey(const AKey: TWalletKey) : boolean;
       class function HasKey(const AKey: TWalletKey) : boolean;
       class procedure DeleteKey(const AKey: TWalletKey);
       class procedure DeleteKey(const AKey: TWalletKey);
-      class procedure GenerateNewKey(const AName: string; AEncryptionTypeNID : Word);
-      class function ExportPublicKey(const AKey: TWalletKey) : string;
-      class function ExportPrivateKey(const AKey: TWalletKey; const APassword: string) : string;
-      class procedure ImportPrivateKey(const AName, AKeyImportText, APassword: string);
-      class procedure ImportPublicKey(Const AName, AKeyImportText : string);
-      class function RestoreWallet(const AFileName, APassword: string) : TRestoreWalletResult;
-      class procedure BackupWallet(const AFileName: string);
-      class function TryDecryptPrivateKey(const AEncryptedKeyText, APassword:string; out APrivateKey : TECPrivateKey; out AMessage : string) : boolean;
-      class function TryParseEncryptedKey(const AKeyText, AKeyPassword : string; out AKey : TECPrivateKey) : boolean;
+      class procedure GenerateNewKey(const AName: AnsiString; AEncryptionTypeNID : Word);
+      class function ExportPublicKey(const AKey: TWalletKey) : AnsiString;
+      class function ExportPrivateKey(const AKey: TWalletKey; const APassword: AnsiString) : AnsiString;
+      class procedure ImportPrivateKey(const AName, AKeyImportText, APassword: AnsiString);
+      class procedure ImportPublicKey(Const AName, AKeyImportText : AnsiString);
+      class function RestoreWallet(const AFileName, APassword: AnsiString) : TRestoreWalletResult;
+      class procedure BackupWallet(const AFileName: AnsiString);
+      class function TryDecryptPrivateKey(const AEncryptedKeyText, APassword:AnsiString; out APrivateKey : TECPrivateKey; out AMessage : AnsiString) : boolean;
+      class function TryParseEncryptedKey(const AKeyText, AKeyPassword : AnsiString; out AKey : TECPrivateKey) : boolean;
       class function TryParseRawKey(const ARawBytes : TRawBytes; AEncryptionTypeNID : Word; out AKey : TECPrivateKey) : boolean;
       class function TryParseRawKey(const ARawBytes : TRawBytes; AEncryptionTypeNID : Word; out AKey : TECPrivateKey) : boolean;
-      class function TryParseHexKey(const AHexString : string; AEncryptionTypeNID : Word; out AKey : TECPrivateKey) : boolean;
+      class function TryParseHexKey(const AHexString : AnsiString; AEncryptionTypeNID : Word; out AKey : TECPrivateKey) : boolean;
   end;
   end;
 
 
 Const CT_TWalletKey_NUL  : TWalletKey = (Name:'';AccountKey:(EC_OpenSSL_NID:0;x:'';y:'');CryptedKey:'';PrivateKey:Nil;SearchableAccountKey:'');
 Const CT_TWalletKey_NUL  : TWalletKey = (Name:'';AccountKey:(EC_OpenSSL_NID:0;x:'';y:'');CryptedKey:'';PrivateKey:Nil;SearchableAccountKey:'');
@@ -166,7 +166,7 @@ begin
     P^.Name := Name;
     P^.Name := Name;
     if NOT P^.HasPrivateKey then begin
     if NOT P^.HasPrivateKey then begin
       // overriding watch-only public key with full private/public key data, so double-check private key matches
       // overriding watch-only public key with full private/public key data, so double-check private key matches
-      if P^.AccountKey <> ECPrivateKey.PublicKey then
+      If Not TAccountComp.EqualAccountKeys(P^.AccountKey,ECPrivateKey.PublicKey) then
         raise Exception.Create('[UWallet.pas] TWalletKeys.AddPrivateKey - consistency check failed when overriding watch-only key');
         raise Exception.Create('[UWallet.pas] TWalletKeys.AddPrivateKey - consistency check failed when overriding watch-only key');
       P^.CryptedKey := TAESComp.EVP_Encrypt_AES256(TCrypto.PrivateKey2Hexa(ECPrivateKey.PrivateKey), WalletPassword);
       P^.CryptedKey := TAESComp.EVP_Encrypt_AES256(TCrypto.PrivateKey2Hexa(ECPrivateKey.PrivateKey), WalletPassword);
       P^.PrivateKey := TECPrivateKey.Create;
       P^.PrivateKey := TECPrivateKey.Create;
@@ -224,7 +224,7 @@ begin
   FWalletPassword := '';
   FWalletPassword := '';
   FSearchableKeys := TList.Create;
   FSearchableKeys := TList.Create;
   FIsReadingStream := false;
   FIsReadingStream := false;
-  FOnChanged := Nil;
+  FOnChanged := TNotifyEventToMany.Create;
 end;
 end;
 
 
 procedure TWalletKeys.Delete(index: Integer);
 procedure TWalletKeys.Delete(index: Integer);
@@ -240,7 +240,7 @@ end;
 
 
 destructor TWalletKeys.destroy;
 destructor TWalletKeys.destroy;
 begin
 begin
-  FOnChanged := Nil;
+  FreeAndNil(FOnChanged);
   FreeAndNil(FWalletFileStream);
   FreeAndNil(FWalletFileStream);
   Clear;
   Clear;
   FreeAndNil(FSearchableKeys);
   FreeAndNil(FSearchableKeys);
@@ -543,7 +543,7 @@ begin
   Result := PublicK;
   Result := PublicK;
 end;
 end;
 
 
-class function TWallet.GetKeys : TWalletKeysExt; inline;
+class function TWallet.GetKeys : TWalletKeysExt;
 begin
 begin
   CheckLoaded;
   CheckLoaded;
   Result := FKeys;
   Result := FKeys;
@@ -580,7 +580,7 @@ begin
     raise Exception.Create('Key not found');
     raise Exception.Create('Key not found');
 end;
 end;
 
 
-class procedure TWallet.GenerateNewKey(const AName: string; AEncryptionTypeNID : Word);
+class procedure TWallet.GenerateNewKey(const AName: AnsiString; AEncryptionTypeNID : Word);
 var
 var
   privateKey : TECPrivateKey;
   privateKey : TECPrivateKey;
 begin
 begin
@@ -593,19 +593,19 @@ begin
   end;
   end;
 end;
 end;
 
 
-class function TWallet.ExportPublicKey(const AKey: TWalletKey) : string;
+class function TWallet.ExportPublicKey(const AKey: TWalletKey) : AnsiString;
 begin
 begin
   Result := TAccountComp.AccountPublicKeyExport(AKey.AccountKey);
   Result := TAccountComp.AccountPublicKeyExport(AKey.AccountKey);
 end;
 end;
 
 
-class function TWallet.ExportPrivateKey(const AKey: TWalletKey; const APassword: string) : string;
+class function TWallet.ExportPrivateKey(const AKey: TWalletKey; const APassword: AnsiString) : AnsiString;
 begin
 begin
   Result := TCrypto.ToHexaString(TAESComp.EVP_Encrypt_AES256(AKey.PrivateKey.ExportToRaw, APassword));
   Result := TCrypto.ToHexaString(TAESComp.EVP_Encrypt_AES256(AKey.PrivateKey.ExportToRaw, APassword));
 end;
 end;
 
 
-class procedure TWallet.ImportPrivateKey(const AName, AKeyImportText, APassword: string);
+class procedure TWallet.ImportPrivateKey(const AName, AKeyImportText, APassword: AnsiString);
 var
 var
- message : String;
+ message : AnsiString;
  EC : TECPrivateKey;
  EC : TECPrivateKey;
  i : Integer;
  i : Integer;
 begin
 begin
@@ -625,7 +625,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-class procedure TWallet.ImportPublicKey(Const AName, AKeyImportText : string);
+class procedure TWallet.ImportPublicKey(Const AName, AKeyImportText : AnsiString);
 var
 var
   raw, errors : AnsiString;
   raw, errors : AnsiString;
   accountKey : TAccountKey;
   accountKey : TAccountKey;
@@ -645,7 +645,7 @@ begin
   FKeys.AddPublicKey(AName, accountKey);
   FKeys.AddPublicKey(AName, accountKey);
 end;
 end;
 
 
-class function TWallet.RestoreWallet(const AFileName, APassword: string) : TRestoreWalletResult;
+class function TWallet.RestoreWallet(const AFileName, APassword: AnsiString) : TRestoreWalletResult;
 var
 var
   wki : TWalletKeys;
   wki : TWalletKeys;
   i, j : Integer;
   i, j : Integer;
@@ -696,7 +696,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-class procedure TWallet.BackupWallet(const AFileName : string);
+class procedure TWallet.BackupWallet(const AFileName : AnsiString);
 var
 var
   fs : TFileStream;
   fs : TFileStream;
 begin
 begin
@@ -710,7 +710,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-class function TWallet.TryDecryptPrivateKey(const AEncryptedKeyText, APassword:string; out APrivateKey : TECPrivateKey; out AMessage : string) : boolean;
+class function TWallet.TryDecryptPrivateKey(const AEncryptedKeyText, APassword:AnsiString; out APrivateKey : TECPrivateKey; out AMessage : AnsiString) : boolean;
 var
 var
  parseResult : Boolean;
  parseResult : Boolean;
 begin
 begin
@@ -750,9 +750,9 @@ begin
   Result := true;
   Result := true;
 end;
 end;
 
 
-class function TWallet.TryParseEncryptedKey(const AKeyText, AKeyPassword : string; out AKey : TECPrivateKey) : boolean;
+class function TWallet.TryParseEncryptedKey(const AKeyText, AKeyPassword : AnsiString; out AKey : TECPrivateKey) : boolean;
 var
 var
- decrypt : string;
+ decrypt : AnsiString;
 begin
 begin
   AKey := nil;
   AKey := nil;
   if NOT TCrypto.IsHexString(AKeyText) then begin
   if NOT TCrypto.IsHexString(AKeyText) then begin
@@ -773,7 +773,7 @@ begin
   Result := TryParseHexKey(TCrypto.ToHexaString(ARawBytes), AEncryptionTypeNID, AKey);
   Result := TryParseHexKey(TCrypto.ToHexaString(ARawBytes), AEncryptionTypeNID, AKey);
 end;
 end;
 
 
-class function TWallet.TryParseHexKey(const AHexString : string; AEncryptionTypeNID : Word; out AKey : TECPrivateKey) : boolean;
+class function TWallet.TryParseHexKey(const AHexString : AnsiString; AEncryptionTypeNID : Word; out AKey : TECPrivateKey) : boolean;
 begin
 begin
   AKey := TECPrivateKey.Create;
   AKey := TECPrivateKey.Create;
   Try
   Try

+ 4 - 4
src/core/upcdaemon.pas

@@ -19,7 +19,7 @@ interface
 
 
 uses
 uses
   Classes, SysUtils, daemonapp,
   Classes, SysUtils, daemonapp,
-  SyncObjs, UOpenSSL, UCrypto, UNode, UFileStorage, UFolderHelper, UWallet, UConst, ULog, UNetProtocol,
+  SyncObjs, UOpenSSL, UCrypto, UNode, UFileStorage, UFolderHelper, UWalletKeys, UConst, ULog, UNetProtocol,
   IniFiles,
   IniFiles,
   UThread, URPC, UPoolMining, UAccounts;
   UThread, URPC, UPoolMining, UAccounts;
 
 
@@ -73,7 +73,7 @@ Type
   TPCDaemonMapper = Class(TCustomDaemonMapper)
   TPCDaemonMapper = Class(TCustomDaemonMapper)
   private
   private
     FLog : TLog;
     FLog : TLog;
-    procedure OnPascalCoinInThreadLog(logtype : TLogType; Time : TDateTime; AThreadID : QWord; Const sender, logtext : AnsiString);
+    procedure OnPascalCoinInThreadLog(logtype : TLogType; Time : TDateTime; AThreadID : TThreadID; Const sender, logtext : AnsiString);
   protected
   protected
     Procedure DoOnCreate; override;
     Procedure DoOnCreate; override;
     Procedure DoOnDestroy; override;
     Procedure DoOnDestroy; override;
@@ -323,13 +323,13 @@ end;
 { TPCDaemonMapper }
 { TPCDaemonMapper }
 
 
 procedure TPCDaemonMapper.OnPascalCoinInThreadLog(logtype: TLogType;
 procedure TPCDaemonMapper.OnPascalCoinInThreadLog(logtype: TLogType;
-  Time: TDateTime; AThreadID: QWord; const sender, logtext: AnsiString);
+  Time: TDateTime; AThreadID: TThreadID; const sender, logtext: AnsiString);
 Var s : AnsiString;
 Var s : AnsiString;
 begin
 begin
 //  If Not SameText(sender,TPCDaemonThread.ClassName) then exit;
 //  If Not SameText(sender,TPCDaemonThread.ClassName) then exit;
   If logtype in [lterror,ltinfo] then begin
   If logtype in [lterror,ltinfo] then begin
     if AThreadID=MainThreadID then s := ' MAIN:' else s:=' TID:';
     if AThreadID=MainThreadID then s := ' MAIN:' else s:=' TID:';
-    WriteLn(formatDateTime('dd/mm/yyyy hh:nn:ss.zzz',Time)+s+IntToHex(AThreadID,8)+' ['+CT_LogType[Logtype]+'] <'+sender+'> '+logtext);
+    WriteLn(formatDateTime('dd/mm/yyyy hh:nn:ss.zzz',Time)+s+IntToHex(PtrInt(AThreadID),8)+' ['+CT_LogType[Logtype]+'] <'+sender+'> '+logtext);
   end;
   end;
 end;
 end;