Browse Source

gui-classic -> TRawBytes

Refactor gui-classic to work with new TRawBytes definition
PascalCoin 6 years ago
parent
commit
86dcabadc7

+ 7 - 7
src/gui-classic/UFRMAccountSelect.pas

@@ -30,7 +30,7 @@ uses
 {$ENDIF}
 {$ENDIF}
   Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
   Dialogs, UAccounts, Grids, StdCtrls, Buttons, ExtCtrls, UWallet, UNode,
   Dialogs, UAccounts, Grids, StdCtrls, Buttons, ExtCtrls, UWallet, UNode,
-  UGridUtils, UConst, UThread, UPCOrderedLists;
+  UGridUtils, UConst, UThread, UPCOrderedLists, UBaseTypes;
 
 
 const
 const
   CT_AS_MyAccounts = $0001;
   CT_AS_MyAccounts = $0001;
@@ -46,7 +46,7 @@ type
     onlyForPublicSale,
     onlyForPublicSale,
     onlyForPrivateSaleToMe : Boolean;
     onlyForPrivateSaleToMe : Boolean;
     minBal,maxBal : Int64;
     minBal,maxBal : Int64;
-    searchName : AnsiString;
+    searchName : TRawBytes;
   end;
   end;
 
 
   TSearchProcedure = procedure(Const searchFound : TCardinalsArray; const searchValues : TSearchValues) of object;
   TSearchProcedure = procedure(Const searchFound : TCardinalsArray; const searchValues : TSearchValues) of object;
@@ -186,8 +186,8 @@ procedure TSearchThread.BCExecute;
       If IsValid then begin
       If IsValid then begin
         IsValid := (account.balance>=FSearchValues.minBal) And ((FSearchValues.maxBal<0) Or (account.balance<=FSearchValues.maxBal));
         IsValid := (account.balance>=FSearchValues.minBal) And ((FSearchValues.maxBal<0) Or (account.balance<=FSearchValues.maxBal));
       end;
       end;
-      If IsValid And (FSearchValues.searchName<>'') then begin
-        i := ansipos(FSearchValues.searchName,account.name);
+      If IsValid And (Length(FSearchValues.searchName)>0) then begin
+        i := TBaseType.FindIn(FSearchValues.searchName,account.name);
         IsValid := i>0;
         IsValid := i>0;
       end;
       end;
       //
       //
@@ -497,15 +497,15 @@ begin
     ebMaxBalance.Font.Color:=clGray;
     ebMaxBalance.Font.Color:=clGray;
   end;
   end;
   if (cbAccountsName.Checked) then begin
   if (cbAccountsName.Checked) then begin
-    searchValues.searchName := LowerCase(Trim(ebAccountName.Text));
+    searchValues.searchName.FromString(ebAccountName.Text);
     ebAccountName.ParentFont:=True;
     ebAccountName.ParentFont:=True;
   end else begin
   end else begin
-    searchValues.searchName:='';
+    searchValues.searchName:=Nil;
     ebAccountName.Font.Color := clGray;
     ebAccountName.Font.Color := clGray;
   end;
   end;
   If (searchValues.inAccountKey.EC_OpenSSL_NID=0) AND (searchValues.inWalletKeys=Nil) And (searchValues.maxBal<0) And (searchValues.minBal<=0) And
   If (searchValues.inAccountKey.EC_OpenSSL_NID=0) AND (searchValues.inWalletKeys=Nil) And (searchValues.maxBal<0) And (searchValues.minBal<=0) And
      (Not searchValues.onlyForPrivateSaleToMe) And (Not searchValues.onlyForPublicSale) And (Not searchValues.onlyForSale) And
      (Not searchValues.onlyForPrivateSaleToMe) And (Not searchValues.onlyForPublicSale) And (Not searchValues.onlyForSale) And
-     (searchValues.searchName='') then begin
+     (Length(searchValues.searchName)=0) then begin
     FAccountsGrid.ShowAllAccounts:=True;
     FAccountsGrid.ShowAllAccounts:=True;
     lblAccountsCount.Caption := IntToStr(FAccountsGrid.Node.Bank.SafeBox.AccountsCount);
     lblAccountsCount.Caption := IntToStr(FAccountsGrid.Node.Bank.SafeBox.AccountsCount);
     lblAccountsBalance.Caption := TAccountComp.FormatMoney(FAccountsGrid.AccountsBalance);
     lblAccountsBalance.Caption := TAccountComp.FormatMoney(FAccountsGrid.AccountsBalance);

+ 22 - 22
src/gui-classic/UFRMOperation.pas

@@ -163,7 +163,7 @@ type
     Function UpdateOpListForSale(Const TargetAccount : TAccount; var SalePrice : Int64; var SellerAccount,SignerAccount : TAccount; var NewOwnerPublicKey : TAccountKey; var LockedUntilBlock : Cardinal; var errors : AnsiString) : Boolean;
     Function UpdateOpListForSale(Const TargetAccount : TAccount; var SalePrice : Int64; var SellerAccount,SignerAccount : TAccount; var NewOwnerPublicKey : TAccountKey; var LockedUntilBlock : Cardinal; var errors : AnsiString) : Boolean;
     Function UpdateOpDelist(Const TargetAccount : TAccount; var SignerAccount : TAccount; var errors : AnsiString) : Boolean;
     Function UpdateOpDelist(Const TargetAccount : TAccount; var SignerAccount : TAccount; var errors : AnsiString) : Boolean;
     Function UpdateOpBuyAccount(Const SenderAccount : TAccount; var AccountToBuy : TAccount; var amount : Int64; var NewPublicKey : TAccountKey; var errors : AnsiString) : Boolean;
     Function UpdateOpBuyAccount(Const SenderAccount : TAccount; var AccountToBuy : TAccount; var amount : Int64; var NewPublicKey : TAccountKey; var errors : AnsiString) : Boolean;
-    Function UpdateOpChangeInfo(Const TargetAccount : TAccount; var SignerAccount : TAccount; var changeName : Boolean; var newName : AnsiString; var changeType : Boolean; var newType : Word; var errors : AnsiString) : Boolean;
+    Function UpdateOpChangeInfo(Const TargetAccount : TAccount; var SignerAccount : TAccount; var changeName : Boolean; var newName : TRawBytes; var changeType : Boolean; var newType : Word; var errors : AnsiString) : Boolean;
     procedure SetDefaultFee(const Value: Int64);
     procedure SetDefaultFee(const Value: Int64);
     Procedure OnSenderAccountsChanged(Sender : TObject);
     Procedure OnSenderAccountsChanged(Sender : TObject);
     procedure OnWalletKeysChanged(Sender : TObject);
     procedure OnWalletKeysChanged(Sender : TObject);
@@ -183,7 +183,7 @@ implementation
 
 
 uses
 uses
   UECIES, UConst, UOpTransaction, UFRMNewPrivateKeyType, UAES, UFRMWalletKeys,
   UECIES, UConst, UOpTransaction, UFRMNewPrivateKeyType, UAES, UFRMWalletKeys,
-  UCommon, UGUIUtils, UPCDataTypes;
+  UCommon, UGUIUtils, UPCDataTypes, ULog;
 
 
 {$IFnDEF FPC}
 {$IFnDEF FPC}
   {$R *.dfm}
   {$R *.dfm}
