Merge 15105306d175fc6da6a843b38ec952577ae30a79 into faee7c8f6a9fe85dcc4fb3c5ffacdde72668137f

This commit is contained in:
cwd.systems | 0KN 2025-02-17 13:56:21 +01:00 committed by GitHub
commit 7e9fda7e79
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -22,28 +22,23 @@ public class CancelSellNameTransaction extends Transaction {
private CancelSellNameTransactionData cancelSellNameTransactionData;
// Constructors
public CancelSellNameTransaction(Repository repository, TransactionData transactionData) {
super(repository, transactionData);
this.cancelSellNameTransactionData = (CancelSellNameTransactionData) this.transactionData;
}
// More information
@Override
public List<String> getRecipientAddresses() throws DataException {
return Collections.emptyList();
return Collections.emptyList(); // No recipient address for this transaction
}
// Navigation
public Account getOwner() {
return this.getCreator();
return this.getCreator(); // The creator of the transaction is the owner
}
// Processing
@Override
public ValidationResult isValid() throws DataException {
String name = this.cancelSellNameTransactionData.getName();
@ -57,61 +52,56 @@ public class CancelSellNameTransaction extends Transaction {
if (!name.equals(Unicode.normalize(name)))
return ValidationResult.NAME_NOT_NORMALIZED;
// Retrieve name data from repository
NameData nameData = this.repository.getNameRepository().fromName(name);
// Check name exists
// Check if name exists
if (nameData == null)
return ValidationResult.NAME_DOES_NOT_EXIST;
// Check name is currently for sale
if (!nameData.isForSale()) {
// Only validate after feature-trigger timestamp, due to a small number of double cancelations in the chain history
// Validate after feature-trigger timestamp, due to potential double cancellations
if (this.cancelSellNameTransactionData.getTimestamp() > BlockChain.getInstance().getCancelSellNameValidationTimestamp())
return ValidationResult.NAME_NOT_FOR_SALE;
}
// Check transaction creator matches name's current owner
// Check if transaction creator matches the name's current owner
Account owner = getOwner();
if (!owner.getAddress().equals(nameData.getOwner()))
return ValidationResult.INVALID_NAME_OWNER;
// Check issuer has enough funds
// Check if issuer has enough balance for the transaction fee
if (owner.getConfirmedBalance(Asset.QORT) < cancelSellNameTransactionData.getFee())
return ValidationResult.NO_BALANCE;
return ValidationResult.OK;
return ValidationResult.OK; // All validations passed
}
@Override
public void preProcess() throws DataException {
CancelSellNameTransactionData cancelSellNameTransactionData = (CancelSellNameTransactionData) transactionData;
// Rebuild this name in the Names table from the transaction history
// This is necessary because in some rare cases names can be missing from the Names table after registration
// but we have been unable to reproduce the issue and track down the root cause
// Direct access to class field, no need to redeclare
NamesDatabaseIntegrityCheck namesDatabaseIntegrityCheck = new NamesDatabaseIntegrityCheck();
namesDatabaseIntegrityCheck.rebuildName(cancelSellNameTransactionData.getName(), this.repository);
namesDatabaseIntegrityCheck.rebuildName(this.cancelSellNameTransactionData.getName(), this.repository);
}
@Override
public void process() throws DataException {
// Update Name
// Update the Name to reflect the cancellation of the sale
Name name = new Name(this.repository, cancelSellNameTransactionData.getName());
name.cancelSell(cancelSellNameTransactionData);
// Save this transaction, with updated "name reference" to previous transaction that updated name
// Save this transaction with updated "name reference"
this.repository.getTransactionRepository().save(cancelSellNameTransactionData);
}
@Override
public void orphan() throws DataException {
// Revert name
// Revert the cancellation of the name sale
Name name = new Name(this.repository, cancelSellNameTransactionData.getName());
name.uncancelSell(cancelSellNameTransactionData);
// Save this transaction, with removed "name reference"
// Save the transaction with the reverted "name reference"
this.repository.getTransactionRepository().save(cancelSellNameTransactionData);
}
}