Browse Source

Adding Protocol to IsOperationRecipientSignable

IsOperationRecipientSignable is only valid if using protocol 5. Fixed
PascalCoin 6 years ago
parent
commit
bf8f574805
3 changed files with 13 additions and 10 deletions
  1. 6 3
      src/core/UAccounts.pas
  2. 6 6
      src/core/UOpTransaction.pas
  3. 1 1
      src/gui-classic/UFRMOperation.pas

+ 6 - 3
src/core/UAccounts.pas

@@ -149,7 +149,7 @@ Type
     Class function IsAccountForAccountSwap(const AAccountInfo: TAccountInfo) : Boolean;
     Class Function IsAccountForSaleOrSwap(const AAccountInfo: TAccountInfo) : Boolean;
     Class Function IsAccountForSaleOrSwapAcceptingTransactions(const AAccount: TAccount; ACurrentBlock : Integer; const APayload : TRawBytes) : Boolean;
-    Class Function IsOperationRecipientSignable(const ASender, ATarget : TAccount; AIncomingFunds : UInt64; ACurrentBlock : Integer ) : Boolean;
+    Class Function IsOperationRecipientSignable(const ASender, ATarget : TAccount; AIncomingFunds : UInt64; ACurrentBlock : Integer; ACurrentProtocol : Word) : Boolean;
     Class Function GetECInfoTxt(Const EC_OpenSSL_NID: Word) : String;
     Class Procedure ValidsEC_OpenSSL_NID(list : TList<Word>);
     Class Function AccountKey2RawString(const account: TAccountKey): TRawBytes; overload;
@@ -1528,10 +1528,11 @@ begin
   Result := True;
 end;
 
-Class Function TAccountComp.IsOperationRecipientSignable(const ASender, ATarget : TAccount; AIncomingFunds : UInt64; ACurrentBlock : Integer ) : Boolean;
+Class Function TAccountComp.IsOperationRecipientSignable(const ASender, ATarget : TAccount; AIncomingFunds : UInt64; ACurrentBlock : Integer; ACurrentProtocol : Word) : Boolean;
 begin
   // V5 - Allow recipient-signed operations under following conditions:
   //  - Sender Account = Target Account
+  //  - Target Account is listed for SWAP (Atomic Swap)
   //  - Target Account is time-locked to new-owner-key R and time-lock is active
   //  - (Target.Balance + Operation.Quantity) >= Target.SalePrice
   //  - Signed by new-owner-key R
@@ -1539,8 +1540,10 @@ begin
   //  This allows following use-cases:
   //  - Private account sale where buyer does not have existing account to initiate transaction
   //  - Atomic account swap where counterparty does not have existing account to initiate transaction
-  Result := (ASender.account = ATarget.account) AND
+  Result := (ACurrentProtocol >= CT_PROTOCOL_5) AND
+            (ASender.account = ATarget.account) AND
             TAccountComp.IsAccountLocked(ATarget.accountInfo, ACurrentBlock) AND
+            TAccountComp.IsAccountForSwap(ATarget.accountInfo) AND
            ((ATarget.balance + AIncomingFunds) >= (ATarget.accountInfo.price));
 
  // Note: this does not validate recipient signature, only determines if

+ 6 - 6
src/core/UOpTransaction.pas

@@ -773,6 +773,10 @@ begin
     AErrors := Format('Invalid sender %d',[FData.sender]);
     Exit;
   end;
+  if (FData.target>=ASafeBoxTransaction.FreezedSafeBox.AccountsCount) then begin
+    AErrors := Format('Invalid target %d',[FData.target]);
+    Exit;
+  end;
   if TAccountComp.IsAccountBlockedByProtocol(FData.sender,LCurrentBlock) then begin
     AErrors := Format('sender (%d) is blocked for protocol',[FData.sender]);
     Exit;
@@ -795,14 +799,9 @@ begin
   LSender := ASafeBoxTransaction.Account(FData.sender);
   LTarget := ASafeBoxTransaction.Account(FData.target);
 
-  if (FData.target>=ASafeBoxTransaction.FreezedSafeBox.AccountsCount) then begin
-    AErrors := Format('Invalid target %d',[FData.target]);
-    Exit;
-  end;
-
   // V5 - Allow recipient-signed transactions. This is defined as
   //  - Sender Account = Target Account
-  LRecipientSignable := TAccountComp.IsOperationRecipientSignable(LSender, LTarget, FData.Amount, LCurrentBlock);
+  LRecipientSignable := TAccountComp.IsOperationRecipientSignable(LSender, LTarget, FData.Amount, LCurrentBlock, LCurrentProtocol);
   LIsSwap := TAccountComp.IsAccountForCoinSwap(LTarget.accountInfo);
 
   if (FData.sender=FData.target) AND (NOT LRecipientSignable) then begin
@@ -1849,6 +1848,7 @@ begin
     errors := 'Target account is blocked for protocol';
     Exit;
   end;
+
   if NOT LIsDelist then begin
     if (FData.account_to_pay>=AccountTransaction.FreezedSafeBox.AccountsCount) then begin
       errors := 'Invalid account to pay number';

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

@@ -838,7 +838,7 @@ begin
       exit;
     end;
     AccountToBuy := FNode.GetMempoolAccount(c);
-    ARecipientSigned := TAccountComp.IsOperationRecipientSignable(SenderAccount, AccountToBuy, Amount, FNode.Bank.BlocksCount);
+    ARecipientSigned := TAccountComp.IsOperationRecipientSignable(SenderAccount, AccountToBuy, Amount, FNode.Bank.BlocksCount, FNode.Bank.SafeBox.CurrentProtocol);
     if (SenderAccount.account = AccountToBuy.Account) AND (NOT ARecipientSigned) then begin
       errors := 'Not recipient signable';
       exit;