@@ -666,7 +666,7 @@ begin
   end;
   end;
   If SenderAccounts.Count>=1 then begin
   If SenderAccounts.Count>=1 then begin
     ebSignerAccount.text := TAccountComp.AccountNumberToAccountTxtNumber(SenderAccounts.Get(0));
     ebSignerAccount.text := TAccountComp.AccountNumberToAccountTxtNumber(SenderAccounts.Get(0));
-    ebChangeName.Text := FNode.Operations.SafeBoxTransaction.Account(SenderAccounts.Get(0)).name;
+    ebChangeName.Text := FNode.Operations.SafeBoxTransaction.Account(SenderAccounts.Get(0)).name.ToPrintable;
     ebChangeType.Text := IntToStr(FNode.Operations.SafeBoxTransaction.Account(SenderAccounts.Get(0)).account_type);
     ebChangeType.Text := IntToStr(FNode.Operations.SafeBoxTransaction.Account(SenderAccounts.Get(0)).account_type);
   end else begin
   end else begin
     ebSignerAccount.text := '';
     ebSignerAccount.text := '';
@@ -854,7 +854,7 @@ begin
 end;
 end;
 
 
 function TFRMOperation.UpdateOpChangeInfo(const TargetAccount: TAccount; var SignerAccount : TAccount;
 function TFRMOperation.UpdateOpChangeInfo(const TargetAccount: TAccount; var SignerAccount : TAccount;
-   var changeName : Boolean; var newName: AnsiString; var changeType : Boolean; var newType: Word; var errors: AnsiString): Boolean;
+   var changeName : Boolean; var newName: TRawBytes; var changeType : Boolean; var newType: Word; var errors: AnsiString): Boolean;
 var auxC : Cardinal;
 var auxC : Cardinal;
   i : Integer;
   i : Integer;
   errCode : Integer;
   errCode : Integer;
@@ -896,17 +896,17 @@ begin
     end;
     end;
     // New name and type (only when single operation)
     // New name and type (only when single operation)
     If (SenderAccounts.Count=1) then begin
     If (SenderAccounts.Count=1) then begin
-      newName := LowerCase( Trim(ebChangeName.Text) );
-      If newName<>TargetAccount.name then begin
+      newName.FromString(LowerCase( Trim(ebChangeName.Text) ));
+      If Not TBaseType.Equals(newName,TargetAccount.name) then begin
         changeName:=True;
         changeName:=True;
-        If newName<>'' then begin
+        If Length(newName)>0 then begin
           if (Not TPCSafeBox.ValidAccountName(newName,errors)) then begin
           if (Not TPCSafeBox.ValidAccountName(newName,errors)) then begin
-            errors := '"'+newName+'" is not a valid name: '+errors;
+            errors := '"'+newName.ToPrintable+'" is not a valid name: '+errors;
             Exit;
             Exit;
           end;
           end;
           i := (FNode.Bank.SafeBox.FindAccountByName(newName));
           i := (FNode.Bank.SafeBox.FindAccountByName(newName));
           if (i>=0) then begin
           if (i>=0) then begin
-            errors := 'Name "'+newName+'" is used by account '+TAccountComp.AccountNumberToAccountTxtNumber(i);
+            errors := 'Name "'+newName.ToPrintable+'" is used by account '+TAccountComp.AccountNumberToAccountTxtNumber(i);
             Exit;
             Exit;
           end;
           end;
         end;
         end;
@@ -1061,7 +1061,7 @@ Var
   salePrice, amount : Int64;
   salePrice, amount : Int64;
   auxC : Cardinal;
   auxC : Cardinal;
   changeName,changeType : Boolean;
   changeName,changeType : Boolean;
-  newName : AnsiString;
+  newName : TRawBytes;
   newType : Word;
   newType : Word;
 begin
 begin
   Result := false;
   Result := false;
@@ -1091,7 +1091,7 @@ begin
         end;
         end;
         wk := WalletKeys.Key[iWallet];
         wk := WalletKeys.Key[iWallet];
         if not assigned(wk.PrivateKey) then begin
         if not assigned(wk.PrivateKey) then begin
-          if wk.CryptedKey<>'' then begin
+          if Length(wk.CryptedKey)>0 then begin
             errors := 'Wallet is password protected. Need password';
             errors := 'Wallet is password protected. Need password';
             bbPassword.Visible := true;
             bbPassword.Visible := true;
             bbPassword.Enabled := true;
             bbPassword.Enabled := true;
@@ -1309,8 +1309,8 @@ Var payload_u : AnsiString;
   wk : TWalletKey;
   wk : TWalletKey;
 begin
 begin
   valid := false;
   valid := false;
-  payload_encrypted := '';
-  FEncodedPayload := '';
+  payload_encrypted := Nil;
+  FEncodedPayload := Nil;
   errors := 'Unknown error';
   errors := 'Unknown error';
   payload_u := memoPayload.Lines.Text;
   payload_u := memoPayload.Lines.Text;
   try
   try
@@ -1322,8 +1322,8 @@ begin
       // Use sender
       // Use sender
       errors := 'Error encrypting';
       errors := 'Error encrypting';
       account := FNode.Operations.SafeBoxTransaction.Account(SenderAccount.account);
       account := FNode.Operations.SafeBoxTransaction.Account(SenderAccount.account);
-      payload_encrypted := ECIESEncrypt(account.accountInfo.accountKey,payload_u);
-      valid := payload_encrypted<>'';
+      payload_encrypted := ECIESEncrypt(account.accountInfo.accountKey,TEncoding.ANSI.GetBytes(payload_u));
+      valid := Length(payload_encrypted)>0;
     end else if (rbEncryptedWithEC.Checked) then begin
     end else if (rbEncryptedWithEC.Checked) then begin
       errors := 'Error encrypting';
       errors := 'Error encrypting';
       if (PageControlOpType.ActivePage=tsTransaction) or (PageControlOpType.ActivePage=tsListForSale) or (PageControlOpType.ActivePage=tsDelist)
       if (PageControlOpType.ActivePage=tsTransaction) or (PageControlOpType.ActivePage=tsListForSale) or (PageControlOpType.ActivePage=tsDelist)
@@ -1358,8 +1358,8 @@ begin
           exit;
           exit;
         end;
         end;
         account := FNode.Operations.SafeBoxTransaction.Account(dest_account_number);
         account := FNode.Operations.SafeBoxTransaction.Account(dest_account_number);
-        payload_encrypted := ECIESEncrypt(account.accountInfo.accountKey,payload_u);
-        valid := payload_encrypted<>'';
+        payload_encrypted := ECIESEncrypt(account.accountInfo.accountKey,TEncoding.ANSI.GetBytes(payload_u));
+        valid := Length(payload_encrypted)>0;
       end else if (PageControlOpType.ActivePage=tsChangePrivateKey) then begin
       end else if (PageControlOpType.ActivePage=tsChangePrivateKey) then begin
         if (rbChangeKeyWithAnother.Checked) then begin
         if (rbChangeKeyWithAnother.Checked) then begin
           // With new key generated
           // With new key generated
@@ -1380,8 +1380,8 @@ begin
           exit;
           exit;
         end;
         end;
         if public_key.EC_OpenSSL_NID<>CT_Account_NUL.accountInfo.accountKey.EC_OpenSSL_NID then begin
         if public_key.EC_OpenSSL_NID<>CT_Account_NUL.accountInfo.accountKey.EC_OpenSSL_NID then begin
