浏览代码

Remove the block number from the account state

Account state (for sale or swap) does not take care of current block number because, even after locking period, account state will be available to be bought
PascalCoin 6 年之前
父节点
当前提交
5c8998bcaa

+ 28 - 28
src/core/UAccounts.pas

@@ -136,18 +136,18 @@ Type
   public
     Class Function IsValidAccountKey(const AAccountInfo: TAccountKey; var errors : String): Boolean;
     Class function IsNullAccountKey(const AAccountInfo : TAccountKey) : Boolean;
-    Class function IsValidNewAccountKey(const AAccountInfo : TAccountInfo; const ANewKey : TAccountKey; AProtocolVersion : Integer; ACurrentBlock : Integer) : Boolean;
+    Class function IsValidNewAccountKey(const AAccountInfo : TAccountInfo; const ANewKey : TAccountKey; AProtocolVersion : Integer) : Boolean;
     Class Function IsValidAccountInfo(const AAccountInfo: TAccountInfo; var errors : String): Boolean;
     Class Function IsValidAccountHashLockKey(const AAccount : TAccount; const AKey : TRawBytes) : Boolean;
     Class Function IsValidHashLockKey(const AKey : TRawBytes; out AError : String) : Boolean;
     Class Function CalculateHashLock(const AKey : TRawBytes) : T32Bytes;
-    Class Function IsAccountForSale(const AAccountInfo: TAccountInfo; ACurrentBlock : Integer) : Boolean;
-    Class function IsAccountForPrivateSale(const AAccountInfo: TAccountInfo; ACurrentBlock : Integer): Boolean;
+    Class Function IsAccountForSale(const AAccountInfo: TAccountInfo) : Boolean;
+    Class function IsAccountForPrivateSale(const AAccountInfo: TAccountInfo): Boolean;
     Class function IsAccountForPublicSale(const AAccountInfo: TAccountInfo): Boolean;
-    Class Function IsAccountForSwap(const AAccountInfo: TAccountInfo; ACurrentBlock : Integer) : Boolean;
-    Class function IsAccountForCoinSwap(const AAccountInfo: TAccountInfo; ACurrentBlock : Integer) : Boolean;
-    Class function IsAccountForAccountSwap(const AAccountInfo: TAccountInfo; ACurrentBlock : Integer) : Boolean;
-    Class Function IsAccountForSaleOrSwap(const AAccountInfo: TAccountInfo; ACurrentBlock : Integer) : Boolean;
+    Class Function IsAccountForSwap(const AAccountInfo: TAccountInfo) : Boolean;
+    Class function IsAccountForCoinSwap(const AAccountInfo: TAccountInfo) : Boolean;
+    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 GetECInfoTxt(Const EC_OpenSSL_NID: Word) : String;
@@ -1476,14 +1476,14 @@ begin
   Result := TBaseType.To32Bytes( TCrypto.DoSha256(AKey) );
 end;
 
-class function TAccountComp.IsAccountForSale(const AAccountInfo: TAccountInfo; ACurrentBlock : Integer): Boolean;
+class function TAccountComp.IsAccountForSale(const AAccountInfo: TAccountInfo): Boolean;
 begin
-  Result := IsAccountForPrivateSale(AAccountInfo, ACurrentBlock) OR IsAccountForPublicSale(AAccountInfo);
+  Result := IsAccountForPrivateSale(AAccountInfo) OR IsAccountForPublicSale(AAccountInfo);
 end;
 
-class function TAccountComp.IsAccountForPrivateSale(const AAccountInfo: TAccountInfo; ACurrentBlock : Integer): Boolean;
+class function TAccountComp.IsAccountForPrivateSale(const AAccountInfo: TAccountInfo): Boolean;
 begin
-  Result := (AAccountInfo.state in [as_ForSale]) AND (NOT IsNullAccountKey(AAccountInfo.accountKey)) AND (AAccountInfo.locked_until_block >= ACurrentBlock);
+  Result := (AAccountInfo.state in [as_ForSale]) AND (NOT IsNullAccountKey(AAccountInfo.accountKey));
 end;
 
 class function TAccountComp.IsAccountForPublicSale(const AAccountInfo: TAccountInfo): Boolean;
@@ -1491,31 +1491,31 @@ begin
   Result := (AAccountInfo.state in [as_ForSale]) AND IsNullAccountKey(AAccountInfo.accountKey);
 end;
 
