Browse Source

EPASA on GUI manual mistake prevention: Base58 must be a public key

Pascal Coin 4 years ago
parent
commit
50c88dc088
1 changed files with 18 additions and 0 deletions
  1. 18 0
      src/gui-classic/UFRMOperation.pas

+ 18 - 0
src/gui-classic/UFRMOperation.pas

@@ -1577,6 +1577,7 @@ end;
 function TFRMOperation.UpdateOpTransaction(const ASenderAccount: TAccount; out ATargetEPASA : TEPasa; out ATargetAccount : TAccount; out AResolvedTargetKey : TECDSA_Public; out ATargetRequiresPurchase : Boolean; out AAmount: Int64; out AErrors: String): Boolean;
 function TFRMOperation.UpdateOpTransaction(const ASenderAccount: TAccount; out ATargetEPASA : TEPasa; out ATargetAccount : TAccount; out AResolvedTargetKey : TECDSA_Public; out ATargetRequiresPurchase : Boolean; out AAmount: Int64; out AErrors: String): Boolean;
 Var
 Var
   LResolvedAccountNo : Cardinal;
   LResolvedAccountNo : Cardinal;
+  LPublicKey : TAccountKey;
 begin
 begin
   AErrors := '';
   AErrors := '';
   lblTransactionErrors.Caption := '';
   lblTransactionErrors.Caption := '';
@@ -1601,6 +1602,16 @@ begin
     Exit(False);
     Exit(False);
   end;
   end;
 
 
+  // GUI Base58 protection: In order to prevent manual mistake, Base58 is only allowed when introducing
+  // a Public key, otherwise will need to use String ("") or Hexadecimal (0x..) input
+  if (ATargetEPASA.PayloadType.HasTrait(ptBase58Formatted)) then begin
+     if Not TAccountComp.AccountPublicKeyImport(ATargetEPASA.Payload,LPublicKey,AErrors) then begin
+       AErrors := 'Not a Base58 Public key: '+AErrors;
+       lblTransactionErrors.Caption := AErrors;
+       Exit(False);
+     end;
+  end;
+
   if LResolvedAccountNo <> CT_AccountNo_NUL then begin
   if LResolvedAccountNo <> CT_AccountNo_NUL then begin
     ATargetAccount := TNode.Node.GetMempoolAccount(LResolvedAccountNo);
     ATargetAccount := TNode.Node.GetMempoolAccount(LResolvedAccountNo);
     if ATargetAccount.account=ASenderAccount.account then begin
     if ATargetAccount.account=ASenderAccount.account then begin
@@ -1683,6 +1694,13 @@ begin
            AErrors := 'Payload is not a Base 58 string';
            AErrors := 'Payload is not a Base 58 string';
            Exit(False);
            Exit(False);
          end;
          end;
+
+         // GUI Base58 protection: In order to prevent manual mistake, Base58 is only allowed when introducing
+         // a Public key, otherwise will need to use String ("") or Hexadecimal (0x..) input
+         if Not TAccountComp.AccountPublicKeyImport(LUserPayloadString,LPublicKey,AErrors) then begin
+           AErrors := 'Not a Public key: '+AErrors;
+           Exit(False);
+         end;
       end
       end
     else
     else
     end;
     end;