-          payload_encrypted := ECIESEncrypt(public_key,payload_u);
-          valid := payload_encrypted<>'';
+          payload_encrypted := ECIESEncrypt(public_key,TEncoding.ANSI.GetBytes(payload_u));
+          valid := Length(payload_encrypted)>0;
         end else begin
         end else begin
           valid := false;
           valid := false;
           errors := 'Selected private key is not valid to encode';
           errors := 'Selected private key is not valid to encode';
@@ -1391,10 +1391,10 @@ begin
         errors := 'This operation does not allow this kind of payload';
         errors := 'This operation does not allow this kind of payload';
       end;
       end;
     end else if (rbEncrptedWithPassword.Checked) then begin
     end else if (rbEncrptedWithPassword.Checked) then begin
-      payload_encrypted := TAESComp.EVP_Encrypt_AES256(payload_u,ebEncryptPassword.Text);
-      valid := payload_encrypted<>'';
+      payload_encrypted := TAESComp.EVP_Encrypt_AES256(TEncoding.ANSI.GetBytes(payload_u),TEncoding.ANSI.GetBytes(ebEncryptPassword.Text));
+      valid := Length(payload_encrypted)>0;
     end else if (rbNotEncrypted.Checked) then begin
     end else if (rbNotEncrypted.Checked) then begin
-      payload_encrypted := payload_u;
+      payload_encrypted := TEncoding.ANSI.GetBytes(payload_u);
       valid := true;
       valid := true;
     end else begin
     end else begin
       errors := 'Must select an encryption option for payload';
       errors := 'Must select an encryption option for payload';

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

@@ -357,7 +357,7 @@ Var op : TPCOperation;
   aux : String;
   aux : String;
   nAccount,n_operation : Cardinal;
   nAccount,n_operation : Cardinal;
   changes : TMultiOpChangesInfo;
   changes : TMultiOpChangesInfo;
-  new_name,errors : AnsiString;
+  new_name, errors : AnsiString;
   new_type : Word;
   new_type : Word;
   new_account_key : TAccountKey;
   new_account_key : TAccountKey;
 label LBL_start_changer;
 label LBL_start_changer;
@@ -391,7 +391,7 @@ LBL_start_changer:
     If Assigned(FSourceNode) then begin
     If Assigned(FSourceNode) then begin
       If (nAccount<FSourceNode.Bank.AccountsCount) then begin
       If (nAccount<FSourceNode.Bank.AccountsCount) then begin
         n_operation := FSourceNode.Bank.SafeBox.Account(nAccount).n_operation+1;
         n_operation := FSourceNode.Bank.SafeBox.Account(nAccount).n_operation+1;
-        new_name:= FSourceNode.Bank.SafeBox.Account(nAccount).name;
+        new_name:= TEncoding.ANSI.GetString( FSourceNode.Bank.SafeBox.Account(nAccount).name );
         new_type:= FSourceNode.Bank.SafeBox.Account(nAccount).account_type;
         new_type:= FSourceNode.Bank.SafeBox.Account(nAccount).account_type;
         new_account_key := FSourceNode.Bank.SafeBox.Account(nAccount).accountInfo.accountKey;
         new_account_key := FSourceNode.Bank.SafeBox.Account(nAccount).accountInfo.accountKey;
       end;
       end;
@@ -408,7 +408,7 @@ LBL_start_changer:
       aux := new_name;
       aux := new_name;
       If Not InputQuery(Caption,Format('New name for account %s:',[TAccountComp.AccountNumberToAccountTxtNumber(nAccount)]),aux) then Break;
       If Not InputQuery(Caption,Format('New name for account %s:',[TAccountComp.AccountNumberToAccountTxtNumber(nAccount)]),aux) then Break;
       aux := LowerCase(aux);
       aux := LowerCase(aux);
-    Until (aux='') Or (TPCSafeBox.ValidAccountName(aux,errors));
+    Until (aux='') Or (TPCSafeBox.ValidAccountName(TEncoding.ANSI.GetBytes(aux),errors));
     new_name := aux;
     new_name := aux;
 
 
     aux := IntToStr(new_type);
     aux := IntToStr(new_type);
@@ -428,7 +428,7 @@ LBL_start_changer:
     changes[high(changes)] := CT_TMultiOpChangeInfo_NUL;
     changes[high(changes)] := CT_TMultiOpChangeInfo_NUL;
     changes[high(changes)].Account:=nAccount;
     changes[high(changes)].Account:=nAccount;
     changes[high(changes)].Changes_type:=[account_name,account_type];
     changes[high(changes)].Changes_type:=[account_name,account_type];
-    changes[high(changes)].New_Name:=new_name;
+    changes[high(changes)].New_Name:=TEncoding.ANSI.GetBytes(new_name);
     changes[high(changes)].New_Type:=new_type;
     changes[high(changes)].New_Type:=new_type;
     If new_account_key.EC_OpenSSL_NID<>CT_TECDSA_Public_Nul.EC_OpenSSL_NID then begin
     If new_account_key.EC_OpenSSL_NID<>CT_TECDSA_Public_Nul.EC_OpenSSL_NID then begin
       changes[high(changes)].Changes_type:=changes[high(changes)].Changes_type + [public_key];
       changes[high(changes)].Changes_type:=changes[high(changes)].Changes_type + [public_key];

+ 9 - 8
src/gui-classic/UFRMPascalCoinWalletConfig.pas

@@ -123,7 +123,7 @@ begin
     if cbPrivateKeyToMine.ItemIndex<0 then raise Exception.Create('Must select a private key');
     if cbPrivateKeyToMine.ItemIndex<0 then raise Exception.Create('Must select a private key');
     i := PtrInt(cbPrivateKeyToMine.Items.Objects[cbPrivateKeyToMine.ItemIndex]);
     i := PtrInt(cbPrivateKeyToMine.Items.Objects[cbPrivateKeyToMine.ItemIndex]);
     if (i<0) Or (i>=FWalletKeys.Count) then raise Exception.Create('Invalid private key');
     if (i<0) Or (i>=FWalletKeys.Count) then raise Exception.Create('Invalid private key');
-    AppParams.ParamByName[CT_PARAM_MinerPrivateKeySelectedPublicKey].SetAsString( TAccountComp.AccountKey2RawString( FWalletKeys.Key[i].AccountKey ) );
+    AppParams.ParamByName[CT_PARAM_MinerPrivateKeySelectedPublicKey].SetAsTBytes( TAccountComp.AccountKey2RawString( FWalletKeys.Key[i].AccountKey ) );
   end else mpk := mpk_Random;
   end else mpk := mpk_Random;
 
 
   AppParams.ParamByName[CT_PARAM_MinerPrivateKeyType].SetAsInteger(integer(mpk));
   AppParams.ParamByName[CT_PARAM_MinerPrivateKeyType].SetAsInteger(integer(mpk));
@@ -254,8 +254,9 @@ end;
 
 
 procedure TFRMPascalCoinWalletConfig.UpdateWalletConfig;
 procedure TFRMPascalCoinWalletConfig.UpdateWalletConfig;
 Var i, iselected : Integer;
 Var i, iselected : Integer;
-  s : String;
+  raw : TBytes;
   wk : TWalletKey;
   wk : TWalletKey;