-class function TAccountComp.IsAccountForSwap(const AAccountInfo: TAccountInfo; ACurrentBlock : Integer): Boolean;
+class function TAccountComp.IsAccountForSwap(const AAccountInfo: TAccountInfo): Boolean;
 begin
-  Result := IsAccountForAccountSwap(AAccountInfo, ACurrentBlock) OR IsAccountForCoinSwap(AAccountInfo, ACurrentBlock);
+  Result := IsAccountForAccountSwap(AAccountInfo) OR IsAccountForCoinSwap(AAccountInfo);
 end;
 
-class function TAccountComp.IsAccountForAccountSwap(const AAccountInfo: TAccountInfo; ACurrentBlock : Integer) : Boolean;
+class function TAccountComp.IsAccountForAccountSwap(const AAccountInfo: TAccountInfo) : Boolean;
 begin
-  Result := (AAccountInfo.state in [as_ForAtomicAccountSwap]) AND (AAccountInfo.locked_until_block >= ACurrentBlock);
+  Result := (AAccountInfo.state in [as_ForAtomicAccountSwap]);
 end;
 
-class function TAccountComp.IsAccountForCoinSwap(const AAccountInfo: TAccountInfo; ACurrentBlock : Integer) : Boolean;
+class function TAccountComp.IsAccountForCoinSwap(const AAccountInfo: TAccountInfo) : Boolean;
 begin
-  Result := (AAccountInfo.state in [ as_ForAtomicCoinSwap]) AND (AAccountInfo.locked_until_block >= ACurrentBlock);
+  Result := (AAccountInfo.state in [ as_ForAtomicCoinSwap]);
 end;
 
-class function TAccountComp.IsAccountForSaleOrSwap(const AAccountInfo: TAccountInfo; ACurrentBlock : Integer): Boolean;
+class function TAccountComp.IsAccountForSaleOrSwap(const AAccountInfo: TAccountInfo): Boolean;
 begin
-  Result := IsAccountForSale(AAccountInfo, ACurrentBlock) OR IsAccountForSwap(AAccountInfo, ACurrentBlock);
+  Result := IsAccountForSale(AAccountInfo) OR IsAccountForSwap(AAccountInfo);
 end;
 
 class function TAccountComp.IsAccountForSaleOrSwapAcceptingTransactions(const AAccount: TAccount; ACurrentBlock : Integer; const APayload : TRawBytes): Boolean;
 var errors : String;
 begin
   Result := False;
-  if Not IsAccountForSaleOrSwap(AAccount.accountInfo, ACurrentBlock) then
+  if Not IsAccountForSaleOrSwap(AAccount.accountInfo) then
     exit;
 
   if (AAccount.accountInfo.state in [as_ForSale, as_ForAtomicAccountSwap]) then
@@ -1549,7 +1549,7 @@ end;
 
 class function TAccountComp.IsAccountLocked(const AccountInfo: TAccountInfo; blocks_count: Cardinal): Boolean;
 begin
-  Result := IsAccountForSaleOrSwap(accountInfo, blocks_count) And ((AccountInfo.locked_until_block)>=blocks_count);
+  Result := IsAccountForSaleOrSwap(accountInfo) And ((AccountInfo.locked_until_block)>=blocks_count);
 end;
 
 class procedure TAccountComp.SaveTOperationBlockToStream(const stream: TStream; const operationBlock: TOperationBlock);
@@ -1636,7 +1636,7 @@ begin
   Result := AAccountInfo.EC_OpenSSL_NID = CT_TECDSA_Public_Nul.EC_OpenSSL_NID;
 end;
 
-class function TAccountComp.IsValidNewAccountKey(const AAccountInfo : TAccountInfo; const ANewKey : TAccountKey; AProtocolVersion : Integer; ACurrentBlock : Integer) : Boolean;
+class function TAccountComp.IsValidNewAccountKey(const AAccountInfo : TAccountInfo; const ANewKey : TAccountKey; AProtocolVersion : Integer) : Boolean;
 begin
   Result :=False;
   if AProtocolVersion <= CT_PROTOCOL_5 then begin
@@ -1644,7 +1644,7 @@ begin
     // - Private Sale: non-null and must match stored new-key in account_info
     // - Public Sale: non-null
     // - Else: non-null  (used for change key)
