mirror of
https://github.com/Qortal/qortal.git
synced 2025-05-03 00:07:52 +00:00
* Created PaymentData transfer objects for (recipient, assetId, amount) tuples * Created corresponding Payment class for validating, processing and orphaning payment(s) * Modified OrderData to support isClosed for when an Order is cancelled so no more trades can occur * Migrated CancelOrderTransactions and MultiPaymentTransactions * Converted MessageTransactions, PaymentTransactions and TransferAssetTransactions to use new Payment class Can't use PaymentTransformer in PaymentTransformer or TransferAssetTransformer due to serialization differences.
65 lines
2.4 KiB
Java
65 lines
2.4 KiB
Java
package qora.transaction;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import data.PaymentData;
|
|
import data.transaction.PaymentTransactionData;
|
|
import data.transaction.TransactionData;
|
|
import qora.account.Account;
|
|
import qora.account.PublicKeyAccount;
|
|
import qora.assets.Asset;
|
|
import qora.payment.Payment;
|
|
import repository.DataException;
|
|
import repository.Repository;
|
|
|
|
public class PaymentTransaction extends Transaction {
|
|
|
|
// Constructors
|
|
|
|
public PaymentTransaction(Repository repository, TransactionData transactionData) {
|
|
super(repository, transactionData);
|
|
}
|
|
|
|
// Processing
|
|
|
|
private PaymentData getPaymentData() {
|
|
PaymentTransactionData paymentTransactionData = (PaymentTransactionData) this.transactionData;
|
|
return new PaymentData(paymentTransactionData.getRecipient(), Asset.QORA, paymentTransactionData.getAmount());
|
|
}
|
|
|
|
public ValidationResult isValid() throws DataException {
|
|
PaymentTransactionData paymentTransactionData = (PaymentTransactionData) this.transactionData;
|
|
|
|
// Check reference is correct
|
|
Account sender = new PublicKeyAccount(repository, paymentTransactionData.getSenderPublicKey());
|
|
if (!Arrays.equals(sender.getLastReference(), paymentTransactionData.getReference()))
|
|
return ValidationResult.INVALID_REFERENCE;
|
|
|
|
// Wrap and delegate final payment checks to Payment class
|
|
return new Payment(this.repository).isValid(paymentTransactionData.getSenderPublicKey(), getPaymentData(), paymentTransactionData.getFee());
|
|
}
|
|
|
|
public void process() throws DataException {
|
|
PaymentTransactionData paymentTransactionData = (PaymentTransactionData) this.transactionData;
|
|
|
|
// Save this transaction itself
|
|
this.repository.getTransactionRepository().save(this.transactionData);
|
|
|
|
// Wrap and delegate payment processing to Payment class
|
|
new Payment(this.repository).process(paymentTransactionData.getSenderPublicKey(), getPaymentData(), paymentTransactionData.getFee(),
|
|
paymentTransactionData.getSignature());
|
|
}
|
|
|
|
public void orphan() throws DataException {
|
|
PaymentTransactionData paymentTransactionData = (PaymentTransactionData) this.transactionData;
|
|
|
|
// Delete this transaction
|
|
this.repository.getTransactionRepository().delete(this.transactionData);
|
|
|
|
// Wrap and delegate payment processing to Payment class
|
|
new Payment(this.repository).orphan(paymentTransactionData.getSenderPublicKey(), getPaymentData(), paymentTransactionData.getFee(),
|
|
paymentTransactionData.getSignature(), paymentTransactionData.getReference());
|
|
}
|
|
|
|
}
|