+  auxs : String;
 begin
 begin
   if Assigned(FWalletKeys) then begin
   if Assigned(FWalletKeys) then begin
     if FWalletKeys.IsValidPassword then begin
     if FWalletKeys.IsValidPassword then begin
@@ -271,18 +272,18 @@ begin
     for i := 0 to FWalletKeys.Count - 1 do begin
     for i := 0 to FWalletKeys.Count - 1 do begin
       wk := FWalletKeys.Key[i];
       wk := FWalletKeys.Key[i];
       if (wk.Name='') then begin
       if (wk.Name='') then begin
-        s := TCrypto.ToHexaString( TAccountComp.AccountKey2RawString(wk.AccountKey));
+        auxs := TCrypto.ToHexaString( TAccountComp.AccountKey2RawString(wk.AccountKey));
       end else begin
       end else begin
-        s := wk.Name;
+        auxs := wk.Name;
       end;
       end;
-      if wk.CryptedKey<>'' then begin
-        cbPrivateKeyToMine.Items.AddObject(s,TObject(i));
+      if (Length(wk.CryptedKey)>0) then begin
+        cbPrivateKeyToMine.Items.AddObject(auxs,TObject(i));
       end;
       end;
     end;
     end;
     cbPrivateKeyToMine.Sorted := true;
     cbPrivateKeyToMine.Sorted := true;
     if Assigned(FAppParams) then begin
     if Assigned(FAppParams) then begin
-      s := FAppParams.ParamByName[CT_PARAM_MinerPrivateKeySelectedPublicKey].GetAsString('');
-      iselected := FWalletKeys.IndexOfAccountKey(TAccountComp.RawString2Accountkey(s));
+      raw := FAppParams.ParamByName[CT_PARAM_MinerPrivateKeySelectedPublicKey].GetAsTBytes(Nil);
+      iselected := FWalletKeys.IndexOfAccountKey(TAccountComp.RawString2Accountkey(raw));
       if iselected>=0 then begin
       if iselected>=0 then begin
         iselected :=  cbPrivateKeyToMine.Items.IndexOfObject(TObject(iselected));
         iselected :=  cbPrivateKeyToMine.Items.IndexOfObject(TObject(iselected));
         cbPrivateKeyToMine.ItemIndex := iselected;
         cbPrivateKeyToMine.ItemIndex := iselected;

+ 9 - 8
src/gui-classic/UFRMPayloadDecoder.pas

@@ -153,7 +153,7 @@ begin
   end;
   end;
   try
   try
     r := TCrypto.HexaToRaw(trim(OpHash));
     r := TCrypto.HexaToRaw(trim(OpHash));
-    if (r='') then begin
+    if (Length(r)=0) then begin
       raise Exception.Create('Value is not an hexadecimal string');
       raise Exception.Create('Value is not an hexadecimal string');
     end;
     end;
     // Build 2.1.4 new decoder option: Check if OpHash is a posible double spend
     // Build 2.1.4 new decoder option: Check if OpHash is a posible double spend
@@ -360,7 +360,7 @@ begin
 end;
 end;
 
 
 procedure TFRMPayloadDecoder.TryToDecode;
 procedure TFRMPayloadDecoder.TryToDecode;
-  Function UseWallet(Const raw : TRawBytes; var Decrypted : AnsiString; var WalletKey : TWalletKey) : Boolean;
+  Function UseWallet(Const raw : TRawBytes; var Decrypted : TRawBytes; var WalletKey : TWalletKey) : Boolean;
   Var i : Integer;
   Var i : Integer;
   begin
   begin
     Result := false;
     Result := false;
@@ -378,7 +378,7 @@ procedure TFRMPayloadDecoder.TryToDecode;
 
 
   end;
   end;
 
 
-  Function  UsePassword(const raw : TRawBytes; var Decrypted,PasswordUsed : AnsiString) : Boolean;
+  Function  UsePassword(const raw : TRawBytes; var Decrypted : TRawBytes; var PasswordUsed : AnsiString) : Boolean;
   Var i : Integer;
   Var i : Integer;
   Begin
   Begin
     Result := false;
     Result := false;
@@ -396,25 +396,26 @@ procedure TFRMPayloadDecoder.TryToDecode;
 
 
 Var raw : TRawBytes;
 Var raw : TRawBytes;
   WalletKey : TWalletKey;
   WalletKey : TWalletKey;
-  Decrypted,PasswordUsed : AnsiString;
+  Decrypted : TRawBytes;
+  PasswordUsed : AnsiString;
   ok : boolean;
   ok : boolean;
 begin
 begin
   ok := true;
   ok := true;
   if Assigned(FWalletKeys) And Assigned(FAppParams) then begin
   if Assigned(FWalletKeys) And Assigned(FAppParams) then begin
     raw := FOpResume.OriginalPayload;
     raw := FOpResume.OriginalPayload;
-    if raw<>'' then begin
+    if Length(raw)>0 then begin
       // First try to a human readable...
       // First try to a human readable...
       if (cbMethodPublicPayload.Checked) and (TCrypto.IsHumanReadable(raw)) then begin
       if (cbMethodPublicPayload.Checked) and (TCrypto.IsHumanReadable(raw)) then begin
         if cbShowAsHexadecimal.Checked then memoDecoded.Lines.Text := TCrypto.ToHexaString(raw)
         if cbShowAsHexadecimal.Checked then memoDecoded.Lines.Text := TCrypto.ToHexaString(raw)
-        else memoDecoded.Lines.Text := raw;
+        else memoDecoded.Lines.Text := TEncoding.ANSI.GetString(raw);
         lblDecodedMethod.Caption := 'Not encrypted payload';
         lblDecodedMethod.Caption := 'Not encrypted payload';
       end else if (cbUsingPrivateKeys.Checked) And (UseWallet(raw,Decrypted,WalletKey)) then begin
       end else if (cbUsingPrivateKeys.Checked) And (UseWallet(raw,Decrypted,WalletKey)) then begin
         if cbShowAsHexadecimal.Checked then memoDecoded.Lines.Text := TCrypto.ToHexaString(Decrypted)
         if cbShowAsHexadecimal.Checked then memoDecoded.Lines.Text := TCrypto.ToHexaString(Decrypted)
-        else memoDecoded.Lines.Text := Decrypted;
+        else memoDecoded.Lines.Text := TEncoding.ANSI.GetString(Decrypted);
         lblDecodedMethod.Caption := 'Encrypted with EC '+TAccountComp.GetECInfoTxt(WalletKey.PrivateKey.EC_OpenSSL_NID);
         lblDecodedMethod.Caption := 'Encrypted with EC '+TAccountComp.GetECInfoTxt(WalletKey.PrivateKey.EC_OpenSSL_NID);
       end else if (cbUsingPasswords.Checked) And (UsePassword(raw,Decrypted,PasswordUsed)) then begin
       end else if (cbUsingPasswords.Checked) And (UsePassword(raw,Decrypted,PasswordUsed)) then begin
         if cbShowAsHexadecimal.Checked then memoDecoded.Lines.Text := TCrypto.ToHexaString(Decrypted)
         if cbShowAsHexadecimal.Checked then memoDecoded.Lines.Text := TCrypto.ToHexaString(Decrypted)