-    if IsAccountForPrivateSale(AAccountInfo, ACurrentBlock) then
+    if IsAccountForPrivateSale(AAccountInfo) then
        Result := (NOT IsNullAccountKey(ANewKey)) AND TAccountComp.EqualAccountKeys(ANewKey, AAccountInfo.new_publicKey)
     else if IsAccountForPublicSale(AAccountInfo) then
        Result := NOT IsNullAccountKey(ANewKey)
@@ -1656,13 +1656,13 @@ begin
     // - Public Sale: non null
     // - Atomic Coin Swap: new key must equal existing account key, ignoring stored new-key if any
     // - else: non-null
-    if TAccountComp.IsAccountForPrivateSale(AAccountInfo, ACurrentBlock) then
+    if TAccountComp.IsAccountForPrivateSale(AAccountInfo) then
       Result := TAccountComp.EqualAccountKeys(ANewKey, AAccountInfo.new_publicKey)
     else if TAccountComp.IsAccountForPublicSale(AAccountInfo) then
       Result := NOT IsNullAccountKey(ANewKey)
-    else if TAccountComp.IsAccountForAccountSwap(AAccountInfo, ACurrentBlock) then
+    else if TAccountComp.IsAccountForAccountSwap(AAccountInfo) then
       Result := TAccountComp.EqualAccountKeys(ANewKey, AAccountInfo.new_publicKey)
-    else if TAccountComp.IsAccountForCoinSwap(AAccountInfo, ACurrentBlock) then
+    else if TAccountComp.IsAccountForCoinSwap(AAccountInfo) then
       Result := TAccountComp.EqualAccountKeys(ANewKey, AAccountInfo.accountKey)
     else
       Result := NOT IsNullAccountKey(ANewKey);
@@ -4164,7 +4164,7 @@ begin
     AErrors := 'Buyer account is locked until block '+Inttostr(LPBuyerAccount^.accountInfo.locked_until_block);
     Exit;
   end;
-  If not (TAccountComp.IsAccountForSaleOrSwap(LPAccountToBuy^.accountInfo, Origin_BlocksCount)) then begin
+  If not (TAccountComp.IsAccountForSaleOrSwap(LPAccountToBuy^.accountInfo)) then begin
     AErrors := 'Account is not for sale or swap';
     Exit;
   end;
@@ -4181,7 +4181,7 @@ begin
       TAccountComp.FormatMoney(LPAccountToBuy^.balance)+' + amount '+TAccountComp.FormatMoney(AAmount);
     Exit;
   end;
-  if TAccountComp.IsAccountForSwap(LPAccountToBuy^.accountInfo, Origin_BlocksCount) AND (NOT TAccountComp.IsValidAccountHashLockKey(LPAccountToBuy^, AHashLockKey)) then begin
+  if TAccountComp.IsAccountForSwap(LPAccountToBuy^.accountInfo) AND (NOT TAccountComp.IsValidAccountHashLockKey(LPAccountToBuy^, AHashLockKey)) then begin
     AErrors := 'Account is not unlocked by supplied hash lock key';
     Exit;
   end;

+ 5 - 5
src/core/UOpTransaction.pas

@@ -802,7 +802,7 @@ begin
   // V5 - Allow recipient-signed transactions. This is defined as
   //  - Sender Account = Target Account
   LRecipientSignable := TAccountComp.IsOperationRecipientSignable(LSender, LTarget, FData.Amount, LCurrentBlock);
-  LIsSwap := TAccountComp.IsAccountForCoinSwap(LTarget.accountInfo, LCurrentBlock);
+  LIsSwap := TAccountComp.IsAccountForCoinSwap(LTarget.accountInfo);
 
   if (FData.sender=FData.target) AND (NOT LRecipientSignable) then begin
     AErrors := Format('Sender=Target and Target is not recipient-signable. Account: %d',[FData.sender]);
@@ -865,13 +865,13 @@ begin
       exit;
     end;
 
-    if (TAccountComp.IsAccountForSwap(LTarget.accountInfo, LCurrentBlock) AND (LCurrentProtocol<CT_PROTOCOL_5)) then begin
+    if (TAccountComp.IsAccountForSwap(LTarget.accountInfo) AND (LCurrentProtocol<CT_PROTOCOL_5)) then begin
       AErrors := 'Atomic swaps are not allowed until Protocol 5';
       exit;
     end;
 
     LSeller := ASafeBoxTransaction.Account(FData.SellerAccount);
