Merge 4766dae062e600b8eb97f25124de41eeb5646ecb into faee7c8f6a9fe85dcc4fb3c5ffacdde72668137f

This commit is contained in:
cwd.systems | 0KN 2025-03-19 13:36:19 +01:00 committed by GitHub
commit 8a6d102a89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,14 +22,10 @@ public class Payment {
private Repository repository;
// Constructors
public Payment(Repository repository) {
this.repository = repository;
}
// Processing
// isValid
/** Are payments valid? */
@ -37,14 +33,12 @@ public class Payment {
AssetRepository assetRepository = this.repository.getAssetRepository();
// Check fee is positive or zero
// We have already checked that the fee is correct in the Transaction superclass
if (fee < 0)
return ValidationResult.NEGATIVE_FEE;
// Total up payment amounts by assetId
Map<Long, Long> amountsByAssetId = new HashMap<>();
// Add transaction fee to start with
amountsByAssetId.put(Asset.QORT, fee);
amountsByAssetId.put(Asset.QORT, fee); // Add transaction fee to the map
// Grab sender info
Account sender = new PublicKeyAccount(this.repository, senderPublicKey);
@ -73,7 +67,7 @@ public class Payment {
if (atData == null)
return ValidationResult.AT_UNKNOWN;
if (atData != null && atData.getIsFinished())
if (atData.getIsFinished())
return ValidationResult.AT_IS_FINISHED;
}
@ -121,29 +115,6 @@ public class Payment {
return isValid(senderPublicKey, paymentData, fee, false);
}
// isProcessable
/** Are multiple payments processable? */
public ValidationResult isProcessable(byte[] senderPublicKey, List<PaymentData> payments, long fee, boolean isZeroAmountValid) throws DataException {
// Essentially the same as isValid...
return isValid(senderPublicKey, payments, fee, isZeroAmountValid);
}
/** Are multiple payments processable? */
public ValidationResult isProcessable(byte[] senderPublicKey, List<PaymentData> payments, long fee) throws DataException {
return isProcessable(senderPublicKey, payments, fee, false);
}
/** Is single payment processable? */
public ValidationResult isProcessable(byte[] senderPublicKey, PaymentData paymentData, long fee, boolean isZeroAmountValid) throws DataException {
return isProcessable(senderPublicKey, Collections.singletonList(paymentData), fee, isZeroAmountValid);
}
/** Is single payment processable? */
public ValidationResult isProcessable(byte[] senderPublicKey, PaymentData paymentData, long fee) throws DataException {
return isProcessable(senderPublicKey, paymentData, fee, false);
}
// process
/** Multiple payment processing */
@ -158,7 +129,7 @@ public class Payment {
long amount = paymentData.getAmount();
// Update sender's balance due to amount
sender.modifyAssetBalance(assetId, - amount);
sender.modifyAssetBalance(assetId, -amount);
// Update recipient's balance
recipient.modifyAssetBalance(assetId, amount);
@ -178,7 +149,7 @@ public class Payment {
Account sender = new PublicKeyAccount(this.repository, senderPublicKey);
// Update sender's balance due to fee
sender.modifyAssetBalance(Asset.QORT, - fee);
sender.modifyAssetBalance(Asset.QORT, -fee);
// Update sender's reference
sender.setLastReference(signature);
@ -216,7 +187,7 @@ public class Payment {
sender.modifyAssetBalance(assetId, amount);
// Update recipient's balance
recipient.modifyAssetBalance(assetId, - amount);
recipient.modifyAssetBalance(assetId, -amount);
}
}
@ -241,10 +212,8 @@ public class Payment {
Account recipient = new Account(this.repository, paymentData.getRecipient());
long assetId = paymentData.getAssetId();
/*
* For QORT amounts only: If recipient's last reference is this transaction's signature, then they can't have made any transactions of their own
* (which would have changed their last reference) thus this is their first reference so remove it.
*/
// For QORT amounts only: If recipient's last reference is this transaction's signature, then they can't have made any transactions of their own
// (which would have changed their last reference) thus this is their first reference so remove it.
if ((alwaysUninitializeRecipientReference || assetId == Asset.QORT) && Arrays.equals(recipient.getLastReference(), signature))
recipient.setLastReference(null);
}
@ -254,5 +223,4 @@ public class Payment {
boolean alwaysUninitializeRecipientReference) throws DataException {
orphanReferencesAndFees(senderPublicKey, Collections.singletonList(paymentData), fee, signature, reference, alwaysUninitializeRecipientReference);
}
}