-        else memoDecoded.Lines.Text := Decrypted;
+        else memoDecoded.Lines.Text := TEncoding.ANSI.GetString(Decrypted);
         lblDecodedMethod.Caption := 'Encrypted with pwd:"'+PasswordUsed+'"';
         lblDecodedMethod.Caption := 'Encrypted with pwd:"'+PasswordUsed+'"';
       end else begin
       end else begin
         memoDecoded.Lines.Text := 'CANNOT DECRYPT';
         memoDecoded.Lines.Text := 'CANNOT DECRYPT';

+ 2 - 2
src/gui-classic/UFRMRPCCalls.pas

@@ -186,9 +186,9 @@ begin
   ms := TMemoryStream.Create;
   ms := TMemoryStream.Create;
   Try
   Try
     ms.Size := 0;
     ms.Size := 0;
-    TStreamOp.LoadStreamFromRaw(ms,json.ToJSON(False));
+    TStreamOp.LoadStreamFromRaw(ms,TEncoding.ANSI.GetBytes(json.ToJSON(False)));
     If Not DoHttpPostBinary(ebServerURL.Text,ms) then ShowCallInfo(error,'no valid response from '+ebServerURL.Text);
     If Not DoHttpPostBinary(ebServerURL.Text,ms) then ShowCallInfo(error,'no valid response from '+ebServerURL.Text);
-    s := TStreamOp.SaveStreamToRaw(ms);
+    s := TEncoding.ANSI.GetString(TStreamOp.SaveStreamToRaw(ms));
     ShowCallInfo(response,s);
     ShowCallInfo(response,s);
     if DecodeJSONResult(s,jsonResult) then begin
     if DecodeJSONResult(s,jsonResult) then begin
       Try
       Try

+ 2 - 2
src/gui-classic/UFRMRandomOperations.pas

@@ -305,7 +305,7 @@ begin
     if (Random(500)<1) then fees := 0
     if (Random(500)<1) then fees := 0
     else fees := 1; // Minimal fee
     else fees := 1; // Minimal fee
     if (senderAcc.balance>2) then begin
     if (senderAcc.balance>2) then begin
-      opTx := TOpTransaction.CreateTransaction(current_protocol,senderAcc.account,senderAcc.n_operation+1,nAccountTarget,aWalletKeys.Key[iKey].PrivateKey,amount,fees,'');
+      opTx := TOpTransaction.CreateTransaction(current_protocol,senderAcc.account,senderAcc.n_operation+1,nAccountTarget,aWalletKeys.Key[iKey].PrivateKey,amount,fees,Nil);
       Try
       Try
         if operationsComp.AddOperation(True,opTx,errors) then inc(Result);
         if operationsComp.AddOperation(True,opTx,errors) then inc(Result);
       finally
       finally
@@ -394,7 +394,7 @@ begin
               end;
               end;
               1 : begin
               1 : begin
                 changer.Changes_type:=[account_name];
                 changer.Changes_type:=[account_name];
-                changer.New_Name:='random'+IntToStr(Random(100)); // <- This will generate collisions
+                changer.New_Name:=TEncoding.ANSI.GetBytes('random'+IntToStr(Random(100))); // <- This will generate collisions
               end;
               end;
             else
             else
               changer.Changes_type:=[account_type];
               changer.Changes_type:=[account_type];

+ 17 - 17
src/gui-classic/UFRMWallet.pas

@@ -278,7 +278,7 @@ type
     procedure OnNetConnectionsUpdated(Sender : TObject);
     procedure OnNetConnectionsUpdated(Sender : TObject);
     procedure OnNetNodeServersUpdated(Sender : TObject);
     procedure OnNetNodeServersUpdated(Sender : TObject);
     procedure OnNetBlackListUpdated(Sender : TObject);
     procedure OnNetBlackListUpdated(Sender : TObject);
-    Procedure OnNodeMessageEvent(NetConnection : TNetConnection; MessageData : TRawBytes);
+    Procedure OnNodeMessageEvent(NetConnection : TNetConnection; MessageData : String);
     Procedure OnNodeKeysActivity(Sender : TObject);
     Procedure OnNodeKeysActivity(Sender : TObject);
     Procedure OnSelectedAccountsGridUpdated(Sender : TObject);
     Procedure OnSelectedAccountsGridUpdated(Sender : TObject);
     Procedure OnMiningServerNewBlockFound(Sender : TObject);
     Procedure OnMiningServerNewBlockFound(Sender : TObject);
@@ -512,7 +512,7 @@ begin
   basem := memoMessageToSend.Lines.Text;
   basem := memoMessageToSend.Lines.Text;
   m := '';
   m := '';
   // Clear non valid characters:
   // Clear non valid characters:
-  for i := 1 to length(basem) do begin
+  for i := Low(basem) to High(basem) do begin
     if basem[i] in [#32..#127] then m := m + basem[i]
     if basem[i] in [#32..#127] then m := m + basem[i]
     else m:=m+'.';
     else m:=m+'.';
   end;
   end;
@@ -813,7 +813,7 @@ begin
   FPoolMiningServer := TPoolMiningServer.Create;
   FPoolMiningServer := TPoolMiningServer.Create;
   FPoolMiningServer.Port := FAppParams.ParamByName[CT_PARAM_JSONRPCMinerServerPort].GetAsInteger(CT_JSONRPCMinerServer_Port);
   FPoolMiningServer.Port := FAppParams.ParamByName[CT_PARAM_JSONRPCMinerServerPort].GetAsInteger(CT_JSONRPCMinerServer_Port);
   FPoolMiningServer.MinerAccountKey := GetAccountKeyForMiner;
   FPoolMiningServer.MinerAccountKey := GetAccountKeyForMiner;
-  FPoolMiningServer.MinerPayload := FAppParams.ParamByName[CT_PARAM_MinerName].GetAsString('');
+  FPoolMiningServer.MinerPayload := TEncoding.ANSI.GetBytes( FAppParams.ParamByName[CT_PARAM_MinerName].GetAsString('') );
   FNode.Operations.AccountKey := GetAccountKeyForMiner;
   FNode.Operations.AccountKey := GetAccountKeyForMiner;
   FPoolMiningServer.Active := FAppParams.ParamByName[CT_PARAM_JSONRPCMinerServerActive].GetAsBoolean(true);
   FPoolMiningServer.Active := FAppParams.ParamByName[CT_PARAM_JSONRPCMinerServerActive].GetAsBoolean(true);
   FPoolMiningServer.OnMiningServerNewBlockFound := OnMiningServerNewBlockFound;
   FPoolMiningServer.OnMiningServerNewBlockFound := OnMiningServerNewBlockFound;
@@ -835,7 +835,7 @@ Var account : TAccount;
 begin
 begin
   if AccountNumber<0 then exit;
   if AccountNumber<0 then exit;
   account := FNode.Operations.SafeBoxTransaction.Account(AccountNumber);
   account := FNode.Operations.SafeBoxTransaction.Account(AccountNumber);
-  if account.name<>'' then s:='Name: '+account.name
+  if Length(account.name)>0 then s:='Name: '+TEncoding.ANSI.GetString(account.name)
   else s:='';
   else s:='';
   Strings.Add(Format('Account: %s %s Type:%d',[TAccountComp.AccountNumberToAccountTxtNumber(AccountNumber),s,account.account_type]));
   Strings.Add(Format('Account: %s %s Type:%d',[TAccountComp.AccountNumberToAccountTxtNumber(AccountNumber),s,account.account_type]));
   Strings.Add('');
   Strings.Add('');
@@ -894,10 +894,10 @@ begin
   end;
   end;
   Strings.Add(Format('OpType:%d Subtype:%d',[OperationResume.OpType,OperationResume.OpSubtype]));
   Strings.Add(Format('OpType:%d Subtype:%d',[OperationResume.OpType,OperationResume.OpSubtype]));
   Strings.Add(Format('Operation Hash (ophash): %s',[TCrypto.ToHexaString(OperationResume.OperationHash)]));
   Strings.Add(Format('Operation Hash (ophash): %s',[TCrypto.ToHexaString(OperationResume.OperationHash)]));
-  If (OperationResume.OperationHash_OLD<>'') then begin
+  If (Length(OperationResume.OperationHash_OLD)>0) then begin
     Strings.Add(Format('Old Operation Hash (old_ophash): %s',[TCrypto.ToHexaString(OperationResume.OperationHash_OLD)]));
     Strings.Add(Format('Old Operation Hash (old_ophash): %s',[TCrypto.ToHexaString(OperationResume.OperationHash_OLD)]));
   end;
   end;
-  if (OperationResume.OriginalPayload<>'') then begin
+  if (Length(OperationResume.OriginalPayload)>0) then begin
     Strings.Add(Format('Payload length:%d',[length(OperationResume.OriginalPayload)]));
     Strings.Add(Format('Payload length:%d',[length(OperationResume.OriginalPayload)]));
     If OperationResume.PrintablePayload<>'' then begin
     If OperationResume.PrintablePayload<>'' then begin
       Strings.Add(Format('Payload (human): %s',[OperationResume.PrintablePayload]));
       Strings.Add(Format('Payload (human): %s',[OperationResume.PrintablePayload]));
@@ -1327,24 +1327,24 @@ begin
   case FMinerPrivateKeyType of
   case FMinerPrivateKeyType of
     mpk_NewEachTime: PublicK := CT_TECDSA_Public_Nul;
     mpk_NewEachTime: PublicK := CT_TECDSA_Public_Nul;
     mpk_Selected: begin
     mpk_Selected: begin
-      PublicK := TAccountComp.RawString2Accountkey(FAppParams.ParamByName[CT_PARAM_MinerPrivateKeySelectedPublicKey].GetAsString(''));
+      PublicK := TAccountComp.RawString2Accountkey(FAppParams.ParamByName[CT_PARAM_MinerPrivateKeySelectedPublicKey].GetAsTBytes(Nil));
     end;
     end;
   else
   else
     // Random
     // Random
     PublicK := CT_TECDSA_Public_Nul;
     PublicK := CT_TECDSA_Public_Nul;
     if FWalletKeys.Count>0 then begin
     if FWalletKeys.Count>0 then begin
       i := Random(FWalletKeys.Count);
       i := Random(FWalletKeys.Count);
-      if (FWalletKeys.Key[i].CryptedKey='') then begin
+      if (Length(FWalletKeys.Key[i].CryptedKey)=0) then begin
         // Not valid, search for first valid:
         // Not valid, search for first valid:
         i:=0;
         i:=0;
-        while (i<FWalletKeys.Count) And (FWalletKeys.Key[i].CryptedKey='') do inc(i);
+        while (i<FWalletKeys.Count) And (Length(FWalletKeys.Key[i].CryptedKey)=0) do inc(i);
         if i<FWalletKeys.Count then PublicK := FWalletKeys.Key[i].AccountKey;
         if i<FWalletKeys.Count then PublicK := FWalletKeys.Key[i].AccountKey;
       end else PublicK := FWalletKeys.Key[i].AccountKey;
       end else PublicK := FWalletKeys.Key[i].AccountKey;
     end;
     end;
   end;
   end;
   i := FWalletKeys.IndexOfAccountKey(PublicK);
   i := FWalletKeys.IndexOfAccountKey(PublicK);
   if i>=0 then begin
   if i>=0 then begin
-    if (FWalletKeys.Key[i].CryptedKey='') then i:=-1;
+    if (Length(FWalletKeys.Key[i].CryptedKey)=0) then i:=-1;
   end;
   end;
   if i<0 then begin
   if i<0 then begin
     PK := TECPrivateKey.Create;
     PK := TECPrivateKey.Create;
@@ -1354,7 +1354,7 @@ begin
       PublicK := PK.PublicKey;
       PublicK := PK.PublicKey;
       // Set to AppParams if not mpk_NewEachTime
       // Set to AppParams if not mpk_NewEachTime
       if (FMinerPrivateKeyType<>mpk_NewEachTime) then begin
       if (FMinerPrivateKeyType<>mpk_NewEachTime) then begin
-        FAppParams.ParamByName[CT_PARAM_MinerPrivateKeySelectedPublicKey].Value:=TAccountComp.AccountKey2RawString(PublicK);
+        FAppParams.ParamByName[CT_PARAM_MinerPrivateKeySelectedPublicKey].SetAsTBytes(TAccountComp.AccountKey2RawString(PublicK));
         FMinerPrivateKeyType:=mpk_Selected;
         FMinerPrivateKeyType:=mpk_Selected;
         FAppParams.ParamByName[CT_PARAM_MinerPrivateKeyType].Value := Integer(mpk_Selected);
         FAppParams.ParamByName[CT_PARAM_MinerPrivateKeyType].Value := Integer(mpk_Selected);
       end;
       end;
@@ -1772,7 +1772,7 @@ begin
   //
   //
 end;
 end;
 
 
-procedure TFRMWallet.OnNodeMessageEvent(NetConnection: TNetConnection; MessageData: TRawBytes);
+procedure TFRMWallet.OnNodeMessageEvent(NetConnection: TNetConnection; MessageData: String);
 Var s : String;
 Var s : String;
 begin
 begin
   inc(FMessagesUnreadCount);
   inc(FMessagesUnreadCount);
@@ -1783,11 +1783,11 @@ begin
     if FAppParams.ParamByName[CT_PARAM_ShowModalMessages].GetAsBoolean(false) then begin
     if FAppParams.ParamByName[CT_PARAM_ShowModalMessages].GetAsBoolean(false) then begin
       s := DateTimeToStr(now)+' Message from '+NetConnection.ClientRemoteAddr+#10+
       s := DateTimeToStr(now)+' Message from '+NetConnection.ClientRemoteAddr+#10+
          'Length '+inttostr(length(MessageData))+' bytes'+#10+#10;
          'Length '+inttostr(length(MessageData))+' bytes'+#10+#10;
-      if TCrypto.IsHumanReadable(MessageData) then begin
+      if TCrypto.IsHumanReadable(TEncoding.ANSI.GetBytes(MessageData)) then begin
          s := s + MessageData;
          s := s + MessageData;
       end else begin
       end else begin
          s := s +'Value in hexadecimal:'+#10+
          s := s +'Value in hexadecimal:'+#10+
-              TCrypto.ToHexaString(MessageData);
+              TCrypto.ToHexaString(TEncoding.ANSI.GetBytes(MessageData));
       end;
       end;
       Application.MessageBox(PChar(s),PChar(Application.Title),MB_ICONINFORMATION+MB_OK);
       Application.MessageBox(PChar(s),PChar(Application.Title),MB_ICONINFORMATION+MB_OK);
     end;
     end;
@@ -2168,7 +2168,7 @@ begin
     wa := FNode.NetServer.Active;
     wa := FNode.NetServer.Active;
     FNode.NetServer.Port := FAppParams.ParamByName[CT_PARAM_InternetServerPort].GetAsInteger(CT_NetServer_Port);
     FNode.NetServer.Port := FAppParams.ParamByName[CT_PARAM_InternetServerPort].GetAsInteger(CT_NetServer_Port);
     FNode.NetServer.Active := wa;
     FNode.NetServer.Active := wa;
-    FNode.Operations.BlockPayload := FAppParams.ParamByName[CT_PARAM_MinerName].GetAsString('');
+    FNode.Operations.BlockPayload := TEncoding.ANSI.GetBytes(FAppParams.ParamByName[CT_PARAM_MinerName].GetAsString(''));
     FNode.NodeLogFilename := TFolderHelper.GetPascalCoinDataFolder+PathDelim+'blocks.log';
     FNode.NodeLogFilename := TFolderHelper.GetPascalCoinDataFolder+PathDelim+'blocks.log';
   end;
   end;
   if Assigned(FPoolMiningServer) then begin
   if Assigned(FPoolMiningServer) then begin
@@ -2177,7 +2177,7 @@ begin
       FPoolMiningServer.Port := FAppParams.ParamByName[CT_PARAM_JSONRPCMinerServerPort].GetAsInteger(CT_JSONRPCMinerServer_Port);
       FPoolMiningServer.Port := FAppParams.ParamByName[CT_PARAM_JSONRPCMinerServerPort].GetAsInteger(CT_JSONRPCMinerServer_Port);
     end;
     end;
     FPoolMiningServer.Active :=FAppParams.ParamByName[CT_PARAM_JSONRPCMinerServerActive].GetAsBoolean(true);
     FPoolMiningServer.Active :=FAppParams.ParamByName[CT_PARAM_JSONRPCMinerServerActive].GetAsBoolean(true);
-    FPoolMiningServer.UpdateAccountAndPayload(GetAccountKeyForMiner,FAppParams.ParamByName[CT_PARAM_MinerName].GetAsString(''));
+    FPoolMiningServer.UpdateAccountAndPayload(GetAccountKeyForMiner,TEncoding.ANSI.GetBytes(FAppParams.ParamByName[CT_PARAM_MinerName].GetAsString('')));
   end;
   end;
   if Assigned(FRPCServer) then begin
   if Assigned(FRPCServer) then begin
     FRPCServer.Active := FAppParams.ParamByName[CT_PARAM_JSONRPCEnabled].GetAsBoolean(false);
     FRPCServer.Active := FAppParams.ParamByName[CT_PARAM_JSONRPCEnabled].GetAsBoolean(false);
@@ -2287,7 +2287,7 @@ begin
         s := wk.Name;
         s := wk.Name;
       end;
       end;
       if Not Assigned(wk.PrivateKey) then begin
       if Not Assigned(wk.PrivateKey) then begin
-        if wk.CryptedKey<>'' then s:=s+' (Encrypted, need password)';
+        if Length(wk.CryptedKey)>0 then s:=s+' (Encrypted, need password)';
         s:=s+' (* without key)';
         s:=s+' (* without key)';
       end;
       end;
       cbMyPrivateKeys.Items.AddObject(s,TObject(i));
       cbMyPrivateKeys.Items.AddObject(s,TObject(i));

+ 16 - 16
src/gui-classic/UFRMWalletKeys.pas

@@ -170,7 +170,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,pwd1) );
+        enc := TCrypto.ToHexaString( TAESComp.EVP_Encrypt_AES256( wk.PrivateKey.ExportToRaw,TEncoding.ANSI.GetBytes(pwd1)) );
         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+