-    if Not TAccountComp.IsAccountForSaleOrSwap(LTarget.accountInfo, LCurrentBlock) then begin
+    if Not TAccountComp.IsAccountForSaleOrSwap(LTarget.accountInfo) then begin
       AErrors := Format('%d is not for sale or swap',[LTarget.account]);
       exit;
     end;
@@ -892,7 +892,7 @@ begin
       AErrors := Format('Signed price (%d) is not the same of account price (%d)',[FData.AccountPrice,LTarget.accountInfo.price]);
       exit;
     end;
-    if NOT TAccountComp.IsValidNewAccountKey(LTarget.accountInfo, FData.new_accountkey, LCurrentProtocol, LCurrentBlock) then begin
+    if NOT TAccountComp.IsValidNewAccountKey(LTarget.accountInfo, FData.new_accountkey, LCurrentProtocol) then begin
       AErrors := Format('Specified new public key for %d does not equal (or is not valid) the new public key stored in account: %s <> %s',
       [LTarget.account,
        TAccountComp.AccountKey2RawString(LTarget.accountInfo.new_publicKey).ToHexaString,
@@ -917,7 +917,7 @@ begin
       exit;
     end;
 
-    if (TAccountComp.IsAccountForSwap( LTarget.accountInfo, LCurrentBlock ) AND (ASafeBoxTransaction.FreezedSafeBox.CurrentProtocol<CT_PROTOCOL_5)) then begin
+    if (TAccountComp.IsAccountForSwap( LTarget.accountInfo ) AND (ASafeBoxTransaction.FreezedSafeBox.CurrentProtocol<CT_PROTOCOL_5)) then begin
       AErrors := 'Tx-Buy atomic swaps are not allowed until Protocol 5';
       exit;
     end else If (LCurrentProtocol<CT_PROTOCOL_5) then begin

+ 1 - 1
src/core/URPC.pas

@@ -2147,7 +2147,7 @@ function TRPCProcess.ProcessMethod(const method: String; params: TPCJSONObject;
           Exit;
         end;
         account_to_purchase := FNode.GetMempoolAccount(c_account);
-        if Not TAccountComp.IsAccountForSale(account_to_purchase.accountInfo, FNode.Bank.BlocksCount) then begin
+        if Not TAccountComp.IsAccountForSale(account_to_purchase.accountInfo) then begin
           ErrorNum := CT_RPC_ErrNum_InvalidAccount;
           ErrorDesc := 'Account is not for sale: '+params.AsString('account_to_purchase','');
           Exit;

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

@@ -176,16 +176,16 @@ procedure TSearchThread.BCExecute;
         isValid := FSearchValues.inWalletKeys.IndexOfAccountKey(account.accountInfo.accountKey)>=0;
       end;
       If isValid And (FSearchValues.onlyForSale) then begin
-        isValid := TAccountComp.IsAccountForSale(account.accountInfo, LBlocksCount);
+        isValid := TAccountComp.IsAccountForSale(account.accountInfo);
       end;
       If IsValid and (FSearchValues.onlyForPublicSale) then begin
         isValid := TAccountComp.IsAccountForPublicSale(account.accountInfo);
       end;
       If IsValid and (FSearchValues.onlyForPrivateSaleToMe) then begin
-        isValid := ((TAccountComp.IsAccountForPrivateSale(account.accountInfo, LBlocksCount) OR
-                    TAccountComp.IsAccountForAccountSwap(account.accountInfo, LBlocksCount)) AND
+        isValid := ((TAccountComp.IsAccountForPrivateSale(account.accountInfo) OR
+                    TAccountComp.IsAccountForAccountSwap(account.accountInfo)) AND
                     (Assigned(FSearchValues.inWalletKeys)) And (FSearchValues.inWalletKeys.IndexOfAccountKey(account.accountInfo.new_publicKey)>=0)) OR
-                    (True {TODO: TAccountComp.IsAccountForCoinSwap(account.accountInfo, LBlocksCount) AND account.accountInfo.account_to_pay in [MyListOfAccounts]});
+                    (True {TODO: TAccountComp.IsAccountForCoinSwap(account.accountInfo) AND account.accountInfo.account_to_pay in [MyListOfAccounts]});
       end;
       If IsValid then begin
         IsValid := (account.balance>=FSearchValues.minBal) And ((FSearchValues.maxBal<0) Or (account.balance<=FSearchValues.maxBal));

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

@@ -840,7 +840,7 @@ begin
       exit;
     end;
 
-    If not TAccountComp.IsAccountForSaleOrSwap(AccountToBuy.accountInfo, FNode.Bank.BlocksCount) then begin
+    If not TAccountComp.IsAccountForSaleOrSwap(AccountToBuy.accountInfo) then begin
       errors := 'Account '+TAccountComp.AccountNumberToAccountTxtNumber(c)+' is not for sale or swap';
       exit;
     end;
@@ -848,11 +848,11 @@ begin
       errors := 'Invalid amount value';
       exit;
     end;
-     if (AccountToBuy.accountInfo.price>amount) AND (NOT TAccountComp.IsAccountForCoinSwap(AccountToBuy.accountInfo, FNode.Bank.BlocksCount)) then begin
+     if (AccountToBuy.accountInfo.price>amount) AND (NOT TAccountComp.IsAccountForCoinSwap(AccountToBuy.accountInfo)) then begin
       errors := 'Account price '+TAccountComp.FormatMoney(AccountToBuy.accountInfo.price);
       exit;
     end;
-    if TAccountComp.IsAccountForSale(AccountToBuy.accountInfo, FNode.Bank.BlocksCount) AND (amount+DefaultFee > SenderAccount.balance) then begin
+    if TAccountComp.IsAccountForSale(AccountToBuy.accountInfo) AND (amount+DefaultFee > SenderAccount.balance) then begin
       errors := 'Insufficient funds';
       exit;
     end;
@@ -1029,7 +1029,7 @@ begin
   Result := false;
   if not (PageControlOpType.ActivePage=tsDelistAccount) then exit;
   try
-    if Not TAccountComp.IsAccountForSaleOrSwap(TargetAccount.accountInfo, FNode.Bank.BlocksCount) then begin
+    if Not TAccountComp.IsAccountForSaleOrSwap(TargetAccount.accountInfo) then begin
       errors := 'Account '+TAccountComp.AccountNumberToAccountTxtNumber(TargetAccount.account)+' is not for sale or swap';
       exit;
     end;

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

@@ -899,12 +899,12 @@ begin
   Strings.Add(Format('Updated on block: %d  (%d blocks ago)',[account.updated_block,FNode.Bank.BlocksCount-account.updated_block]));
   Strings.Add(Format('Public key type: %s',[TAccountComp.GetECInfoTxt(account.accountInfo.accountKey.EC_OpenSSL_NID)]));
   Strings.Add(Format('Base58 Public key: %s',[TAccountComp.AccountPublicKeyExport(account.accountInfo.accountKey)]));
-  if TAccountComp.IsAccountForSale(account.accountInfo, FNode.Bank.BlocksCount) then begin
+  if TAccountComp.IsAccountForSale(account.accountInfo) then begin
     Strings.Add('');
     Strings.Add('** Account is for sale: **');
     Strings.Add(Format('Price: %s',[TAccountComp.FormatMoney(account.accountInfo.price)]));
     Strings.Add(Format('Seller account (where to pay): %s',[TAccountComp.AccountNumberToAccountTxtNumber(account.accountInfo.account_to_pay)]));
-    if TAccountComp.IsAccountForPrivateSale(account.accountInfo, FNode.Bank.BlocksCount) then begin
+    if TAccountComp.IsAccountForPrivateSale(account.accountInfo) then begin
       Strings.Add('');
       Strings.Add('** Private sale **');
       Strings.Add(Format('New Base58 Public key: %s',[TAccountComp.AccountPublicKeyExport(account.accountInfo.new_publicKey)]));

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

@@ -722,10 +722,10 @@ begin
           Canvas_TextRect(DrawGrid.Canvas,Rect,s,State,[tfRight,tfVerticalCenter,tfSingleLine]);
         end;
         act_saleprice : Begin
-          if TAccountComp.IsAccountForSale(account.accountInfo, LNodeBlocksCount) then begin
+          if TAccountComp.IsAccountForSale(account.accountInfo) then begin
             // Show price for sale
             s := TAccountComp.FormatMoney(account.accountInfo.price);
-            if TAccountComp.IsAccountForPrivateSale(account.accountInfo, LNodeBlocksCount) then begin
+            if TAccountComp.IsAccountForPrivateSale(account.accountInfo) then begin
               if TAccountComp.IsAccountLocked(account.accountInfo,LNodeBlocksCount) then begin
                 DrawGrid.Canvas.Font.Color := clNavy;
               end else begin