@@ -272,18 +272,18 @@ end;
 
 
 procedure TFRMWalletKeys.bbImportPrivateKeyClick(Sender: TObject);
 procedure TFRMWalletKeys.bbImportPrivateKeyClick(Sender: TObject);
 var s : String;
 var s : String;
- desenc, enc : AnsiString;
+ desenc, enc : TRawBytes;
  EC : TECPrivateKey;
  EC : TECPrivateKey;
  i : Integer;
  i : Integer;
  wk : TWalletKey;
  wk : TWalletKey;
  parseResult : Boolean;
  parseResult : Boolean;
 
 
-  function ParseRawKey(EC_OpenSSL_NID : Word) : boolean;
+  function ParseRawKey(EC_OpenSSL_NID : Word; const rawPrivateKey : TRawBytes) : boolean;
   begin
   begin
     FreeAndNil(EC); ParseRawKey := False;
     FreeAndNil(EC); ParseRawKey := False;
     EC := TECPrivateKey.Create;
     EC := TECPrivateKey.Create;
     Try
     Try
-      EC.SetPrivateKeyFromHexa(EC_OpenSSL_NID, TCrypto.ToHexaString(enc));
+      EC.SetPrivateKeyFromHexa(EC_OpenSSL_NID, TCrypto.ToHexaString(rawPrivateKey));
       ParseRawKey := True;
       ParseRawKey := True;
     Except
     Except
       On E:Exception do begin
       On E:Exception do begin
@@ -297,10 +297,10 @@ var s : String;
   begin
   begin
       Repeat
       Repeat
         s := '';
         s := '';
-        desenc := '';
+        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
           If (TAESComp.EVP_Decrypt_AES256(enc,s,desenc)) then begin
-            if (desenc<>'') then begin
+            if Length(desenc)>0 then begin
               EC := TECPrivateKey.ImportFromRaw(desenc);
               EC := TECPrivateKey.ImportFromRaw(desenc);
               ParseEncryptedKey := True;
               ParseEncryptedKey := True;
               Exit;
               Exit;
@@ -309,7 +309,7 @@ var s : String;
                 ParseEncryptedKey := False;
                 ParseEncryptedKey := False;
                 Exit;
                 Exit;
               end;
               end;
-              desenc := '';
+              desenc := Nil;
             end;
             end;
           end else begin
           end else begin
             if Application.MessageBox(PChar('Invalid password or corrupted data!'),'',MB_RETRYCANCEL+MB_ICONERROR)<>IDRETRY then begin
             if Application.MessageBox(PChar('Invalid password or corrupted data!'),'',MB_RETRYCANCEL+MB_ICONERROR)<>IDRETRY then begin
@@ -321,7 +321,7 @@ var s : String;
           ParseEncryptedKey := false;
           ParseEncryptedKey := false;
           Exit;
           Exit;
         end;
         end;
-      Until (desenc<>'');
+      Until Length(desenc)>0;
   end;
   end;
 
 
 begin
 begin
@@ -332,12 +332,12 @@ begin
     s := trim(s);
     s := trim(s);
     if (s='') then raise Exception.Create('No valid key');
     if (s='') then raise Exception.Create('No valid key');
     enc := TCrypto.HexaToRaw(s);
     enc := TCrypto.HexaToRaw(s);
-    if (enc='') then raise Exception.Create('Invalid text... You must enter an hexadecimal value ("0".."9" or "A".."F")');
+    if Length(enc)=0 then raise Exception.Create('Invalid text... You must enter an hexadecimal value ("0".."9" or "A".."F")');
     case Length(enc) of
     case Length(enc) of
-         32: parseResult := ParseRawKey(CT_NID_secp256k1);
-         35,36: parseResult := ParseRawKey(CT_NID_sect283k1);
-         48: parseResult := ParseRawKey(CT_NID_secp384r1);
-         65,66: parseResult := ParseRawKey(CT_NID_secp521r1);
+         32: parseResult := ParseRawKey(CT_NID_secp256k1,enc);
+         35,36: parseResult := ParseRawKey(CT_NID_sect283k1,enc);
+         48: parseResult := ParseRawKey(CT_NID_secp384r1,enc);
+         65,66: parseResult := ParseRawKey(CT_NID_secp521r1,enc);
          64, 80, 96: parseResult := ParseEncryptedKey;
          64, 80, 96: parseResult := ParseEncryptedKey;
          else Exception.Create('Invalidly formatted private key string. Ensure it is an encrypted private key export or raw private key hexstring.');
          else Exception.Create('Invalidly formatted private key string. Ensure it is an encrypted private key export or raw private key hexstring.');
     end;
     end;
@@ -367,7 +367,7 @@ end;
 
 
 procedure TFRMWalletKeys.bbImportPublicKeyClick(Sender: TObject);
 procedure TFRMWalletKeys.bbImportPublicKeyClick(Sender: TObject);
 var s : String;
 var s : String;
- raw : AnsiString;
+ raw : TRawBytes;
  EC : TECPrivateKey;
  EC : TECPrivateKey;
  account : TAccountKey;
  account : TAccountKey;
  errors : AnsiString;
  errors : AnsiString;
@@ -377,7 +377,7 @@ begin
   if Not InputQuery('Import publick key','Insert the public key in hexa format or imported format',s) then exit;
   if Not InputQuery('Import publick key','Insert the public key in hexa format or imported format',s) then exit;
   If not TAccountComp.AccountPublicKeyImport(s,account,errors) then begin
   If not TAccountComp.AccountPublicKeyImport(s,account,errors) then begin
     raw := TCrypto.HexaToRaw(s);
     raw := TCrypto.HexaToRaw(s);
-    if trim(raw)='' then raise Exception.Create('Invalid public key value (Not hexa or not an imported format)'+#10+errors);
+    if Length(raw)=0 then raise Exception.Create('Invalid public key value (Not hexa or not an imported format)'+#10+errors);
     account := TAccountComp.RawString2Accountkey(raw);
     account := TAccountComp.RawString2Accountkey(raw);
   end;
   end;
   If not TAccountComp.IsValidAccountKey(account,errors) then raise Exception.Create('This data is not a valid public key'+#10+errors);
   If not TAccountComp.IsValidAccountKey(account,errors) then raise Exception.Create('This data is not a valid public key'+#10+errors);
@@ -560,7 +560,7 @@ begin
         s := wk.Name;
         s := wk.Name;
       end;
       end;
       if Not Assigned(wk.PrivateKey) then begin
       if Not Assigned(wk.PrivateKey) then begin
-        if wk.CryptedKey<>'' then s:=s+' (Encrypted, need password)';
+        if Length(wk.CryptedKey)>0 then s:=s+' (Encrypted, need password)';
         s:=s+' (* without key)';
         s:=s+' (* without key)';
       end;
       end;
       lbWalletKeys.Items.AddObject(s,TObject(i));
       lbWalletKeys.Items.AddObject(s,TObject(i));

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

@@ -198,7 +198,7 @@ Type
   End;
   End;
 
 
 Const
 Const
-  CT_TBlockChainData_NUL : TBlockChainData = (Block:0;Timestamp:0;BlockProtocolVersion:0;BlockProtocolAvailable:0;OperationsCount:-1;Volume:-1;Reward:0;Fee:0;Target:0;HashRateTargetHs:0;HashRateHs:0;HashRateTargetKhs:0;HashRateKhs:0;MinerPayload:'';PoW:'';SafeBoxHash:'';AccumulatedWork:0;TimeAverage200:0;TimeAverage150:0;TimeAverage100:0;TimeAverage75:0;TimeAverage50:0;TimeAverage25:0;TimeAverage10:0);
+  CT_TBlockChainData_NUL : TBlockChainData = (Block:0;Timestamp:0;BlockProtocolVersion:0;BlockProtocolAvailable:0;OperationsCount:-1;Volume:-1;Reward:0;Fee:0;Target:0;HashRateTargetHs:0;HashRateHs:0;HashRateTargetKhs:0;HashRateKhs:0;MinerPayload:Nil;PoW:Nil;SafeBoxHash:Nil;AccumulatedWork:0;TimeAverage200:0;TimeAverage150:0;TimeAverage100:0;TimeAverage75:0;TimeAverage50:0;TimeAverage25:0;TimeAverage10:0);
 
 
 
 
 implementation
 implementation
@@ -509,7 +509,7 @@ begin
           DrawGrid.Canvas.Ellipse(Rect.Left+1,Rect.Top+1,Rect.Right-1,Rect.Bottom-1);
           DrawGrid.Canvas.Ellipse(Rect.Left+1,Rect.Top+1,Rect.Right-1,Rect.Bottom-1);
         End;
         End;
         act_name : Begin
         act_name : Begin
-          s := account.name;
+          s := account.name.ToPrintable;
           Canvas_TextRect(DrawGrid.Canvas,Rect,s,State,[tfLeft,tfVerticalCenter,tfSingleLine]);
           Canvas_TextRect(DrawGrid.Canvas,Rect,s,State,[tfLeft,tfVerticalCenter,tfSingleLine]);
         end;
         end;
         act_type : Begin
         act_type : Begin
@@ -1174,7 +1174,7 @@ begin
         Canvas_TextRect(DrawGrid.Canvas,Rect,s,State,[tfRight,tfVerticalCenter]);
         Canvas_TextRect(DrawGrid.Canvas,Rect,s,State,[tfRight,tfVerticalCenter]);
       end else if ACol=8 then begin
       end else if ACol=8 then begin
         if TCrypto.IsHumanReadable(bcd.MinerPayload) then
         if TCrypto.IsHumanReadable(bcd.MinerPayload) then
-          s := bcd.MinerPayload
+          s := TEncoding.ANSI.GetString(bcd.MinerPayload)
         else s := TCrypto.ToHexaString( bcd.MinerPayload );
         else s := TCrypto.ToHexaString( bcd.MinerPayload );
         Canvas_TextRect(DrawGrid.Canvas,Rect,s,State,[tfLeft,tfVerticalCenter]);
         Canvas_TextRect(DrawGrid.Canvas,Rect,s,State,[tfLeft,tfVerticalCenter]);
       end else if ACol=9 then begin
       end else if ACol=9 then begin
@@ -1338,7 +1338,6 @@ begin
         finally
         finally
           bn.Free;
           bn.Free;
         end;
         end;
-        // bcd.HashRateKhs := Node.Bank.SafeBox.CalcBlockHashRateInKhs(bcd.Block,HashRateAverageBlocksCount); XXXXXXXX
         bn := TBigNum.TargetToHashRate(opb.compact_target);
         bn := TBigNum.TargetToHashRate(opb.compact_target);
         Try
         Try
           bcd.HashRateTargetHs := bn.Value / (CT_NewLineSecondsAvg);
           bcd.HashRateTargetHs := bn.Value / (CT_NewLineSecondsAvg);